-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make ThreadContext.stashAndMergeHeaders package-private
Signed-off-by: Craig Perkins <cwperx@amazon.com>
- Loading branch information
Showing
3 changed files
with
48 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...src/main/java/org/opensearch/common/util/concurrent/StashAndMergeHeadersFilterClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.common.util.concurrent; | ||
|
||
import org.opensearch.action.ActionRequest; | ||
import org.opensearch.action.ActionType; | ||
import org.opensearch.client.Client; | ||
import org.opensearch.client.FilterClient; | ||
import org.opensearch.core.action.ActionListener; | ||
import org.opensearch.core.action.ActionResponse; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* This class is used for simulating request headers for testing. Used in TasksIT to | ||
* assert that request headers are carried to task info | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public class StashAndMergeHeadersFilterClient extends FilterClient { | ||
private Map<String, String> headers; | ||
|
||
public StashAndMergeHeadersFilterClient(Client in, Map<String, String> headers) { | ||
super(in); | ||
this.headers = headers; | ||
} | ||
|
||
@Override | ||
protected <Request extends ActionRequest, Response extends ActionResponse> void doExecute( | ||
ActionType<Response> action, | ||
Request request, | ||
ActionListener<Response> listener | ||
) { | ||
ThreadContext threadContext = threadPool().getThreadContext(); | ||
try (ThreadContext.StoredContext ctx = threadContext.stashAndMergeHeaders(headers)) { | ||
super.doExecute(action, request, listener); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters