use of io.confluent.ksql.rest.entity.CommandId in project ksql by confluentinc.
the class InteractiveStatementExecutorTest method shouldSkipStartWhenReplayingLog.
@Test
public void shouldSkipStartWhenReplayingLog() {
// Given:
final QueryId queryId = new QueryId("csas-query-id");
final String name = "foo";
final PersistentQueryMetadata mockQuery = mockReplayCSAS(queryId);
final Command command = new Command("CSAS", emptyMap(), emptyMap(), Optional.of(plan));
when(commandDeserializer.deserialize(any(), any())).thenReturn(command);
// When:
statementExecutorWithMocks.handleRestore(new QueuedCommand(new CommandId(Type.STREAM, name, Action.CREATE), command, Optional.empty(), 0L));
// Then:
verify(mockQueryIdGenerator, times(1)).setNextId(anyLong());
verify(mockQuery, times(0)).start();
}
use of io.confluent.ksql.rest.entity.CommandId in project ksql by confluentinc.
the class InteractiveStatementExecutorTest method shouldThrowOnUnexpectedException.
@Test
public void shouldThrowOnUnexpectedException() {
// Given:
final String statementText = "mama said knock you out";
final RuntimeException exception = new RuntimeException("i'm gonna knock you out");
when(mockParser.parseSingleStatement(statementText)).thenThrow(exception);
final Command command = new Command(statementText, emptyMap(), emptyMap(), Optional.empty());
final CommandId commandId = new CommandId(CommandId.Type.STREAM, "_CSASGen", CommandId.Action.CREATE);
// When:
try {
handleStatement(statementExecutorWithMocks, command, commandId, Optional.empty(), 0);
Assert.fail("handleStatement should throw");
} catch (final RuntimeException caughtException) {
// Then:
assertThat(caughtException, is(exception));
}
}
use of io.confluent.ksql.rest.entity.CommandId in project ksql by confluentinc.
the class InteractiveStatementExecutorTest method shouldDoIdempotentTerminate.
@Test
public void shouldDoIdempotentTerminate() {
// Given:
final String queryStatement = "a persistent query";
final TerminateQuery terminate = mock(TerminateQuery.class);
when(terminate.getQueryId()).thenReturn(Optional.of(new QueryId("foo")));
when(mockParser.parseSingleStatement(any())).thenReturn(PreparedStatement.of(queryStatement, terminate));
final PersistentQueryMetadata query = mock(PersistentQueryMetadata.class);
when(mockEngine.getPersistentQuery(new QueryId("foo"))).thenReturn(Optional.of(query)).thenReturn(Optional.empty());
final Command command = new Command("terminate all", emptyMap(), emptyMap(), Optional.empty());
when(commandDeserializer.deserialize(any(), any())).thenReturn(command);
final QueuedCommand cmd = new QueuedCommand(new CommandId(Type.TERMINATE, "-", Action.EXECUTE), command, Optional.empty(), 0L);
// When:
statementExecutorWithMocks.handleStatement(cmd);
statementExecutorWithMocks.handleStatement(cmd);
// Then should not throw
}
use of io.confluent.ksql.rest.entity.CommandId in project ksql by confluentinc.
the class InteractiveStatementExecutorTest method shouldEnforceReferentialIntegrity.
@Test
public void shouldEnforceReferentialIntegrity() {
createStreamsAndStartTwoPersistentQueries();
// Now try to drop streams/tables to test referential integrity
assertThrows(KsqlStatementException.class, () -> tryDropThatViolatesReferentialIntegrity());
// Terminate the queries using the stream/table
terminateQueries();
// Drop user1pv stream, which is linked to the pageview stream.
// The user1pv query will be terminated during the drop.
final Command dropStreamCommand1 = commandWithPlan("drop stream user1pv;", ksqlConfig.getAllConfigPropsWithSecretsObfuscated());
final CommandId dropStreamCommandId1 = new CommandId(Type.STREAM, "_user1pv", CommandId.Action.DROP);
handleStatement(statementExecutor, dropStreamCommand1, dropStreamCommandId1, Optional.empty(), 4);
// Now drop should be successful
final Command dropTableCommand2 = commandWithPlan("drop table table1;", ksqlConfig.getAllConfigPropsWithSecretsObfuscated());
final CommandId dropTableCommandId2 = new CommandId(CommandId.Type.TABLE, "_TABLE1", CommandId.Action.DROP);
handleStatement(statementExecutor, dropTableCommand2, dropTableCommandId2, Optional.empty(), 4);
// DROP should succeed since no query is using the table
final Optional<CommandStatus> dropTableCommandStatus2 = statementExecutor.getStatus(dropTableCommandId2);
Assert.assertTrue(dropTableCommandStatus2.isPresent());
assertThat(dropTableCommandStatus2.get().getStatus(), equalTo(CommandStatus.Status.SUCCESS));
// DROP should succeed since no query is using the stream.
final Command dropStreamCommand3 = commandWithPlan("drop stream pageview;", ksqlConfig.getAllConfigPropsWithSecretsObfuscated());
final CommandId dropStreamCommandId3 = new CommandId(CommandId.Type.STREAM, "_user1pv", CommandId.Action.DROP);
handleStatement(statementExecutor, dropStreamCommand3, dropStreamCommandId3, Optional.empty(), 5);
final Optional<CommandStatus> dropStreamCommandStatus3 = statementExecutor.getStatus(dropStreamCommandId3);
assertThat(dropStreamCommandStatus3.get().getStatus(), CoreMatchers.equalTo(CommandStatus.Status.SUCCESS));
}
use of io.confluent.ksql.rest.entity.CommandId in project ksql by confluentinc.
the class InteractiveStatementExecutorTest method shouldSetNextQueryIdToNextOffsetWhenExecutingRestoreCommand.
@Test
public void shouldSetNextQueryIdToNextOffsetWhenExecutingRestoreCommand() {
// Given:
mockReplayCSAS(new QueryId("csas-query-id"));
final Command command = new Command("CSAS", emptyMap(), emptyMap(), Optional.of(plan));
when(commandDeserializer.deserialize(any(), any())).thenReturn(command);
// When:
statementExecutorWithMocks.handleRestore(new QueuedCommand(new CommandId(Type.STREAM, "foo", Action.CREATE), command, Optional.empty(), 2L));
// Then:
verify(mockQueryIdGenerator).setNextId(3L);
}
Aggregations