Skip to content

Commit cd18cf9

Browse files
authored
Assert NodeClient in client wrapper (#113515) (#113521)
Some `getClientWrapper()` implementations return a wrapper that only wraps `NodeClient` instances. In practice we _only_ wrap `NodeClient` instances so this check is redundant, and in a recent investigation it was confusing to readers. With this commit we assert that we're always wrapping a `NodeClient`.
1 parent 74785f3 commit cd18cf9

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

x-pack/plugin/identity-provider/src/internalClusterTest/java/org/elasticsearch/xpack/idp/saml/test/IdentityProviderIntegTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ protected Function<Client, Client> getClientWrapper() {
158158
// user. This is ok for internal n2n stuff but the test framework does other things like wiping indices, repositories, etc
159159
// that the system user cannot do. so we wrap the node client with a user that can do these things since the client() calls
160160
// return a node client
161-
return client -> (client instanceof NodeClient) ? client.filterWithHeader(headers) : client;
161+
return client -> asInstanceOf(NodeClient.class, client).filterWithHeader(headers);
162162
}
163163

164164
@Override

x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/MlNativeIntegTestCase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.elasticsearch.action.support.broadcast.BroadcastResponse;
1919
import org.elasticsearch.action.support.master.AcknowledgedResponse;
2020
import org.elasticsearch.client.internal.Client;
21+
import org.elasticsearch.client.internal.node.NodeClient;
2122
import org.elasticsearch.cluster.ClusterModule;
2223
import org.elasticsearch.cluster.ClusterState;
2324
import org.elasticsearch.cluster.NamedDiff;
@@ -172,7 +173,7 @@ protected Function<Client, Client> getClientWrapper() {
172173
// user. This is ok for internal n2n stuff but the test framework does other things like wiping indices, repositories, etc
173174
// that the system user cannot do. so we wrap the node client with a user that can do these things since the client() calls
174175
// return a node client
175-
return client -> client.filterWithHeader(headers);
176+
return client -> asInstanceOf(NodeClient.class, client).filterWithHeader(headers);
176177
}
177178

178179
private Settings externalClusterClientSettings() {

x-pack/plugin/security/src/test/java/org/elasticsearch/test/SecurityIntegTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ protected Function<Client, Client> getClientWrapper() {
379379
// user. This is ok for internal n2n stuff but the test framework does other things like wiping indices, repositories, etc
380380
// that the system user cannot do. so we wrap the node client with a user that can do these things since the client() calls
381381
// return a node client
382-
return client -> (client instanceof NodeClient) ? client.filterWithHeader(headers) : client;
382+
return client -> asInstanceOf(NodeClient.class, client).filterWithHeader(headers);
383383
}
384384

385385
/**

0 commit comments

Comments
 (0)