Search in sources :

Example 11 with EndpointResponse

use of io.confluent.ksql.rest.EndpointResponse in project ksql by confluentinc.

the class KsqlResourceTest method shouldHandleTerminateRequestCorrectly.

@Test
public void shouldHandleTerminateRequestCorrectly() {
    // When:
    final EndpointResponse response = ksqlResource.terminateCluster(securityContext, VALID_TERMINATE_REQUEST);
    // Then:
    assertThat(response.getStatus(), equalTo(200));
    assertThat(response.getEntity(), instanceOf(KsqlEntityList.class));
    assertThat(((KsqlEntityList) response.getEntity()).size(), equalTo(1));
    assertThat(((KsqlEntityList) response.getEntity()).get(0), instanceOf(CommandStatusEntity.class));
    final CommandStatusEntity commandStatusEntity = (CommandStatusEntity) ((KsqlEntityList) response.getEntity()).get(0);
    assertThat(commandStatusEntity.getCommandStatus().getStatus(), equalTo(CommandStatus.Status.QUEUED));
    verify(transactionalProducer, times(1)).initTransactions();
    verify(commandStore).enqueueCommand(any(), argThat(is(commandWithStatement(TerminateCluster.TERMINATE_CLUSTER_STATEMENT_TEXT))), any());
}
Also used : KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) EndpointResponse(io.confluent.ksql.rest.EndpointResponse) CommandStatusEntity(io.confluent.ksql.rest.entity.CommandStatusEntity) Test(org.junit.Test)

Example 12 with EndpointResponse

use of io.confluent.ksql.rest.EndpointResponse in project ksql by confluentinc.

the class KsqlResourceTest method makeFailingRequest.

private KsqlErrorMessage makeFailingRequest(final KsqlRequest ksqlRequest, final int errorCode) {
    try {
        final EndpointResponse response = ksqlResource.handleKsqlStatements(securityContext, ksqlRequest);
        assertThat(response.getStatus(), is(errorCode));
        assertThat(response.getEntity(), instanceOf(KsqlErrorMessage.class));
        return (KsqlErrorMessage) response.getEntity();
    } catch (final KsqlRestException e) {
        return (KsqlErrorMessage) e.getResponse().getEntity();
    }
}
Also used : EndpointResponse(io.confluent.ksql.rest.EndpointResponse) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage)

Example 13 with EndpointResponse

use of io.confluent.ksql.rest.EndpointResponse in project ksql by confluentinc.

the class OldApiUtilsTest method shouldReturnCorrectResponseForUnspecificException.

@Test
public void shouldReturnCorrectResponseForUnspecificException() {
    final EndpointResponse response = OldApiUtils.mapException(new Exception("error msg"));
    assertThat(response.getEntity(), instanceOf(KsqlErrorMessage.class));
    final KsqlErrorMessage errorMessage = (KsqlErrorMessage) response.getEntity();
    assertThat(errorMessage.getMessage(), equalTo("error msg"));
    assertThat(errorMessage.getErrorCode(), equalTo(Errors.ERROR_CODE_SERVER_ERROR));
    assertThat(response.getStatus(), equalTo(INTERNAL_SERVER_ERROR.code()));
}
Also used : EndpointResponse(io.confluent.ksql.rest.EndpointResponse) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage) Test(org.junit.Test)

Example 14 with EndpointResponse

use of io.confluent.ksql.rest.EndpointResponse in project ksql by confluentinc.

the class KsqlResourceTest method shouldReturnBadRequestWhenIsValidatorIsCalledWithNonQueryLevelProps.

@Test
public void shouldReturnBadRequestWhenIsValidatorIsCalledWithNonQueryLevelProps() {
    final Map<String, Object> properties = new HashMap<>();
    properties.put(StreamsConfig.COMMIT_INTERVAL_MS_CONFIG, "");
    givenKsqlConfigWith(ImmutableMap.of(KsqlConfig.KSQL_SHARED_RUNTIME_ENABLED, true));
    // When:
    final EndpointResponse response = ksqlResource.isValidProperty("ksql.service.id");
    // Then:
    assertThat(response.getStatus(), equalTo(400));
}
Also used : EndpointResponse(io.confluent.ksql.rest.EndpointResponse) HashMap(java.util.HashMap) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 15 with EndpointResponse

use of io.confluent.ksql.rest.EndpointResponse in project ksql by confluentinc.

the class ServerStateHandler method handle.

@Override
public void handle(final RoutingContext routingContext) {
    final Optional<EndpointResponse> response = serverState.checkReady();
    if (response.isPresent()) {
        final KsqlErrorMessage errorMsg = (KsqlErrorMessage) response.get().getEntity();
        routingContext.fail(SERVICE_UNAVAILABLE.code(), new KsqlApiException(errorMsg.getMessage(), errorMsg.getErrorCode()));
    } else {
        routingContext.next();
    }
}
Also used : EndpointResponse(io.confluent.ksql.rest.EndpointResponse) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage)

Aggregations

EndpointResponse (io.confluent.ksql.rest.EndpointResponse)30 Test (org.junit.Test)25 KsqlErrorMessage (io.confluent.ksql.rest.entity.KsqlErrorMessage)10 KsqlRequest (io.confluent.ksql.rest.entity.KsqlRequest)8 KsqlException (io.confluent.ksql.util.KsqlException)7 KsqlTopicAuthorizationException (io.confluent.ksql.exception.KsqlTopicAuthorizationException)6 HashMap (java.util.HashMap)6 MetricsCallbackHolder (io.confluent.ksql.api.server.MetricsCallbackHolder)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 Query (io.confluent.ksql.parser.tree.Query)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 SessionConfig (io.confluent.ksql.config.SessionConfig)3 KsqlEngine (io.confluent.ksql.engine.KsqlEngine)3 KsqlEntityList (io.confluent.ksql.rest.entity.KsqlEntityList)3 KsqlConfig (io.confluent.ksql.util.KsqlConfig)3 ImmutableList (com.google.common.collect.ImmutableList)2 AvroSchema (io.confluent.kafka.schemaregistry.avro.AvroSchema)2 SchemaRegistryClient (io.confluent.kafka.schemaregistry.client.SchemaRegistryClient)2