From b403fdce6f9759569310a69658725ba74e39f2fa Mon Sep 17 00:00:00 2001 From: Chenyang Ji Date: Mon, 10 Jun 2024 12:00:46 -0700 Subject: [PATCH] fix japicmp check for threadContext Signed-off-by: Chenyang Ji --- .../common/util/concurrent/ThreadContext.java | 30 +++++++++++-------- .../util/concurrent/ThreadContextTests.java | 9 ++---- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/server/src/main/java/org/opensearch/common/util/concurrent/ThreadContext.java b/server/src/main/java/org/opensearch/common/util/concurrent/ThreadContext.java index b9c7177da828b..906a27e9f398c 100644 --- a/server/src/main/java/org/opensearch/common/util/concurrent/ThreadContext.java +++ b/server/src/main/java/org/opensearch/common/util/concurrent/ThreadContext.java @@ -480,7 +480,7 @@ public T getTransient(String key) { * @param value the header value */ public void addResponseHeader(final String key, final String value) { - updateResponseHeader(key, value, v -> v, false); + addResponseHeader(key, value, v -> v); } /** @@ -490,7 +490,19 @@ public void addResponseHeader(final String key, final String value) { * @param value the header value */ public void updateResponseHeader(final String key, final String value) { - updateResponseHeader(key, value, v -> v, true); + updateResponseHeader(key, value, v -> v); + } + + /** + * Add the {@code value} for the specified {@code key} with the specified {@code uniqueValue} used for de-duplication. Any duplicate + * {@code value} after applying {@code uniqueValue} is ignored. + * + * @param key the header name + * @param value the header value + * @param uniqueValue the function that produces de-duplication values + */ + public void addResponseHeader(final String key, final String value, final Function uniqueValue) { + threadLocal.set(threadLocal.get().putResponse(key, value, uniqueValue, maxWarningHeaderCount, maxWarningHeaderSize, false)); } /** @@ -500,17 +512,9 @@ public void updateResponseHeader(final String key, final String value) { * @param key the header name * @param value the header value * @param uniqueValue the function that produces de-duplication values - * @param replaceExistingKey whether to replace the existing header if it already exists - */ - public void updateResponseHeader( - final String key, - final String value, - final Function uniqueValue, - final boolean replaceExistingKey - ) { - threadLocal.set( - threadLocal.get().putResponse(key, value, uniqueValue, maxWarningHeaderCount, maxWarningHeaderSize, replaceExistingKey) - ); + */ + public void updateResponseHeader(final String key, final String value, final Function uniqueValue) { + threadLocal.set(threadLocal.get().putResponse(key, value, uniqueValue, maxWarningHeaderCount, maxWarningHeaderSize, true)); } /** diff --git a/server/src/test/java/org/opensearch/common/util/concurrent/ThreadContextTests.java b/server/src/test/java/org/opensearch/common/util/concurrent/ThreadContextTests.java index e6d07c5630541..4e66575711046 100644 --- a/server/src/test/java/org/opensearch/common/util/concurrent/ThreadContextTests.java +++ b/server/src/test/java/org/opensearch/common/util/concurrent/ThreadContextTests.java @@ -344,16 +344,11 @@ public void testResponseHeaders() { } final String value = HeaderWarning.formatWarning("qux"); - threadContext.updateResponseHeader("baz", value, s -> HeaderWarning.extractWarningValueFromWarningHeader(s, false), false); + threadContext.updateResponseHeader("baz", value, s -> HeaderWarning.extractWarningValueFromWarningHeader(s, false)); // pretend that another thread created the same response at a different time if (randomBoolean()) { final String duplicateValue = HeaderWarning.formatWarning("qux"); - threadContext.updateResponseHeader( - "baz", - duplicateValue, - s -> HeaderWarning.extractWarningValueFromWarningHeader(s, false), - false - ); + threadContext.updateResponseHeader("baz", duplicateValue, s -> HeaderWarning.extractWarningValueFromWarningHeader(s, false)); } threadContext.addResponseHeader("Warning", "One is the loneliest number");