From 84a325d397b259d26a54850ae6634608157f8bda Mon Sep 17 00:00:00 2001 From: Craig Perkins Date: Wed, 7 Aug 2024 13:31:00 -0400 Subject: [PATCH] Add test Signed-off-by: Craig Perkins --- .../opensearch/http/ExecutionContextPluginGetIT.java | 2 +- .../common/util/concurrent/ThreadContextTests.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/qa/smoke-test-http/src/test/java/org/opensearch/http/ExecutionContextPluginGetIT.java b/qa/smoke-test-http/src/test/java/org/opensearch/http/ExecutionContextPluginGetIT.java index 08cc59b868fdc..6b259e104a72e 100644 --- a/qa/smoke-test-http/src/test/java/org/opensearch/http/ExecutionContextPluginGetIT.java +++ b/qa/smoke-test-http/src/test/java/org/opensearch/http/ExecutionContextPluginGetIT.java @@ -24,7 +24,7 @@ import static org.hamcrest.Matchers.equalTo; /** - * Test a rest action that sets special response headers + * Test to ensure that plugin execution context is set when plugin uses pluginNodeClient */ @ClusterScope(scope = Scope.SUITE, supportsDedicatedMasters = false, numDataNodes = 1) public class ExecutionContextPluginGetIT extends HttpSmokeTestCase { 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 177bfc2415319..316b6be606cbe 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 @@ -34,6 +34,7 @@ import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.logging.HeaderWarning; import org.opensearch.common.settings.Settings; +import org.opensearch.plugins.Plugin; import org.opensearch.test.OpenSearchTestCase; import java.io.IOException; @@ -73,6 +74,17 @@ public void testStashContext() { assertEquals("1", threadContext.getHeader("default")); } + public void testStashContextWithPluginInfo() { + ThreadContext threadContext = new ThreadContext(Settings.EMPTY); + threadContext.putHeader("foo", "bar"); + try (ThreadContext.StoredContext ctx = threadContext.stashContext(Plugin.class)) { + assertNull(threadContext.getHeader("foo")); + assertEquals(Plugin.class.getCanonicalName(), threadContext.getHeader("_plugin_execution_context")); + } + + assertNull(threadContext.getHeader("_plugin_execution_context")); + } + public void testStashContextWithPersistentHeaders() { Settings build = Settings.builder().put("request.headers.default", "1").build(); ThreadContext threadContext = new ThreadContext(build);