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