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