Skip to content

Commit f00ba1b

Browse files
Make integration tests explicitly indicate when a multi-project cluster state is expected
1 parent 547be49 commit f00ba1b

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

server/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateRequest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ public boolean customs() {
141141
return customs;
142142
}
143143

144-
public void multiproject(boolean multiproject) {
144+
public ClusterStateRequest multiproject(boolean multiproject) {
145145
this.multiproject = multiproject;
146+
return this;
146147
}
147148

148149
public boolean multiproject() {

server/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateRequestBuilder.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,12 @@ public ClusterStateRequestBuilder setWaitForTimeOut(TimeValue waitForTimeout) {
108108
request.waitForTimeout(waitForTimeout);
109109
return this;
110110
}
111+
112+
/**
113+
* When set then the response will be in multi-project format
114+
*/
115+
public ClusterStateRequestBuilder setMultiproject(boolean multiproject) {
116+
request.multiproject(multiproject);
117+
return this;
118+
}
111119
}

test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
3434
import org.elasticsearch.action.admin.cluster.node.info.NodeInfo;
3535
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse;
36+
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequestBuilder;
3637
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
3738
import org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksRequest;
3839
import org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksResponse;
@@ -1397,12 +1398,13 @@ protected final void doEnsureClusterStateConsistency(NamedWriteableRegistry name
13971398
final var masterName = internalCluster().getMasterName();
13981399
for (Client client : cluster().getClients()) {
13991400
localStates.add(
1400-
SubscribableListener.newForked(l -> client.admin().cluster().prepareState(TEST_REQUEST_TIMEOUT).all().execute(l))
1401+
SubscribableListener.newForked(l -> prepareClusterStateRequest(client)
1402+
.execute(l))
14011403
);
14021404
}
14031405
try (RefCountingListener refCountingListener = new RefCountingListener(future)) {
14041406
SubscribableListener.<ClusterStateResponse>newForked(
1405-
l -> client(masterName).admin().cluster().prepareState(TEST_REQUEST_TIMEOUT).all().execute(l)
1407+
l -> prepareClusterStateRequest(client(masterName)).execute(l)
14061408
).andThenAccept(masterStateResponse -> {
14071409
byte[] masterClusterStateBytes = ClusterState.Builder.toBytes(masterStateResponse.getState());
14081410
// remove local node reference
@@ -1462,7 +1464,7 @@ protected final void doEnsureClusterStateConsistency(NamedWriteableRegistry name
14621464
protected void ensureClusterStateCanBeReadByNodeTool() throws IOException {
14631465
if (cluster() != null && cluster().size() > 0) {
14641466
final Client masterClient = client();
1465-
Metadata metadata = masterClient.admin().cluster().prepareState(TEST_REQUEST_TIMEOUT).all().get().getState().metadata();
1467+
Metadata metadata = prepareClusterStateRequest(masterClient).get().getState().metadata();
14661468
final Map<String, String> serializationParams = Maps.newMapWithExpectedSize(2);
14671469
serializationParams.put("binary", "true");
14681470
serializationParams.put(Metadata.CONTEXT_MODE_PARAM, Metadata.CONTEXT_MODE_GATEWAY);
@@ -1565,6 +1567,10 @@ protected void ensureClusterStateCanBeReadByNodeTool() throws IOException {
15651567
}
15661568
}
15671569

1570+
private ClusterStateRequestBuilder prepareClusterStateRequest(Client client) {
1571+
return client.admin().cluster().prepareState(TEST_REQUEST_TIMEOUT).all().setMultiproject(multiProjectIntegrationTest());
1572+
}
1573+
15681574
private static void ensureClusterInfoServiceRunning() {
15691575
if (isInternalCluster() && cluster().size() > 0) {
15701576
// ensures that the cluster info service didn't leak its async task, which would prevent future refreshes

test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2065,7 +2065,7 @@ public String getMasterName(@Nullable String viaNode) {
20652065
}
20662066
try {
20672067
ClusterServiceUtils.awaitClusterState(state -> state.nodes().getMasterNode() != null, clusterService(viaNode));
2068-
final ClusterState state = client(viaNode).admin().cluster().prepareState(TEST_REQUEST_TIMEOUT).get().getState();
2068+
final ClusterState state = client(viaNode).admin().cluster().prepareState(TEST_REQUEST_TIMEOUT).clear().setBlocks(true).setNodes(true).get().getState();
20692069
final DiscoveryNode masterNode = state.nodes().getMasterNode();
20702070
if (masterNode == null) {
20712071
throw new AssertionError("Master is not stable but the method expects a stable master node");

0 commit comments

Comments
 (0)