use of io.confluent.ksql.rest.entity.KsqlErrorMessage in project ksql by confluentinc.
the class KsqlRestApplicationTest method shouldNotInitializeUntilPreconditionsChecked.
@Test
public void shouldNotInitializeUntilPreconditionsChecked() {
// Given:
final KsqlErrorMessage error1 = new KsqlErrorMessage(50000, "error1");
final KsqlErrorMessage error2 = new KsqlErrorMessage(50000, "error2");
final Queue<KsqlErrorMessage> errors = new LinkedList<>();
errors.add(error1);
errors.add(error2);
when(precondition2.checkPrecondition(any(), any(), any())).then(a -> {
verifyNoMoreInteractions(serviceContext);
return Optional.ofNullable(errors.isEmpty() ? null : errors.remove());
});
// When:
app.startKsql(ksqlConfig);
// Then:
final InOrder inOrder = Mockito.inOrder(precondition1, precondition2, serverState);
inOrder.verify(precondition1).checkPrecondition(restConfig, serviceContext, internalTopicClient);
inOrder.verify(precondition2).checkPrecondition(restConfig, serviceContext, internalTopicClient);
inOrder.verify(serverState).setInitializingReason(error1);
inOrder.verify(precondition1).checkPrecondition(restConfig, serviceContext, internalTopicClient);
inOrder.verify(precondition2).checkPrecondition(restConfig, serviceContext, internalTopicClient);
inOrder.verify(serverState).setInitializingReason(error2);
inOrder.verify(precondition1).checkPrecondition(restConfig, serviceContext, internalTopicClient);
inOrder.verify(precondition2).checkPrecondition(restConfig, serviceContext, internalTopicClient);
}
use of io.confluent.ksql.rest.entity.KsqlErrorMessage in project ksql by confluentinc.
the class CliTest method shouldPrintErrorOnUnsupportedAPI.
@Test
public void shouldPrintErrorOnUnsupportedAPI() throws Exception {
givenRunInteractivelyWillExit();
final KsqlRestClient mockRestClient = givenMockRestClient();
when(mockRestClient.getServerInfo()).thenReturn(RestResponse.erroneous(NOT_ACCEPTABLE.code(), new KsqlErrorMessage(Errors.toErrorCode(NOT_ACCEPTABLE.code()), "Minimum supported client version: 1.0")));
new Cli(1L, 1L, mockRestClient, console).runInteractively();
assertThat(terminal.getOutputString(), containsString("This CLI version no longer supported"));
assertThat(terminal.getOutputString(), containsString("Minimum supported client version: 1.0"));
}
use of io.confluent.ksql.rest.entity.KsqlErrorMessage in project ksql by confluentinc.
the class CliTest method shouldThrowWhenTryingToSetDeniedProperty.
@Test
public void shouldThrowWhenTryingToSetDeniedProperty() throws Exception {
// Given
final KsqlRestClient mockRestClient = givenMockRestClient();
when(mockRestClient.makeIsValidRequest("ksql.service.id")).thenReturn(RestResponse.erroneous(NOT_ACCEPTABLE.code(), new KsqlErrorMessage(Errors.toErrorCode(NOT_ACCEPTABLE.code()), "Property cannot be set")));
// When:
assertThrows(IllegalArgumentException.class, () -> localCli.handleLine("set 'ksql.service.id'='test';"));
}
use of io.confluent.ksql.rest.entity.KsqlErrorMessage in project ksql by confluentinc.
the class FailureHandler method handleError.
private static void handleError(final HttpServerResponse response, final int statusCode, final int errorCode, final String errMsg, final Optional<String> statement) {
if (statement.isPresent()) {
final KsqlStatementErrorMessage errorResponse = new KsqlStatementErrorMessage(errorCode, errMsg, statement.get(), new KsqlEntityList());
final Buffer buffer = ServerUtils.serializeObject(errorResponse);
response.setStatusCode(statusCode).end(buffer);
} else {
final KsqlErrorMessage errorResponse = new KsqlErrorMessage(errorCode, errMsg);
final Buffer buffer = ServerUtils.serializeObject(errorResponse);
response.setStatusCode(statusCode).end(buffer);
}
}
use of io.confluent.ksql.rest.entity.KsqlErrorMessage in project ksql by confluentinc.
the class KsqlResourceTest method shouldThrowOnDenyListValidatorWhenHandleKsqlStatement.
@Test
public void shouldThrowOnDenyListValidatorWhenHandleKsqlStatement() {
// Given:
ksqlResource = new KsqlResource(ksqlEngine, commandRunner, DISTRIBUTED_COMMAND_RESPONSE_TIMEOUT, activenessRegistrar, (ec, sc) -> InjectorChain.of(schemaInjectorFactory.apply(sc), topicInjectorFactory.apply(ec), new TopicDeleteInjector(ec, sc)), Optional.of(authorizationValidator), errorsHandler, connectErrorHandler, denyListPropertyValidator, commandRunnerWarning);
final Map<String, Object> props = new HashMap<>(ksqlRestConfig.getKsqlConfigProperties());
props.put(KsqlConfig.KSQL_PROPERTIES_OVERRIDES_DENYLIST, StreamsConfig.NUM_STREAM_THREADS_CONFIG);
ksqlResource.configure(new KsqlConfig(props));
final Map<String, Object> overrides = ImmutableMap.of(StreamsConfig.NUM_STREAM_THREADS_CONFIG, 1);
doThrow(new KsqlException("deny override")).when(denyListPropertyValidator).validateAll(overrides);
// When:
final EndpointResponse response = ksqlResource.handleKsqlStatements(securityContext, new KsqlRequest("query", // stream properties
overrides, emptyMap(), null));
// Then:
verify(denyListPropertyValidator).validateAll(overrides);
assertThat(response.getStatus(), CoreMatchers.is(BAD_REQUEST.code()));
assertThat(((KsqlErrorMessage) response.getEntity()).getMessage(), is("deny override"));
}
Aggregations