Search in sources :

Example 1 with CommandId

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

the class ClientTest method shouldSendCustomRequestHeaders.

@Test
public void shouldSendCustomRequestHeaders() throws Exception {
    // Given:
    final CommandStatusEntity entity = new CommandStatusEntity("CSAS;", new CommandId("STREAM", "FOO", "CREATE"), new CommandStatus(CommandStatus.Status.SUCCESS, "Success"), 0L);
    testEndpoints.setKsqlEndpointResponse(Collections.singletonList(entity));
    // When:
    javaClient.executeStatement("CSAS;").get();
    // Then:
    final List<Entry<String, String>> requestHeaders = testEndpoints.getLastApiSecurityContext().getRequestHeaders();
    for (final Entry<String, String> header : REQUEST_HEADERS.entrySet()) {
        assertThat(requestHeaders, hasItems(entry(header)));
    }
}
Also used : Entry(java.util.Map.Entry) CommandStatus(io.confluent.ksql.rest.entity.CommandStatus) CommandId(io.confluent.ksql.rest.entity.CommandId) Matchers.containsString(org.hamcrest.Matchers.containsString) CommandStatusEntity(io.confluent.ksql.rest.entity.CommandStatusEntity) BaseApiTest(io.confluent.ksql.api.BaseApiTest) Test(org.junit.Test)

Example 2 with CommandId

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

the class ClientTest method shouldExecuteStatementWithoutQueryId.

@Test
public void shouldExecuteStatementWithoutQueryId() throws Exception {
    // Given
    final CommandStatusEntity entity = new CommandStatusEntity("CSAS;", new CommandId("STREAM", "FOO", "CREATE"), new CommandStatus(CommandStatus.Status.SUCCESS, "Success"), 0L);
    testEndpoints.setKsqlEndpointResponse(Collections.singletonList(entity));
    final Map<String, Object> properties = ImmutableMap.of("auto.offset.reset", "earliest");
    // When
    final ExecuteStatementResult result = javaClient.executeStatement("CSAS;", properties).get();
    // Then
    assertThat(testEndpoints.getLastSql(), is("CSAS;"));
    assertThat(testEndpoints.getLastProperties(), is(new JsonObject().put("auto.offset.reset", "earliest")));
    assertThat(result.queryId(), is(Optional.empty()));
}
Also used : JsonObject(io.vertx.core.json.JsonObject) CommandStatus(io.confluent.ksql.rest.entity.CommandStatus) JsonObject(io.vertx.core.json.JsonObject) CommandId(io.confluent.ksql.rest.entity.CommandId) Matchers.containsString(org.hamcrest.Matchers.containsString) CommandStatusEntity(io.confluent.ksql.rest.entity.CommandStatusEntity) BaseApiTest(io.confluent.ksql.api.BaseApiTest) Test(org.junit.Test)

Example 3 with CommandId

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

the class CommandStore method getNewCommands.

@Override
public List<QueuedCommand> getNewCommands(final Duration timeout) {
    completeSatisfiedSequenceNumberFutures();
    final List<QueuedCommand> commands = Lists.newArrayList();
    final Iterable<ConsumerRecord<byte[], byte[]>> records = commandTopic.getNewCommands(timeout);
    for (ConsumerRecord<byte[], byte[]> record : records) {
        if (record.value() != null) {
            Optional<CommandStatusFuture> commandStatusFuture = Optional.empty();
            try {
                final CommandId commandId = commandIdDeserializer.deserialize(commandTopicName, record.key());
                commandStatusFuture = Optional.ofNullable(commandStatusMap.remove(commandId));
            } catch (Exception e) {
                LOG.warn("Error while attempting to fetch from commandStatusMap for key {}", record.key(), e);
            }
            commands.add(new QueuedCommand(record.key(), record.value(), commandStatusFuture, record.offset()));
        }
    }
    return commands;
}
Also used : CommandId(io.confluent.ksql.rest.entity.CommandId) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException) KsqlServerException(io.confluent.ksql.util.KsqlServerException) KsqlException(io.confluent.ksql.util.KsqlException)

Example 4 with CommandId

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

the class StatusResourceTest method testGetStatus.

@Test
public void testGetStatus() throws Exception {
    final StatusResource testResource = getTestStatusResource();
    for (final Map.Entry<CommandId, CommandStatus> commandEntry : mockCommandStatuses.entrySet()) {
        final CommandId commandId = commandEntry.getKey();
        final CommandStatus expectedCommandStatus = commandEntry.getValue();
        final Object statusEntity = testResource.getStatus(commandId.getType().name(), commandId.getEntity(), commandId.getAction().name()).getEntity();
        assertThat(statusEntity, instanceOf(CommandStatus.class));
        final CommandStatus testCommandStatus = (CommandStatus) statusEntity;
        assertEquals(expectedCommandStatus, testCommandStatus);
    }
}
Also used : CommandStatus(io.confluent.ksql.rest.entity.CommandStatus) EasyMock.anyObject(org.easymock.EasyMock.anyObject) CommandId(io.confluent.ksql.rest.entity.CommandId) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 5 with CommandId

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

the class InteractiveStatementExecutorTest method shouldTerminateAll.

@Test
public void shouldTerminateAll() {
    // Given:
    final String queryStatement = "a persistent query";
    final TerminateQuery terminateAll = mock(TerminateQuery.class);
    when(terminateAll.getQueryId()).thenReturn(Optional.empty());
    when(mockParser.parseSingleStatement(any())).thenReturn(PreparedStatement.of(queryStatement, terminateAll));
    final PersistentQueryMetadata query0 = mock(PersistentQueryMetadata.class);
    final PersistentQueryMetadata query1 = mock(PersistentQueryMetadata.class);
    when(mockEngine.getPersistentQueries()).thenReturn(ImmutableList.of(query0, query1));
    final Command command = new Command("terminate all", emptyMap(), emptyMap(), Optional.empty());
    when(commandDeserializer.deserialize(any(), any())).thenReturn(command);
    // When:
    statementExecutorWithMocks.handleStatement(new QueuedCommand(new CommandId(Type.TERMINATE, "-", Action.EXECUTE), command, Optional.empty(), 0L));
    // Then:
    verify(query0).close();
    verify(query1).close();
}
Also used : TerminateQuery(io.confluent.ksql.parser.tree.TerminateQuery) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) CommandId(io.confluent.ksql.rest.entity.CommandId) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) Test(org.junit.Test)

Aggregations

CommandId (io.confluent.ksql.rest.entity.CommandId)29 Test (org.junit.Test)20 CommandStatus (io.confluent.ksql.rest.entity.CommandStatus)13 CommandStatusEntity (io.confluent.ksql.rest.entity.CommandStatusEntity)7 QueryId (io.confluent.ksql.query.QueryId)6 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 BaseApiTest (io.confluent.ksql.api.BaseApiTest)5 KsqlException (io.confluent.ksql.util.KsqlException)5 Command (io.confluent.ksql.rest.server.computation.Command)4 JsonObject (io.vertx.core.json.JsonObject)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 IntegrationTest (io.confluent.common.utils.IntegrationTest)3 KsqlServerException (io.confluent.ksql.util.KsqlServerException)3 PersistentQueryMetadata (io.confluent.ksql.util.PersistentQueryMetadata)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ExecutionException (java.util.concurrent.ExecutionException)3 TimeoutException (java.util.concurrent.TimeoutException)3 KsqlPlan (io.confluent.ksql.engine.KsqlPlan)2