diff options
author | Jay Modi <jaymode@users.noreply.github.com> | 2017-04-06 20:38:09 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-06 20:38:09 +0100 |
commit | 495bf21b461ee15834a81b8f6a1b2311e4058bf6 (patch) | |
tree | 6e90aac6dbcc39f3ae1746ed31650c5fada390a6 /core/src/test/java/org/elasticsearch/action/support | |
parent | 2620200ff7d945c5bc17d2b854b4a6a92fd2120e (diff) |
Preserve response headers when creating an index (#23950)
This commit preserves the response headers when creating an index and updating settings for an
index.
Closes #23947
Diffstat (limited to 'core/src/test/java/org/elasticsearch/action/support')
-rw-r--r-- | core/src/test/java/org/elasticsearch/action/support/ContextPreservingActionListenerTests.java | 85 |
1 files changed, 50 insertions, 35 deletions
diff --git a/core/src/test/java/org/elasticsearch/action/support/ContextPreservingActionListenerTests.java b/core/src/test/java/org/elasticsearch/action/support/ContextPreservingActionListenerTests.java index 37f12ca822..dd627041f2 100644 --- a/core/src/test/java/org/elasticsearch/action/support/ContextPreservingActionListenerTests.java +++ b/core/src/test/java/org/elasticsearch/action/support/ContextPreservingActionListenerTests.java @@ -33,11 +33,10 @@ public class ContextPreservingActionListenerTests extends ESTestCase { if (nonEmptyContext) { threadContext.putHeader("not empty", "value"); } - ContextPreservingActionListener<Void> actionListener; + final ContextPreservingActionListener<Void> actionListener; try (ThreadContext.StoredContext ignore = threadContext.stashContext()) { threadContext.putHeader("foo", "bar"); - actionListener = new ContextPreservingActionListener<>(threadContext.newRestorableContext(true), - new ActionListener<Void>() { + final ActionListener<Void> delegate = new ActionListener<Void>() { @Override public void onResponse(Void aVoid) { assertEquals("bar", threadContext.getHeader("foo")); @@ -48,7 +47,12 @@ public class ContextPreservingActionListenerTests extends ESTestCase { public void onFailure(Exception e) { throw new RuntimeException("onFailure shouldn't be called", e); } - }); + }; + if (randomBoolean()) { + actionListener = new ContextPreservingActionListener<>(threadContext.newRestorableContext(true), delegate); + } else { + actionListener = ContextPreservingActionListener.wrapPreservingContext(delegate, threadContext); + } } assertNull(threadContext.getHeader("foo")); @@ -67,22 +71,28 @@ public class ContextPreservingActionListenerTests extends ESTestCase { if (nonEmptyContext) { threadContext.putHeader("not empty", "value"); } - ContextPreservingActionListener<Void> actionListener; + final ContextPreservingActionListener<Void> actionListener; try (ThreadContext.StoredContext ignore = threadContext.stashContext()) { threadContext.putHeader("foo", "bar"); - actionListener = new ContextPreservingActionListener<>(threadContext.newRestorableContext(true), - new ActionListener<Void>() { - @Override - public void onResponse(Void aVoid) { - throw new RuntimeException("onResponse shouldn't be called"); - } - - @Override - public void onFailure(Exception e) { - assertEquals("bar", threadContext.getHeader("foo")); - assertNull(threadContext.getHeader("not empty")); - } - }); + final ActionListener<Void> delegate = new ActionListener<Void>() { + @Override + public void onResponse(Void aVoid) { + throw new RuntimeException("onResponse shouldn't be called"); + } + + @Override + public void onFailure(Exception e) { + assertEquals("bar", threadContext.getHeader("foo")); + assertNull(threadContext.getHeader("not empty")); + } + }; + + if (randomBoolean()) { + actionListener = new ContextPreservingActionListener<>(threadContext.newRestorableContext(true), delegate); + } else { + actionListener = ContextPreservingActionListener.wrapPreservingContext(delegate, threadContext); + } + } assertNull(threadContext.getHeader("foo")); @@ -101,25 +111,30 @@ public class ContextPreservingActionListenerTests extends ESTestCase { if (nonEmptyContext) { threadContext.putHeader("not empty", "value"); } - ContextPreservingActionListener<Void> actionListener; + final ContextPreservingActionListener<Void> actionListener; try (ThreadContext.StoredContext ignore = threadContext.stashContext()) { threadContext.putHeader("foo", "bar"); - actionListener = new ContextPreservingActionListener<>(threadContext.newRestorableContext(true), - new ActionListener<Void>() { - @Override - public void onResponse(Void aVoid) { - assertEquals("bar", threadContext.getHeader("foo")); - assertNull(threadContext.getHeader("not empty")); - throw new RuntimeException("onResponse called"); - } - - @Override - public void onFailure(Exception e) { - assertEquals("bar", threadContext.getHeader("foo")); - assertNull(threadContext.getHeader("not empty")); - throw new RuntimeException("onFailure called"); - } - }); + final ActionListener<Void> delegate = new ActionListener<Void>() { + @Override + public void onResponse(Void aVoid) { + assertEquals("bar", threadContext.getHeader("foo")); + assertNull(threadContext.getHeader("not empty")); + throw new RuntimeException("onResponse called"); + } + + @Override + public void onFailure(Exception e) { + assertEquals("bar", threadContext.getHeader("foo")); + assertNull(threadContext.getHeader("not empty")); + throw new RuntimeException("onFailure called"); + } + }; + + if (randomBoolean()) { + actionListener = new ContextPreservingActionListener<>(threadContext.newRestorableContext(true), delegate); + } else { + actionListener = ContextPreservingActionListener.wrapPreservingContext(delegate, threadContext); + } } assertNull(threadContext.getHeader("foo")); |