Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2713,6 +2713,20 @@ public static <T extends Throwable> T expectThrows(Class<T> expectedType, Matche
return e;
}

/**
* Checks a specific exception class with matched message is thrown by the given runnable, and returns it.
*/
public static <T extends Throwable> T expectThrows(
String reason,
Class<T> expectedType,
Matcher<String> messageMatcher,
ThrowingRunnable runnable
) {
var e = expectThrows(expectedType, reason, runnable);
assertThat(reason, e.getMessage(), messageMatcher);
return e;
}

/**
* Same as {@link #runInParallel(int, IntConsumer)} but also attempts to start all tasks at the same time by blocking execution on a
* barrier until all threads are started and ready to execute their task.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ public static String randomIndexPattern(Feature... features) {
var cluster = maybeQuote(randomIdentifier());
pattern = maybeQuote(cluster + ":" + pattern);
} else if (EsqlCapabilities.Cap.INDEX_COMPONENT_SELECTORS.isEnabled() && canAdd(Features.INDEX_SELECTOR, features)) {
var selector = ESTestCase.randomFrom(IndexComponentSelector.values());
pattern = maybeQuote(pattern + "::" + selector.getKey());
pattern = maybeQuote(pattern + "::" + randomFrom(IndexComponentSelector.values()).getKey());
}
return pattern;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,22 +140,25 @@ static MapExpression mapExpression(Map<String, Object> keyValuePairs) {
}

void expectError(String query, String errorMessage) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could just defer to expectError(String query, List<QueryParam> params, String errorMessage) with params given by new QueryParams().

ParsingException e = expectThrows(ParsingException.class, "Expected syntax error for " + query, () -> statement(query));
assertThat(e.getMessage(), containsString(errorMessage));
}

void expectVerificationError(String query, String errorMessage) {
VerificationException e = expectThrows(VerificationException.class, "Expected syntax error for " + query, () -> statement(query));
assertThat(e.getMessage(), containsString(errorMessage));
expectError(query, null, errorMessage);
}

void expectError(String query, List<QueryParam> params, String errorMessage) {
ParsingException e = expectThrows(
expectThrows(
"Query [" + query + "] is expected to throw " + ParsingException.class + " with message [" + errorMessage + "]",
ParsingException.class,
"Expected syntax error for " + query,
containsString(errorMessage),
() -> statement(query, new QueryParams(params))
);
assertThat(e.getMessage(), containsString(errorMessage));
}

void expectVerificationError(String query, String errorMessage) {
expectThrows(
"Query [" + query + "] is expected to throw " + VerificationException.class + " with message [" + errorMessage + "]",
VerificationException.class,
containsString(errorMessage),
() -> parser.createStatement(query)
);
}

void expectInvalidIndexNameErrorWithLineNumber(String query, String indexString, String lineNumber) {
Expand Down