use of io.confluent.ksql.api.server.MetricsCallbackHolder in project ksql by confluentinc.
the class StreamedQueryResourceTest method shouldReturnForbiddenKafkaAccessIfKsqlTopicAuthorizationException.
@Test
public void shouldReturnForbiddenKafkaAccessIfKsqlTopicAuthorizationException() {
// Given:
when(mockStatementParser.<Query>parseSingleStatement(PUSH_QUERY_STRING)).thenReturn(query);
doThrow(new KsqlTopicAuthorizationException(AclOperation.READ, Collections.singleton(TOPIC_NAME))).when(authorizationValidator).checkAuthorization(any(), any(), any());
// When:
final EndpointResponse response = testResource.streamQuery(securityContext, new KsqlRequest(PUSH_QUERY_STRING, Collections.emptyMap(), Collections.emptyMap(), null), new CompletableFuture<>(), Optional.empty(), new MetricsCallbackHolder(), context);
final KsqlErrorMessage responseEntity = (KsqlErrorMessage) response.getEntity();
final KsqlErrorMessage expectedEntity = (KsqlErrorMessage) AUTHORIZATION_ERROR_RESPONSE.getEntity();
assertEquals(response.getStatus(), AUTHORIZATION_ERROR_RESPONSE.getStatus());
assertEquals(responseEntity.getMessage(), expectedEntity.getMessage());
}
use of io.confluent.ksql.api.server.MetricsCallbackHolder in project ksql by confluentinc.
the class StreamedQueryResourceTest method shouldWaitIfCommandSequenceNumberSpecified.
@Test
public void shouldWaitIfCommandSequenceNumberSpecified() throws Exception {
// When:
testResource.streamQuery(securityContext, new KsqlRequest(PUSH_QUERY_STRING, Collections.emptyMap(), Collections.emptyMap(), 3L), new CompletableFuture<>(), Optional.empty(), new MetricsCallbackHolder(), context);
// Then:
verify(commandQueue).ensureConsumedPast(eq(3L), any());
}
use of io.confluent.ksql.api.server.MetricsCallbackHolder 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))));
}
use of io.confluent.ksql.api.server.MetricsCallbackHolder in project ksql by confluentinc.
the class StreamedQueryResourceTest method shouldUpdateTheLastRequestTime.
@Test
public void shouldUpdateTheLastRequestTime() {
// / When:
testResource.streamQuery(securityContext, new KsqlRequest(PUSH_QUERY_STRING, Collections.emptyMap(), Collections.emptyMap(), null), new CompletableFuture<>(), Optional.empty(), new MetricsCallbackHolder(), context);
// Then:
verify(activenessRegistrar).updateLastRequestTime();
}
Aggregations