Skip to content

Commit d57f0fa

Browse files
Use assertResponse() in test
1 parent ba8ae4b commit d57f0fa

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

server/src/internalClusterTest/java/org/elasticsearch/search/ccs/CpsDoesNotUseSkipUnavailableIT.java

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.concurrent.ExecutionException;
2929

3030
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
31+
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertResponse;
3132

3233
public class CpsDoesNotUseSkipUnavailableIT extends AbstractMultiClustersTestCase {
3334
private static final String LINKED_CLUSTER_1 = "cluster-a";
@@ -65,7 +66,7 @@ protected Map<String, Boolean> skipUnavailableForRemoteClusters() {
6566
return Map.of(LINKED_CLUSTER_1, false);
6667
}
6768

68-
public void testCpsShouldNotUseSkipUnavailable() {
69+
public void testCpsShouldNotUseSkipUnavailable() throws Exception {
6970
// Add some dummy data to prove we are communicating fine with the remote.
7071
assertAcked(client(LINKED_CLUSTER_1).admin().indices().prepareCreate("test-index"));
7172
client(LINKED_CLUSTER_1).prepareIndex("test-index").setSource("sample-field", "sample-value").get();
@@ -86,23 +87,24 @@ public void testCpsShouldNotUseSkipUnavailable() {
8687
{
8788
var searchRequest = getSearchRequest(true);
8889
searchRequest.setCcsMinimizeRoundtrips(randomBoolean());
89-
var result = safeGet(client().execute(TransportSearchAction.TYPE, searchRequest));
90-
91-
var originCluster = result.getClusters().getCluster(LOCAL_CLUSTER);
92-
assertThat(originCluster.getStatus(), Matchers.is(SearchResponse.Cluster.Status.SUCCESSFUL));
93-
94-
var linkedCluster = result.getClusters().getCluster(LINKED_CLUSTER_1);
95-
assertThat(linkedCluster.getStatus(), Matchers.is(SearchResponse.Cluster.Status.SKIPPED));
96-
97-
var linkedClusterFailures = result.getClusters().getCluster(LINKED_CLUSTER_1).getFailures();
98-
assertThat(linkedClusterFailures.size(), Matchers.is(1));
99-
// Failure is something along the lines of shard failure and is caused by a connection error.
100-
assertThat(
101-
linkedClusterFailures.getFirst().getCause(),
102-
Matchers.anyOf(Matchers.instanceOf(RemoteTransportException.class), Matchers.instanceOf(ConnectTransportException.class))
103-
);
104-
105-
result.decRef();
90+
assertResponse(client().execute(TransportSearchAction.TYPE, searchRequest), result -> {
91+
var originCluster = result.getClusters().getCluster(LOCAL_CLUSTER);
92+
assertThat(originCluster.getStatus(), Matchers.is(SearchResponse.Cluster.Status.SUCCESSFUL));
93+
94+
var linkedCluster = result.getClusters().getCluster(LINKED_CLUSTER_1);
95+
assertThat(linkedCluster.getStatus(), Matchers.is(SearchResponse.Cluster.Status.SKIPPED));
96+
97+
var linkedClusterFailures = result.getClusters().getCluster(LINKED_CLUSTER_1).getFailures();
98+
assertThat(linkedClusterFailures.size(), Matchers.is(1));
99+
// Failure is something along the lines of shard failure and is caused by a connection error.
100+
assertThat(
101+
linkedClusterFailures.getFirst().getCause(),
102+
Matchers.anyOf(
103+
Matchers.instanceOf(RemoteTransportException.class),
104+
Matchers.instanceOf(ConnectTransportException.class)
105+
)
106+
);
107+
});
106108
}
107109

108110
/*

0 commit comments

Comments
 (0)