Skip to content

Commit

Permalink
Adjusted IT based on PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
quux00 committed Jan 21, 2025
1 parent d5aea8c commit 3d8599c
Showing 1 changed file with 35 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,21 +220,13 @@ public void testSearchesAgainstNonMatchingIndicesWithLocalOnly() {
}
{
String q = "FROM nomatch";
VerificationException e = expectThrows(VerificationException.class, () -> runQuery(q, false));
assertThat(e.getDetailedMessage(), containsString("Unknown index [nomatch]"));

String limit0 = q + " | LIMIT 0";
e = expectThrows(VerificationException.class, () -> runQuery(limit0, false));
assertThat(e.getDetailedMessage(), containsString("Unknown index [nomatch]"));
String expectedError = "Unknown index [nomatch]";
expectVerificationExceptionForQuery(q, expectedError, false);
}
{
String q = "FROM nomatch*";
VerificationException e = expectThrows(VerificationException.class, () -> runQuery(q, false));
assertThat(e.getDetailedMessage(), containsString("Unknown index [nomatch*]"));

String limit0 = q + " | LIMIT 0";
e = expectThrows(VerificationException.class, () -> runQuery(limit0, false));
assertThat(e.getDetailedMessage(), containsString("Unknown index [nomatch*]"));
String expectedError = "Unknown index [nomatch*]";
expectVerificationExceptionForQuery(q, expectedError, false);
}
}

Expand Down Expand Up @@ -314,23 +306,15 @@ public void testSearchesAgainstNonMatchingIndices() {
// missing concrete local index is an error
{
String q = "FROM nomatch,cluster-a:" + remote1Index;
VerificationException e = expectThrows(VerificationException.class, () -> runQuery(q, requestIncludeMeta));
assertThat(e.getDetailedMessage(), containsString("Unknown index [nomatch]"));

String limit0 = q + " | LIMIT 0";
e = expectThrows(VerificationException.class, () -> runQuery(limit0, requestIncludeMeta));
assertThat(e.getDetailedMessage(), containsString("Unknown index [nomatch]"));
String expectedError = "Unknown index [nomatch]";
expectVerificationExceptionForQuery(q, expectedError, requestIncludeMeta);
}

// missing concrete remote index is fatal
{
String q = "FROM logs*,cluster-a:nomatch";
VerificationException e = expectThrows(VerificationException.class, () -> runQuery(q, requestIncludeMeta));
assertThat(e.getDetailedMessage(), containsString("Unknown index [cluster-a:nomatch]"));

String limit0 = q + " | LIMIT 0";
e = expectThrows(VerificationException.class, () -> runQuery(limit0, requestIncludeMeta));
assertThat(e.getDetailedMessage(), containsString("Unknown index [cluster-a:nomatch]"));
String expectedError = "Unknown index [cluster-a:nomatch]";
expectVerificationExceptionForQuery(q, expectedError, requestIncludeMeta);
}

// No error since local non-matching index has wildcard and the remote cluster index expression matches
Expand Down Expand Up @@ -417,63 +401,39 @@ public void testSearchesAgainstNonMatchingIndices() {
// an error is thrown if there is a concrete index that does not match
{
String q = "FROM cluster-a:nomatch";
VerificationException e = expectThrows(VerificationException.class, () -> runQuery(q, requestIncludeMeta));
assertThat(e.getDetailedMessage(), containsString("Unknown index [cluster-a:nomatch]"));

String limit0 = q + " | LIMIT 0";
e = expectThrows(VerificationException.class, () -> runQuery(limit0, requestIncludeMeta));
assertThat(e.getDetailedMessage(), containsString("Unknown index [cluster-a:nomatch]"));
String expectedError = "Unknown index [cluster-a:nomatch]";
expectVerificationExceptionForQuery(q, expectedError, requestIncludeMeta);
}

// an error is thrown if there are no matching indices at all - single remote cluster with wildcard index expression
{
String q = "FROM cluster-a:nomatch*";
VerificationException e = expectThrows(VerificationException.class, () -> runQuery(q, requestIncludeMeta));
assertThat(e.getDetailedMessage(), containsString("Unknown index [cluster-a:nomatch*]"));

String limit0 = q + " | LIMIT 0";
e = expectThrows(VerificationException.class, () -> runQuery(limit0, requestIncludeMeta));
assertThat(e.getDetailedMessage(), containsString("Unknown index [cluster-a:nomatch*]"));
String expectedError = "Unknown index [cluster-a:nomatch*]";
expectVerificationExceptionForQuery(q, expectedError, requestIncludeMeta);
}

// an error is thrown if there is a concrete index that does not match
{
String q = "FROM nomatch*,cluster-a:nomatch";
VerificationException e = expectThrows(VerificationException.class, () -> runQuery(q, requestIncludeMeta));
assertThat(e.getDetailedMessage(), containsString("Unknown index [cluster-a:nomatch,nomatch*]"));

String limit0 = q + " | LIMIT 0";
e = expectThrows(VerificationException.class, () -> runQuery(limit0, requestIncludeMeta));
assertThat(e.getDetailedMessage(), containsString("Unknown index [cluster-a:nomatch,nomatch*]"));
String expectedError = "Unknown index [cluster-a:nomatch,nomatch*]";
expectVerificationExceptionForQuery(q, expectedError, requestIncludeMeta);
}

// an error is thrown if there are no matching indices at all - local with wildcard, remote with wildcard
{
String q = "FROM nomatch*,cluster-a:nomatch*";
VerificationException e = expectThrows(VerificationException.class, () -> runQuery(q, requestIncludeMeta));
assertThat(e.getDetailedMessage(), containsString("Unknown index [cluster-a:nomatch*,nomatch*]"));

String limit0 = q + " | LIMIT 0";
e = expectThrows(VerificationException.class, () -> runQuery(limit0, requestIncludeMeta));
assertThat(e.getDetailedMessage(), containsString("Unknown index [cluster-a:nomatch*,nomatch*]"));
String expectedError = "Unknown index [cluster-a:nomatch*,nomatch*]";
expectVerificationExceptionForQuery(q, expectedError, requestIncludeMeta);
}
{
String q = "FROM nomatch,cluster-a:nomatch";
VerificationException e = expectThrows(VerificationException.class, () -> runQuery(q, requestIncludeMeta));
assertThat(e.getDetailedMessage(), containsString("Unknown index [cluster-a:nomatch,nomatch]"));

String limit0 = q + " | LIMIT 0";
e = expectThrows(VerificationException.class, () -> runQuery(limit0, requestIncludeMeta));
assertThat(e.getDetailedMessage(), containsString("Unknown index [cluster-a:nomatch,nomatch]"));
String expectedError = "Unknown index [cluster-a:nomatch,nomatch]";
expectVerificationExceptionForQuery(q, expectedError, requestIncludeMeta);
}
{
String q = "FROM nomatch,cluster-a:nomatch*";
VerificationException e = expectThrows(VerificationException.class, () -> runQuery(q, requestIncludeMeta));
assertThat(e.getDetailedMessage(), containsString("Unknown index [cluster-a:nomatch*,nomatch]"));

String limit0 = q + " | LIMIT 0";
e = expectThrows(VerificationException.class, () -> runQuery(limit0, requestIncludeMeta));
assertThat(e.getDetailedMessage(), containsString("Unknown index [cluster-a:nomatch*,nomatch]"));
String expectedError = "Unknown index [cluster-a:nomatch*,nomatch]";
expectVerificationExceptionForQuery(q, expectedError, requestIncludeMeta);
}

// --- test against 3 clusters
Expand All @@ -483,17 +443,26 @@ public void testSearchesAgainstNonMatchingIndices() {
String localIndexName = randomFrom(localIndex, IDX_ALIAS, FILTERED_IDX_ALIAS);
String remote2IndexName = randomFrom(remote2Index, IDX_ALIAS, FILTERED_IDX_ALIAS);
String q = Strings.format("FROM %s*,cluster-a:nomatch,%s:%s*", localIndexName, REMOTE_CLUSTER_2, remote2IndexName);
VerificationException e = expectThrows(VerificationException.class, () -> runQuery(q, requestIncludeMeta));
assertThat(e.getDetailedMessage(), containsString("Unknown index [cluster-a:nomatch]"));

String limit0 = q + " | LIMIT 0";
e = expectThrows(VerificationException.class, () -> runQuery(limit0, requestIncludeMeta));
assertThat(e.getDetailedMessage(), containsString("Unknown index [cluster-a:nomatch]"));
String expectedError = "Unknown index [cluster-a:nomatch]";
expectVerificationExceptionForQuery(q, expectedError, requestIncludeMeta);
}
}

record ExpectedCluster(String clusterAlias, String indexExpression, EsqlExecutionInfo.Cluster.Status status, Integer totalShards) {}

/**
* Runs the provided query, expecting a VerificationError. It then runs the same query with a "| LIMIT 0"
* extra processing step to ensure that ESQL coordinator-only operations throw the same VerificationError.
*/
private void expectVerificationExceptionForQuery(String query, String error, Boolean requestIncludeMeta) {
VerificationException e = expectThrows(VerificationException.class, () -> runQuery(query, requestIncludeMeta));
assertThat(e.getDetailedMessage(), containsString(error));

String limit0 = query + " | LIMIT 0";
e = expectThrows(VerificationException.class, () -> runQuery(limit0, requestIncludeMeta));
assertThat(e.getDetailedMessage(), containsString(error));
}

public void assertExpectedClustersForMissingIndicesTests(EsqlExecutionInfo executionInfo, List<ExpectedCluster> expected) {
long overallTookMillis = executionInfo.overallTook().millis();
assertThat(overallTookMillis, greaterThanOrEqualTo(0L));
Expand Down

0 comments on commit 3d8599c

Please sign in to comment.