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';"))));
}
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"));
}
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"))));
}
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;"))));
}
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))));
}
Aggregations