Search in sources :

Example 1 with KsqlErrorMessage

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"));
}
Also used : KsqlStatementException(io.confluent.ksql.util.KsqlStatementException) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage) Test(org.junit.Test)

Example 2 with KsqlErrorMessage

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"));
}
Also used : KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage) Test(org.junit.Test)

Example 3 with KsqlErrorMessage

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"));
}
Also used : EndpointResponse(io.confluent.ksql.rest.EndpointResponse) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage) Test(org.junit.Test)

Example 4 with KsqlErrorMessage

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());
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage) Test(org.junit.Test)

Example 5 with KsqlErrorMessage

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();
    }
}
Also used : EndpointResponse(io.confluent.ksql.rest.EndpointResponse) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage)

Aggregations

KsqlErrorMessage (io.confluent.ksql.rest.entity.KsqlErrorMessage)43 Test (org.junit.Test)35 EndpointResponse (io.confluent.ksql.rest.EndpointResponse)8 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 KsqlEntityList (io.confluent.ksql.rest.entity.KsqlEntityList)5 KsqlStatementErrorMessage (io.confluent.ksql.rest.entity.KsqlStatementErrorMessage)5 IntegrationTest (io.confluent.common.utils.IntegrationTest)4 KsqlTopicAuthorizationException (io.confluent.ksql.exception.KsqlTopicAuthorizationException)4 KsqlEngine (io.confluent.ksql.engine.KsqlEngine)3 KsqlHostInfoEntity (io.confluent.ksql.rest.entity.KsqlHostInfoEntity)3 KsqlRequest (io.confluent.ksql.rest.entity.KsqlRequest)3 ConfiguredStatement (io.confluent.ksql.statement.ConfiguredStatement)3 MetricsCallbackHolder (io.confluent.ksql.api.server.MetricsCallbackHolder)2 ListQueries (io.confluent.ksql.parser.tree.ListQueries)2 Query (io.confluent.ksql.parser.tree.Query)2 KsqlRestClient (io.confluent.ksql.rest.client.KsqlRestClient)2 KsqlConfig (io.confluent.ksql.util.KsqlConfig)2 KsqlStatementException (io.confluent.ksql.util.KsqlStatementException)2 PersistentQueryMetadata (io.confluent.ksql.util.PersistentQueryMetadata)2