Search in sources :

Example 1 with ErrorEntity

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

the class ClientTest method shouldFailOnErrorEntityFromExecuteStatement.

@Test
public void shouldFailOnErrorEntityFromExecuteStatement() {
    // Given
    final ErrorEntity entity = new ErrorEntity("create connector;", "error msg");
    testEndpoints.setKsqlEndpointResponse(Collections.singletonList(entity));
    // When
    final Exception e = assertThrows(// thrown from .get() when the future completes exceptionally
    ExecutionException.class, () -> javaClient.executeStatement("create connector;").get());
    // Then
    assertThat(e.getCause(), instanceOf(KsqlClientException.class));
    assertThat(e.getCause().getMessage(), containsString(EXECUTE_STATEMENT_USAGE_DOC));
    assertThat(e.getCause().getMessage(), containsString("Use the createConnector, dropConnector, describeConnector or listConnectors methods instead"));
}
Also used : ErrorEntity(io.confluent.ksql.rest.entity.ErrorEntity) KsqlClientException(io.confluent.ksql.api.client.exception.KsqlClientException) KafkaResponseGetFailedException(io.confluent.ksql.exception.KafkaResponseGetFailedException) KsqlClientException(io.confluent.ksql.api.client.exception.KsqlClientException) KsqlApiException(io.confluent.ksql.api.server.KsqlApiException) ExecutionException(java.util.concurrent.ExecutionException) ParseFailedException(io.confluent.ksql.parser.exception.ParseFailedException) KsqlException(io.confluent.ksql.api.client.exception.KsqlException) BaseApiTest(io.confluent.ksql.api.BaseApiTest) Test(org.junit.Test)

Example 2 with ErrorEntity

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

the class ConsoleTest method shouldPrintErrorEntityLongJson.

@Test
public void shouldPrintErrorEntityLongJson() throws IOException {
    // Given:
    final KsqlEntity entity = new ErrorEntity("statementText", new ObjectMapper().writeValueAsString(ImmutableMap.of("foo", "bar", "message", "a " + StringUtils.repeat("really ", 20) + " long message")));
    // When:
    console.printKsqlEntityList(ImmutableList.of(entity));
    // Then:
    final String output = terminal.getOutputString();
    Approvals.verify(output, approvalOptions);
}
Also used : ErrorEntity(io.confluent.ksql.rest.entity.ErrorEntity) Matchers.containsString(org.hamcrest.Matchers.containsString) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 3 with ErrorEntity

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

the class ConnectExecutorTest method shouldReturnErrorIfConnectorTypeIsEmpty.

@Test
public void shouldReturnErrorIfConnectorTypeIsEmpty() {
    // Given:
    final CreateConnector createConnectorEmptyType = new CreateConnector("foo", ImmutableMap.of("connector.class", new StringLiteral(" ")), Type.SOURCE, false);
    final ConfiguredStatement<CreateConnector> createConnectorEmptyTypeConfigured = ConfiguredStatement.of(PreparedStatement.of("CREATE SOURCE CONNECTOR foo WITH ('connector.class'=' ');", createConnectorEmptyType), SessionConfig.of(CONFIG, ImmutableMap.of()));
    // When:
    final Optional<KsqlEntity> entity = EXECUTOR.execute(createConnectorEmptyTypeConfigured, mock(SessionProperties.class), null, serviceContext).getEntity();
    // Then:
    assertThat("Expected non-empty response", entity.isPresent());
    assertThat(entity.get(), instanceOf(ErrorEntity.class));
    final String expectedError = "Validation error: Connector type cannot be empty";
    assertThat(((ErrorEntity) entity.get()).getErrorMessage(), is(expectedError));
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) ErrorEntity(io.confluent.ksql.rest.entity.ErrorEntity) CreateConnector(io.confluent.ksql.parser.tree.CreateConnector) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) Test(org.junit.Test)

Example 4 with ErrorEntity

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

the class ConnectExecutorTest method shouldReturnErrorIfConnectorTypeIsMissing.

@Test
public void shouldReturnErrorIfConnectorTypeIsMissing() {
    // Given:
    final CreateConnector createConnectorMissingType = new CreateConnector("connector-name", ImmutableMap.of("foo", new StringLiteral("bar")), Type.SOURCE, false);
    final ConfiguredStatement<CreateConnector> createConnectorMissingTypeConfigured = ConfiguredStatement.of(PreparedStatement.of("CREATE SOURCE CONNECTOR foo WITH ('foo'='bar');", createConnectorMissingType), SessionConfig.of(CONFIG, ImmutableMap.of()));
    // When:
    final Optional<KsqlEntity> entity = EXECUTOR.execute(createConnectorMissingTypeConfigured, mock(SessionProperties.class), null, serviceContext).getEntity();
    // Then:
    assertThat("Expected non-empty response", entity.isPresent());
    assertThat(entity.get(), instanceOf(ErrorEntity.class));
    final String expectedError = "Validation error: " + "Connector config {name=connector-name, foo=bar} contains no connector type";
    assertThat(((ErrorEntity) entity.get()).getErrorMessage(), is(expectedError));
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) ErrorEntity(io.confluent.ksql.rest.entity.ErrorEntity) CreateConnector(io.confluent.ksql.parser.tree.CreateConnector) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) Test(org.junit.Test)

Example 5 with ErrorEntity

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

the class ConnectExecutorTest method shouldReturnErrorEntityOnValidationError.

@Test
public void shouldReturnErrorEntityOnValidationError() {
    // Given:
    givenValidationError();
    givenCreationSuccess();
    // When:
    final Optional<KsqlEntity> entity = EXECUTOR.execute(CREATE_CONNECTOR_CONFIGURED, mock(SessionProperties.class), null, serviceContext).getEntity();
    // Then:
    assertThat("Expected non-empty response", entity.isPresent());
    assertThat(entity.get(), instanceOf(ErrorEntity.class));
    final String expectedError = "Validation error: name - Name is missing\n" + "hostname - Hostname is required. Some other error";
    assertThat(((ErrorEntity) entity.get()).getErrorMessage(), is(expectedError));
}
Also used : ErrorEntity(io.confluent.ksql.rest.entity.ErrorEntity) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) Test(org.junit.Test)

Aggregations

ErrorEntity (io.confluent.ksql.rest.entity.ErrorEntity)7 KsqlEntity (io.confluent.ksql.rest.entity.KsqlEntity)6 Test (org.junit.Test)6 CreateConnector (io.confluent.ksql.parser.tree.CreateConnector)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 BaseApiTest (io.confluent.ksql.api.BaseApiTest)1 KsqlClientException (io.confluent.ksql.api.client.exception.KsqlClientException)1 KsqlException (io.confluent.ksql.api.client.exception.KsqlException)1 KsqlApiException (io.confluent.ksql.api.server.KsqlApiException)1 KafkaResponseGetFailedException (io.confluent.ksql.exception.KafkaResponseGetFailedException)1 ParseFailedException (io.confluent.ksql.parser.exception.ParseFailedException)1 CreateConnectorEntity (io.confluent.ksql.rest.entity.CreateConnectorEntity)1 ConnectClient (io.confluent.ksql.services.ConnectClient)1 ExecutionException (java.util.concurrent.ExecutionException)1 ConnectorInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo)1