Search in sources :

Example 6 with DropSourceCommand

use of io.confluent.ksql.execution.ddl.commands.DropSourceCommand in project ksql by confluentinc.

the class DdlCommandExecTest method shouldThrowOnDropStreamWhenConstraintExist.

@Test
public void shouldThrowOnDropStreamWhenConstraintExist() {
    // Given:
    final CreateStreamCommand stream1 = buildCreateStream(SourceName.of("s1"), SCHEMA, false, false);
    final CreateStreamCommand stream2 = buildCreateStream(SourceName.of("s2"), SCHEMA, false, false);
    final CreateStreamCommand stream3 = buildCreateStream(SourceName.of("s3"), SCHEMA, false, false);
    cmdExec.execute(SQL_TEXT, stream1, true, Collections.emptySet());
    cmdExec.execute(SQL_TEXT, stream2, true, Collections.singleton(SourceName.of("s1")));
    cmdExec.execute(SQL_TEXT, stream3, true, Collections.singleton(SourceName.of("s1")));
    // When:
    final DropSourceCommand dropStream = buildDropSourceCommand(SourceName.of("s1"));
    final Exception e = assertThrows(KsqlReferentialIntegrityException.class, () -> cmdExec.execute(SQL_TEXT, dropStream, false, Collections.emptySet()));
    // Then:
    assertThat(e.getMessage(), containsString("Cannot drop s1."));
    assertThat(e.getMessage(), containsString("The following streams and/or tables read from this source: [s2, s3]."));
    assertThat(e.getMessage(), containsString("You need to drop them before dropping s1."));
}
Also used : CreateStreamCommand(io.confluent.ksql.execution.ddl.commands.CreateStreamCommand) DropSourceCommand(io.confluent.ksql.execution.ddl.commands.DropSourceCommand) KsqlReferentialIntegrityException(io.confluent.ksql.util.KsqlReferentialIntegrityException) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Aggregations

DropSourceCommand (io.confluent.ksql.execution.ddl.commands.DropSourceCommand)6 Test (org.junit.Test)6 CreateStreamCommand (io.confluent.ksql.execution.ddl.commands.CreateStreamCommand)4 CommandId (io.confluent.ksql.rest.entity.CommandId)2 KsqlException (io.confluent.ksql.util.KsqlException)2 KsqlReferentialIntegrityException (io.confluent.ksql.util.KsqlReferentialIntegrityException)2 CreateTableCommand (io.confluent.ksql.execution.ddl.commands.CreateTableCommand)1 DdlCommandResult (io.confluent.ksql.execution.ddl.commands.DdlCommandResult)1 DropStream (io.confluent.ksql.parser.tree.DropStream)1