Search in sources :

Example 21 with KsqlErrorMessage

use of io.confluent.ksql.rest.entity.KsqlErrorMessage in project ksql by confluentinc.

the class ClusterTerminationTest method shouldReturn50303WhenTerminating.

private void shouldReturn50303WhenTerminating() {
    // Given: TERMINATE CLUSTER has been issued
    // When:
    final KsqlErrorMessage error = RestIntegrationTestUtil.makeKsqlRequestWithError(REST_APP, "SHOW STREAMS;");
    // Then:
    assertThat(error.getErrorCode(), is(Errors.ERROR_CODE_SERVER_SHUTTING_DOWN));
}
Also used : KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage)

Example 22 with KsqlErrorMessage

use of io.confluent.ksql.rest.entity.KsqlErrorMessage in project ksql by confluentinc.

the class PreconditionFunctionalTest method shouldNotServeRequestsWhileWaitingForPrecondition.

@Test
public void shouldNotServeRequestsWhileWaitingForPrecondition() {
    // When:
    final KsqlErrorMessage error = RestIntegrationTestUtil.makeKsqlRequestWithError(REST_APP, "SHOW STREAMS;");
    // Then:
    assertThat(error.getErrorCode(), is(CUSTOM_ERROR_CODE));
}
Also used : KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage) IntegrationTest(io.confluent.common.utils.IntegrationTest) Test(org.junit.Test)

Example 23 with KsqlErrorMessage

use of io.confluent.ksql.rest.entity.KsqlErrorMessage in project ksql by confluentinc.

the class ListQueriesExecutorTest method shouldIncludeUnresponsiveIfShowQueriesErrorResponse.

@Test
public void shouldIncludeUnresponsiveIfShowQueriesErrorResponse() {
    // Given
    when(sessionProperties.getInternalRequest()).thenReturn(false);
    final ConfiguredStatement<ListQueries> showQueries = (ConfiguredStatement<ListQueries>) engine.configure("SHOW QUERIES;");
    final PersistentQueryMetadata metadata = givenPersistentQuery("id", RUNNING_QUERY_STATE);
    final KsqlEngine engine = mock(KsqlEngine.class);
    when(engine.getAllLiveQueries()).thenReturn(ImmutableList.of(metadata));
    when(engine.getPersistentQueries()).thenReturn(ImmutableList.of(metadata));
    when(response.isErroneous()).thenReturn(true);
    when(response.getErrorMessage()).thenReturn(new KsqlErrorMessage(10000, "error"));
    queryStatusCount.updateStatusCount(RUNNING_QUERY_STATE, 1);
    queryStatusCount.updateStatusCount(KsqlQueryStatus.UNRESPONSIVE, 1);
    // When
    final Queries queries = (Queries) CUSTOM_EXECUTORS.listQueries().execute(showQueries, sessionProperties, engine, serviceContext).getEntity().orElseThrow(IllegalStateException::new);
    // Then
    assertThat(queries.getQueries(), containsInAnyOrder(persistentQueryMetadataToRunningQuery(metadata, queryStatusCount)));
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) KsqlEngine(io.confluent.ksql.engine.KsqlEngine) Queries(io.confluent.ksql.rest.entity.Queries) ListQueries(io.confluent.ksql.parser.tree.ListQueries) ListQueries(io.confluent.ksql.parser.tree.ListQueries) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage) Test(org.junit.Test)

Example 24 with KsqlErrorMessage

use of io.confluent.ksql.rest.entity.KsqlErrorMessage in project ksql by confluentinc.

the class ListQueriesExecutorTest method shouldIncludeUnresponsiveIfShowQueriesExtendedErrorResponse.

@Test
public void shouldIncludeUnresponsiveIfShowQueriesExtendedErrorResponse() {
    // Given
    when(sessionProperties.getInternalRequest()).thenReturn(false);
    final ConfiguredStatement<ListQueries> showQueries = (ConfiguredStatement<ListQueries>) engine.configure("SHOW QUERIES EXTENDED;");
    final PersistentQueryMetadata metadata = givenPersistentQuery("id", RUNNING_QUERY_STATE);
    final KsqlEngine engine = mock(KsqlEngine.class);
    when(engine.getAllLiveQueries()).thenReturn(ImmutableList.of(metadata));
    when(engine.getPersistentQueries()).thenReturn(ImmutableList.of(metadata));
    when(response.isErroneous()).thenReturn(true);
    when(response.getErrorMessage()).thenReturn(new KsqlErrorMessage(10000, "error"));
    final Map<KsqlHostInfoEntity, KsqlQueryStatus> map = new HashMap<>();
    map.put(LOCAL_KSQL_HOST_INFO_ENTITY, KsqlQueryStatus.RUNNING);
    map.put(REMOTE_KSQL_HOST_INFO_ENTITY, KsqlQueryStatus.UNRESPONSIVE);
    // When
    final QueryDescriptionList queries = (QueryDescriptionList) CUSTOM_EXECUTORS.listQueries().execute(showQueries, sessionProperties, engine, serviceContext).getEntity().orElseThrow(IllegalStateException::new);
    // Then
    assertThat(queries.getQueryDescriptions(), containsInAnyOrder(QueryDescriptionFactory.forQueryMetadata(metadata, map)));
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) KsqlEngine(io.confluent.ksql.engine.KsqlEngine) HashMap(java.util.HashMap) ListQueries(io.confluent.ksql.parser.tree.ListQueries) QueryDescriptionList(io.confluent.ksql.rest.entity.QueryDescriptionList) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage) KsqlQueryStatus(io.confluent.ksql.util.KsqlConstants.KsqlQueryStatus) Test(org.junit.Test)

Example 25 with KsqlErrorMessage

use of io.confluent.ksql.rest.entity.KsqlErrorMessage in project ksql by confluentinc.

the class StreamedQueryResourceTest method shouldReturnForbiddenKafkaAccessForPullQueryAuthorizationDenied.

@Test
public void shouldReturnForbiddenKafkaAccessForPullQueryAuthorizationDenied() {
    // Given:
    when(mockStatementParser.<Query>parseSingleStatement(PULL_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(PULL_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)

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