use of io.confluent.ksql.rest.entity.KsqlErrorMessage in project ksql by confluentinc.
the class KsqlResourceTest method shouldFailWhenTopicInferenceFailsDuringValidate.
@Test
public void shouldFailWhenTopicInferenceFailsDuringValidate() {
// Given:
givenSource(DataSourceType.KSTREAM, "ORDERS1", "ORDERS1", SOME_SCHEMA);
when(sandboxTopicInjector.inject(any())).thenThrow(new KsqlStatementException("boom", "sql"));
// When:
final KsqlErrorMessage result = makeFailingRequest("CREATE STREAM orders2 AS SELECT * FROM orders1;", BAD_REQUEST.code());
// Then:
assertThat(result.getErrorCode(), is(Errors.ERROR_CODE_BAD_STATEMENT));
assertThat(result.getMessage(), is("boom"));
}
use of io.confluent.ksql.rest.entity.KsqlErrorMessage in project ksql by confluentinc.
the class KsqlResourceTest method shouldReturn5xxOnSystemError.
@Test
public void shouldReturn5xxOnSystemError() {
// Given:
givenMockEngine();
when(ksqlEngine.parse(anyString())).thenThrow(new RuntimeException("internal error"));
// When:
final KsqlErrorMessage result = makeFailingRequest("CREATE STREAM test_explain AS SELECT * FROM test_stream;", INTERNAL_SERVER_ERROR.code());
// Then:
assertThat(result.getErrorCode(), is(Errors.ERROR_CODE_SERVER_ERROR));
assertThat(result.getMessage(), containsString("internal error"));
}
use of io.confluent.ksql.rest.entity.KsqlErrorMessage in project ksql by confluentinc.
the class StatusResourceTest method testGetStatusNotFound.
@Test
public void testGetStatusNotFound() throws Exception {
final StatusResource testResource = getTestStatusResource();
final EndpointResponse response = testResource.getStatus(CommandId.Type.STREAM.name(), "foo", CommandId.Action.CREATE.name());
assertThat(response.getStatus(), equalTo(NOT_FOUND.code()));
assertThat(response.getEntity(), instanceOf(KsqlErrorMessage.class));
final KsqlErrorMessage errorMessage = (KsqlErrorMessage) response.getEntity();
assertThat(errorMessage.getErrorCode(), equalTo(Errors.ERROR_CODE_NOT_FOUND));
assertThat(errorMessage.getMessage(), equalTo("Command not found"));
}
use of io.confluent.ksql.rest.entity.KsqlErrorMessage in project ksql by confluentinc.
the class KsqlResourceTest method shouldFailAllCommandsIfWouldReachActivePersistentQueriesLimit.
@Test
public void shouldFailAllCommandsIfWouldReachActivePersistentQueriesLimit() {
// Given:
givenKsqlConfigWith(ImmutableMap.of(KsqlConfig.KSQL_ACTIVE_PERSISTENT_QUERY_LIMIT_CONFIG, 1));
final String ksqlString = "CREATE STREAM new_stream AS SELECT * FROM test_stream;" + "CREATE STREAM another_stream AS SELECT * FROM test_stream;";
givenMockEngine();
// mock 2 new query to execute
givenPersistentQueryCount(2);
// When:
final KsqlErrorMessage result = makeFailingRequest(ksqlString, BAD_REQUEST.code());
// Then:
assertThat(result.getErrorCode(), is(Errors.ERROR_CODE_BAD_REQUEST));
assertThat(result.getMessage(), containsString("would cause the number of active, persistent queries " + "to exceed the configured limit"));
verify(commandStore, never()).enqueueCommand(any(), any(), any());
}
use of io.confluent.ksql.rest.entity.KsqlErrorMessage in project ksql by confluentinc.
the class KsqlResourceTest method makeFailingRequest.
private KsqlErrorMessage makeFailingRequest(final KsqlRequest ksqlRequest, final int errorCode) {
try {
final EndpointResponse response = ksqlResource.handleKsqlStatements(securityContext, ksqlRequest);
assertThat(response.getStatus(), is(errorCode));
assertThat(response.getEntity(), instanceOf(KsqlErrorMessage.class));
return (KsqlErrorMessage) response.getEntity();
} catch (final KsqlRestException e) {
return (KsqlErrorMessage) e.getResponse().getEntity();
}
}
Aggregations