Skip to content

Commit 99f9b45

Browse files
Relax assertions for the wrapping
1 parent a5d14a4 commit 99f9b45

File tree

3 files changed

+41
-15
lines changed

3 files changed

+41
-15
lines changed

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/CrossClusterCancellationIT.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ protected boolean reuseClusters() {
8989
return false;
9090
}
9191

92+
private Exception unwrapIfWrappedInRemoteComputeException(Exception e) {
93+
if (e instanceof RemoteComputeException rce) {
94+
return (Exception) rce.getCause();
95+
} else {
96+
return e;
97+
}
98+
}
99+
92100
private void createRemoteIndex(int numDocs) throws Exception {
93101
XContentBuilder mapping = JsonXContent.contentBuilder().startObject();
94102
mapping.startObject("runtime");
@@ -163,8 +171,9 @@ public void testCancel() throws Exception {
163171
} finally {
164172
SimplePauseFieldPlugin.allowEmitting.countDown();
165173
}
166-
RemoteComputeException rce = expectThrows(RemoteComputeException.class, requestFuture::actionGet);
167-
assertThat(rce.getCause().getMessage(), containsString("proxy timeout"));
174+
Exception error = expectThrows(Exception.class, requestFuture::actionGet);
175+
error = unwrapIfWrappedInRemoteComputeException(error);
176+
assertThat(error.getCause().getMessage(), containsString("proxy timeout"));
168177
}
169178

170179
public void testSameRemoteClusters() throws Exception {
@@ -284,7 +293,8 @@ public void testCancelSkipUnavailable() throws Exception {
284293
SimplePauseFieldPlugin.allowEmitting.countDown();
285294
}
286295

287-
RemoteComputeException error = expectThrows(RemoteComputeException.class, requestFuture::actionGet);
296+
Exception error = expectThrows(Exception.class, requestFuture::actionGet);
297+
error = unwrapIfWrappedInRemoteComputeException(error);
288298
assertThat(error.getCause(), instanceOf(TaskCancelledException.class));
289299
}
290300
}

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/CrossClusterQueryIT.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ protected Map<String, Boolean> skipUnavailableForRemoteClusters() {
6464
return Map.of(REMOTE_CLUSTER_1, randomBoolean(), REMOTE_CLUSTER_2, randomBoolean());
6565
}
6666

67+
private Exception unwrapIfWrappedInRemoteComputeException(Exception e) {
68+
if (e instanceof RemoteComputeException rce) {
69+
return (Exception) rce.getCause();
70+
} else {
71+
return e;
72+
}
73+
}
74+
6775
public void testSuccessfulPathways() throws Exception {
6876
Map<String, Object> testClusterInfo = setupTwoClusters();
6977
int localNumShards = (Integer) testClusterInfo.get("local.num_shards");
@@ -816,11 +824,11 @@ public void testRemoteFailureSkipUnavailableTrue() throws IOException {
816824
String remote1Index = (String) testClusterInfo.get("remote.index");
817825
String q = Strings.format("FROM %s,cluster-a:%s*", localIndex, remote1Index);
818826

819-
RemoteComputeException rce = expectThrows(RemoteComputeException.class, () -> runQuery(q, false));
820-
Throwable t = rce.getCause();
827+
Exception error = expectThrows(Exception.class, () -> runQuery(q, false));
828+
error = unwrapIfWrappedInRemoteComputeException(error);
821829

822-
assertThat(t, instanceOf(IllegalStateException.class));
823-
assertThat(t.getMessage(), containsString("Accessing failing field"));
830+
assertThat(error, instanceOf(IllegalStateException.class));
831+
assertThat(error.getMessage(), containsString("Accessing failing field"));
824832
}
825833

826834
private static void assertClusterMetadataInResponse(EsqlQueryResponse resp, boolean responseExpectMeta) {

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/CrossClusterQueryWithPartialResultsIT.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,26 @@ private void assertClusterSuccess(EsqlQueryResponse resp, String clusterAlias, i
9999
assertThat(clusterInfo.getFailures(), empty());
100100
}
101101

102+
private Exception unwrapIfWrappedInRemoteComputeException(Exception e) {
103+
if (e instanceof RemoteComputeException rce) {
104+
return (Exception) rce.getCause();
105+
} else {
106+
return e;
107+
}
108+
}
109+
102110
public void testPartialResults() throws Exception {
103111
populateIndices();
104112
EsqlQueryRequest request = new EsqlQueryRequest();
105113
request.query("FROM ok*,fail*,*:ok*,*:fail* | KEEP id, fail_me | LIMIT 1000");
106114
request.includeCCSMetadata(randomBoolean());
107115
{
108116
request.allowPartialResults(false);
109-
RemoteComputeException rce = expectThrows(RemoteComputeException.class, () -> runQuery(request).close());
110-
Throwable t = rce.getCause();
117+
Exception error = expectThrows(Exception.class, () -> runQuery(request).close());
118+
error = unwrapIfWrappedInRemoteComputeException(error);
111119

112-
assertThat(t, instanceOf(IllegalStateException.class));
113-
assertThat(t.getMessage(), containsString("Accessing failing field"));
120+
assertThat(error, instanceOf(IllegalStateException.class));
121+
assertThat(error.getMessage(), containsString("Accessing failing field"));
114122
}
115123
request.allowPartialResults(true);
116124
try (var resp = runQuery(request)) {
@@ -194,8 +202,8 @@ public void sendResponse(Exception exception) {
194202
request.includeCCSMetadata(randomBoolean());
195203
{
196204
request.allowPartialResults(false);
197-
RemoteComputeException rce = expectThrows(RemoteComputeException.class, () -> runQuery(request).close());
198-
var error = (Exception) rce.getCause();
205+
Exception error = expectThrows(Exception.class, () -> runQuery(request).close());
206+
error = unwrapIfWrappedInRemoteComputeException(error);
199207
var unwrapped = ExceptionsHelper.unwrap(error, simulatedFailure.getClass());
200208
assertNotNull(unwrapped);
201209
assertThat(unwrapped.getMessage(), equalTo(simulatedFailure.getMessage()));
@@ -242,8 +250,8 @@ public void testFailToStartRequestOnRemoteCluster() throws Exception {
242250
request.includeCCSMetadata(randomBoolean());
243251
{
244252
request.allowPartialResults(false);
245-
var rce = expectThrows(RemoteComputeException.class, () -> runQuery(request).close());
246-
var error = (Exception) rce.getCause();
253+
Exception error = expectThrows(Exception.class, () -> runQuery(request).close());
254+
error = unwrapIfWrappedInRemoteComputeException(error);
247255
EsqlTestUtils.assertEsqlFailure(error);
248256
var unwrapped = ExceptionsHelper.unwrap(error, simulatedFailure.getClass());
249257
assertNotNull(unwrapped);

0 commit comments

Comments
 (0)