Search in sources :

Example 11 with MetricsCallbackHolder

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());
}
Also used : KsqlTopicAuthorizationException(io.confluent.ksql.exception.KsqlTopicAuthorizationException) EndpointResponse(io.confluent.ksql.rest.EndpointResponse) Query(io.confluent.ksql.parser.tree.Query) MetricsCallbackHolder(io.confluent.ksql.api.server.MetricsCallbackHolder) KsqlRequest(io.confluent.ksql.rest.entity.KsqlRequest) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage) Test(org.junit.Test)

Example 12 with MetricsCallbackHolder

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

Example 13 with MetricsCallbackHolder

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))));
}
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)

Example 14 with MetricsCallbackHolder

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

Aggregations

MetricsCallbackHolder (io.confluent.ksql.api.server.MetricsCallbackHolder)14 KsqlRequest (io.confluent.ksql.rest.entity.KsqlRequest)13 Test (org.junit.Test)13 Query (io.confluent.ksql.parser.tree.Query)5 EndpointResponse (io.confluent.ksql.rest.EndpointResponse)5 KsqlRestException (io.confluent.ksql.rest.server.resources.KsqlRestException)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 KsqlTopicAuthorizationException (io.confluent.ksql.exception.KsqlTopicAuthorizationException)4 PrintTopic (io.confluent.ksql.parser.tree.PrintTopic)3 KsqlErrorMessage (io.confluent.ksql.rest.entity.KsqlErrorMessage)3 KsqlConfig (io.confluent.ksql.util.KsqlConfig)3 StreamedRow (io.confluent.ksql.rest.entity.StreamedRow)2 QueryMetadataHolder (io.confluent.ksql.rest.server.query.QueryMetadataHolder)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 GenericRow (io.confluent.ksql.GenericRow)1 GenericRow.genericRow (io.confluent.ksql.GenericRow.genericRow)1 StreamingOutput (io.confluent.ksql.api.server.StreamingOutput)1 SessionConfig (io.confluent.ksql.config.SessionConfig)1