Search in sources :

Example 6 with KsqlRestException

use of io.confluent.ksql.rest.server.resources.KsqlRestException in project ksql by confluentinc.

the class PrintTopicValidatorTest method shouldThrowExceptionOnPrintTopic.

@Test
public void shouldThrowExceptionOnPrintTopic() {
    // Given:
    final ConfiguredStatement<PrintTopic> query = ConfiguredStatement.of(PreparedStatement.of("PRINT 'topic';", mock(PrintTopic.class)), SessionConfig.of(CONFIG, ImmutableMap.of()));
    // When:
    final KsqlRestException e = assertThrows(KsqlRestException.class, () -> CustomValidators.PRINT_TOPIC.validate(query, mock(SessionProperties.class), ksqlEngine, serviceContext));
    // Then:
    assertThat(e, exceptionStatusCode(is(BAD_REQUEST.code())));
    assertThat(e, exceptionStatementErrorMessage(errorMessage(containsString("The following statement types should be issued to the websocket endpoint '/query'"))));
    assertThat(e, exceptionStatementErrorMessage(statement(containsString("PRINT 'topic';"))));
}
Also used : KsqlRestException(io.confluent.ksql.rest.server.resources.KsqlRestException) PrintTopic(io.confluent.ksql.parser.tree.PrintTopic) Test(org.junit.Test)

Example 7 with KsqlRestException

use of io.confluent.ksql.rest.server.resources.KsqlRestException in project ksql by confluentinc.

the class DistributingExecutorTest method shouldThrowIfRateLimitHit.

@Test
public void shouldThrowIfRateLimitHit() {
    // Given:
    final DistributingExecutor rateLimitedDistributor = new DistributingExecutor(new KsqlConfig(ImmutableMap.of(KsqlRestConfig.KSQL_COMMAND_TOPIC_RATE_LIMIT_CONFIG, 0.5)), queue, DURATION_10_MS, (ec, sc) -> InjectorChain.of(schemaInjector, topicInjector), Optional.of(authorizationValidator), validatedCommandFactory, errorHandler, commandRunnerWarning);
    // When:
    rateLimitedDistributor.execute(CONFIGURED_STATEMENT, executionContext, securityContext);
    // Then:
    final KsqlRestException e = assertThrows(KsqlRestException.class, () -> rateLimitedDistributor.execute(CONFIGURED_STATEMENT, executionContext, securityContext));
    assertEquals(e.getResponse().getStatus(), 429);
    final KsqlErrorMessage errorMessage = (KsqlErrorMessage) e.getResponse().getEntity();
    assertTrue(errorMessage.getMessage().contains("DDL/DML rate is crossing the configured rate limit of statements/second"));
}
Also used : KsqlRestException(io.confluent.ksql.rest.server.resources.KsqlRestException) KsqlConfig(io.confluent.ksql.util.KsqlConfig) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage) Test(org.junit.Test)

Example 8 with KsqlRestException

use of io.confluent.ksql.rest.server.resources.KsqlRestException in project ksql by confluentinc.

the class CommandStoreUtilTest method shouldThrowKsqlRestExceptionOnTimeout.

@Test
public void shouldThrowKsqlRestExceptionOnTimeout() throws Exception {
    // Given:
    when(request.getCommandSequenceNumber()).thenReturn(Optional.of(SEQUENCE_NUMBER));
    doThrow(new TimeoutException("uh oh")).when(commandQueue).ensureConsumedPast(SEQUENCE_NUMBER, TIMEOUT);
    // When:
    final KsqlRestException e = assertThrows(KsqlRestException.class, () -> CommandStoreUtil.httpWaitForCommandSequenceNumber(commandQueue, request, TIMEOUT));
    // Then:
    assertThat(e, exceptionStatusCode(is(SERVICE_UNAVAILABLE.code())));
    assertThat(e, exceptionErrorMessage(errorMessage(containsString("Timed out while waiting for a previous command to execute"))));
    assertThat(e, exceptionErrorMessage(errorMessage(containsString("command sequence number: 2"))));
}
Also used : KsqlRestException(io.confluent.ksql.rest.server.resources.KsqlRestException) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 9 with KsqlRestException

use of io.confluent.ksql.rest.server.resources.KsqlRestException in project ksql by confluentinc.

the class StreamedQueryResourceTest method shouldRedirectQueriesToQueryEndPoint.

@Test
public void shouldRedirectQueriesToQueryEndPoint() {
    // Given:
    final ConfiguredStatement<Query> query = ConfiguredStatement.of(PreparedStatement.of("SELECT * FROM test_table;", mock(Query.class)), SessionConfig.of(ksqlConfig, ImmutableMap.of()));
    // When:
    final KsqlRestException e = assertThrows(KsqlRestException.class, () -> CustomValidators.QUERY_ENDPOINT.validate(query, mock(SessionProperties.class), mockKsqlEngine, serviceContext));
    // Then:
    assertThat(e, exceptionStatusCode(is(BAD_REQUEST.code())));
    assertThat(e, exceptionStatementErrorMessage(errorMessage(containsString("The following statement types should be issued to the websocket endpoint '/query'"))));
    assertThat(e, exceptionStatementErrorMessage(statement(containsString("SELECT * FROM test_table;"))));
}
Also used : KsqlRestException(io.confluent.ksql.rest.server.resources.KsqlRestException) Query(io.confluent.ksql.parser.tree.Query) Test(org.junit.Test)

Example 10 with KsqlRestException

use of io.confluent.ksql.rest.server.resources.KsqlRestException in project ksql by confluentinc.

the class StreamedQueryResourceTest method shouldReturnServiceUnavailableIfTimeoutWaitingForCommandSequenceNumber.

@Test
public void shouldReturnServiceUnavailableIfTimeoutWaitingForCommandSequenceNumber() throws Exception {
    // Given:
    doThrow(new TimeoutException("whoops")).when(commandQueue).ensureConsumedPast(anyLong(), any());
    // When:
    final KsqlRestException e = assertThrows(KsqlRestException.class, () -> testResource.streamQuery(securityContext, new KsqlRequest(PUSH_QUERY_STRING, Collections.emptyMap(), Collections.emptyMap(), 3L), new CompletableFuture<>(), Optional.empty(), new MetricsCallbackHolder(), context));
    // Then:
    assertThat(e, exceptionStatusCode(is(SERVICE_UNAVAILABLE.code())));
    assertThat(e, exceptionErrorMessage(errorMessage(containsString("Timed out while waiting for a previous command to execute"))));
    assertThat(e, exceptionErrorMessage(errorCode(is(Errors.ERROR_CODE_COMMAND_QUEUE_CATCHUP_TIMEOUT))));
}
Also used : KsqlRestException(io.confluent.ksql.rest.server.resources.KsqlRestException) CompletableFuture(java.util.concurrent.CompletableFuture) MetricsCallbackHolder(io.confluent.ksql.api.server.MetricsCallbackHolder) KsqlRequest(io.confluent.ksql.rest.entity.KsqlRequest) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Aggregations

KsqlRestException (io.confluent.ksql.rest.server.resources.KsqlRestException)11 Test (org.junit.Test)8 MetricsCallbackHolder (io.confluent.ksql.api.server.MetricsCallbackHolder)4 KsqlRequest (io.confluent.ksql.rest.entity.KsqlRequest)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 PrintTopic (io.confluent.ksql.parser.tree.PrintTopic)3 TimeoutException (java.util.concurrent.TimeoutException)3 CommandStatusEntity (io.confluent.ksql.rest.entity.CommandStatusEntity)2 InsertInto (io.confluent.ksql.parser.tree.InsertInto)1 Query (io.confluent.ksql.parser.tree.Query)1 CommandId (io.confluent.ksql.rest.entity.CommandId)1 CommandStatus (io.confluent.ksql.rest.entity.CommandStatus)1 KsqlEntity (io.confluent.ksql.rest.entity.KsqlEntity)1 KsqlErrorMessage (io.confluent.ksql.rest.entity.KsqlErrorMessage)1 StatementExecutorResponse (io.confluent.ksql.rest.server.execution.StatementExecutorResponse)1 KsqlConfig (io.confluent.ksql.util.KsqlConfig)1 KsqlException (io.confluent.ksql.util.KsqlException)1 KsqlServerException (io.confluent.ksql.util.KsqlServerException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1