Search in sources :

Example 6 with SourceDescriptionList

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

the class ListSourceExecutorTest method shouldDescribeTables.

@Test
public void shouldDescribeTables() {
    // Given:
    final KsqlTable<?> table1 = engine.givenSource(DataSourceType.KTABLE, "table1");
    final KsqlTable<?> table2 = engine.givenSource(DataSourceType.KTABLE, "table2", ImmutableSet.of(SourceName.of("table1")));
    engine.givenSource(DataSourceType.KSTREAM, "stream");
    // When:
    final SourceDescriptionList descriptionList = (SourceDescriptionList) CUSTOM_EXECUTORS.describeTables().execute((ConfiguredStatement<DescribeTables>) engine.configure("DESCRIBE TABLES;"), SESSION_PROPERTIES, engine.getEngine(), engine.getServiceContext()).getEntity().orElseThrow(IllegalStateException::new);
    // Then:
    assertThat(descriptionList.getSourceDescriptions(), containsInAnyOrder(SourceDescriptionFactory.create(table1, false, ImmutableList.of(), ImmutableList.of(), Optional.of(topicWith1PartitionAndRfOf1), ImmutableList.of(), ImmutableList.of("table2"), new MetricCollectors()), SourceDescriptionFactory.create(table2, false, ImmutableList.of(), ImmutableList.of(), Optional.of(topicWith1PartitionAndRfOf1), ImmutableList.of(), ImmutableList.of(), new MetricCollectors())));
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) SourceDescriptionList(io.confluent.ksql.rest.entity.SourceDescriptionList) MetricCollectors(io.confluent.ksql.metrics.MetricCollectors) Test(org.junit.Test)

Example 7 with SourceDescriptionList

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

the class ListSourceExecutorTest method shouldShowTablesExtended.

@Test
public void shouldShowTablesExtended() {
    // Given:
    final KsqlTable<?> table1 = engine.givenSource(DataSourceType.KTABLE, "table1");
    final KsqlTable<?> table2 = engine.givenSource(DataSourceType.KTABLE, "table2", ImmutableSet.of(SourceName.of("table1")));
    engine.givenSource(DataSourceType.KSTREAM, "stream");
    // When:
    final SourceDescriptionList descriptionList = (SourceDescriptionList) CUSTOM_EXECUTORS.listTables().execute((ConfiguredStatement<ListTables>) engine.configure("LIST TABLES EXTENDED;"), SESSION_PROPERTIES, engine.getEngine(), engine.getServiceContext()).getEntity().orElseThrow(IllegalStateException::new);
    // Then:
    final KafkaTopicClient client = engine.getServiceContext().getTopicClient();
    assertThat(descriptionList.getSourceDescriptions(), containsInAnyOrder(SourceDescriptionFactory.create(table1, true, ImmutableList.of(), ImmutableList.of(), Optional.of(client.describeTopic(table1.getKafkaTopicName())), ImmutableList.of(), ImmutableList.of("table2"), new MetricCollectors()), SourceDescriptionFactory.create(table2, true, ImmutableList.of(), ImmutableList.of(), Optional.of(client.describeTopic(table1.getKafkaTopicName())), ImmutableList.of(), ImmutableList.of(), new MetricCollectors())));
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) KafkaTopicClient(io.confluent.ksql.services.KafkaTopicClient) SourceDescriptionList(io.confluent.ksql.rest.entity.SourceDescriptionList) MetricCollectors(io.confluent.ksql.metrics.MetricCollectors) Test(org.junit.Test)

Example 8 with SourceDescriptionList

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

the class KsqlResourceTest method shouldShowStreamsExtended.

@Test
public void shouldShowStreamsExtended() {
    // Given:
    final LogicalSchema schema = LogicalSchema.builder().keyColumn(SystemColumns.ROWKEY_NAME, SqlTypes.STRING).valueColumn(ColumnName.of("FIELD1"), SqlTypes.BOOLEAN).valueColumn(ColumnName.of("FIELD2"), SqlTypes.STRING).build();
    givenSource(DataSourceType.KSTREAM, "new_stream", "new_topic", schema);
    // When:
    final SourceDescriptionList descriptionList = makeSingleRequest("SHOW STREAMS EXTENDED;", SourceDescriptionList.class);
    // Then:
    assertThat(descriptionList.getSourceDescriptions(), containsInAnyOrder(SourceDescriptionFactory.create(ksqlEngine.getMetaStore().getSource(SourceName.of("TEST_STREAM")), true, Collections.emptyList(), Collections.emptyList(), Optional.of(kafkaTopicClient.describeTopic("KAFKA_TOPIC_2")), Collections.emptyList(), Collections.emptyList(), new MetricCollectors()), SourceDescriptionFactory.create(ksqlEngine.getMetaStore().getSource(SourceName.of("new_stream")), true, Collections.emptyList(), Collections.emptyList(), Optional.of(kafkaTopicClient.describeTopic("new_topic")), Collections.emptyList(), Collections.emptyList(), new MetricCollectors())));
}
Also used : SourceDescriptionList(io.confluent.ksql.rest.entity.SourceDescriptionList) MetricCollectors(io.confluent.ksql.metrics.MetricCollectors) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Test(org.junit.Test)

Example 9 with SourceDescriptionList

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

the class KsqlResourceTest method shouldHaveKsqlWarningIfCommandRunnerDegraded.

@Test
public void shouldHaveKsqlWarningIfCommandRunnerDegraded() {
    // Given:
    final LogicalSchema schema = LogicalSchema.builder().keyColumn(SystemColumns.ROWKEY_NAME, SqlTypes.STRING).valueColumn(ColumnName.of("FIELD1"), SqlTypes.BOOLEAN).valueColumn(ColumnName.of("FIELD2"), SqlTypes.STRING).build();
    givenSource(DataSourceType.KSTREAM, "new_stream", "new_topic", schema);
    // When:
    final SourceDescriptionList descriptionList1 = makeSingleRequest("SHOW STREAMS EXTENDED;", SourceDescriptionList.class);
    when(commandRunnerWarning.get()).thenReturn(DefaultErrorMessages.COMMAND_RUNNER_DEGRADED_INCOMPATIBLE_COMMANDS_ERROR_MESSAGE);
    final SourceDescriptionList descriptionList2 = makeSingleRequest("SHOW STREAMS EXTENDED;", SourceDescriptionList.class);
    assertThat(descriptionList1.getWarnings().size(), is(0));
    assertThat(descriptionList2.getWarnings().size(), is(1));
    assertThat(descriptionList2.getWarnings().get(0).getMessage(), is(DefaultErrorMessages.COMMAND_RUNNER_DEGRADED_INCOMPATIBLE_COMMANDS_ERROR_MESSAGE));
}
Also used : SourceDescriptionList(io.confluent.ksql.rest.entity.SourceDescriptionList) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Test(org.junit.Test)

Example 10 with SourceDescriptionList

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

the class ListSourceExecutorTest method assertSourceListWithWarning.

private static void assertSourceListWithWarning(final KsqlEntity entity, final DataSource... sources) {
    assertThat(entity, instanceOf(SourceDescriptionList.class));
    final SourceDescriptionList listing = (SourceDescriptionList) entity;
    assertThat(listing.getSourceDescriptions(), containsInAnyOrder(Arrays.stream(sources).map(s -> equalTo(SourceDescriptionFactory.create(s, true, ImmutableList.of(), ImmutableList.of(), Optional.empty(), ImmutableList.of(), ImmutableList.of(), new MetricCollectors()))).collect(Collectors.toList())));
    assertThat(listing.getWarnings(), containsInAnyOrder(Arrays.stream(sources).map(s -> equalTo(new KsqlWarning("Error from Kafka: unknown topic: " + s.getKafkaTopicName()))).collect(Collectors.toList())));
}
Also used : DataSource(io.confluent.ksql.metastore.model.DataSource) Arrays(java.util.Arrays) StreamsList(io.confluent.ksql.rest.entity.StreamsList) SessionProperties(io.confluent.ksql.rest.SessionProperties) SourceName(io.confluent.ksql.name.SourceName) RunningQuery(io.confluent.ksql.rest.entity.RunningQuery) DescribeTables(io.confluent.ksql.parser.tree.DescribeTables) ServiceContext(io.confluent.ksql.services.ServiceContext) ExecuteResult(io.confluent.ksql.KsqlExecutionContext.ExecuteResult) SourceDescriptionList(io.confluent.ksql.rest.entity.SourceDescriptionList) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) KsqlTable(io.confluent.ksql.metastore.model.KsqlTable) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) TemporaryEngine(io.confluent.ksql.rest.server.TemporaryEngine) ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) Collectors(java.util.stream.Collectors) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) TestServiceContext(io.confluent.ksql.services.TestServiceContext) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) Node(org.apache.kafka.common.Node) Matchers.containsString(org.hamcrest.Matchers.containsString) KsqlConstants(io.confluent.ksql.util.KsqlConstants) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Mockito.mock(org.mockito.Mockito.mock) FormatOptions(io.confluent.ksql.schema.utils.FormatOptions) Mock(org.mockito.Mock) Assert.assertThrows(org.junit.Assert.assertThrows) RunWith(org.junit.runner.RunWith) DataSourceType(io.confluent.ksql.metastore.model.DataSource.DataSourceType) Mockito.spy(org.mockito.Mockito.spy) MetricCollectors(io.confluent.ksql.metrics.MetricCollectors) KafkaTopicClient(io.confluent.ksql.services.KafkaTopicClient) KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) SessionConfig(io.confluent.ksql.config.SessionConfig) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) QueryStatusCount(io.confluent.ksql.rest.entity.QueryStatusCount) ImmutableList(com.google.common.collect.ImmutableList) SourceDescriptionEntity(io.confluent.ksql.rest.entity.SourceDescriptionEntity) ShowColumns(io.confluent.ksql.parser.tree.ShowColumns) DescribeStreams(io.confluent.ksql.parser.tree.DescribeStreams) TablesList(io.confluent.ksql.rest.entity.TablesList) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TopicDescription(org.apache.kafka.clients.admin.TopicDescription) ListTables(io.confluent.ksql.parser.tree.ListTables) Before(org.junit.Before) TopicPartitionInfo(org.apache.kafka.common.TopicPartitionInfo) ListStreams(io.confluent.ksql.parser.tree.ListStreams) EasyRandom(org.jeasy.random.EasyRandom) SourceDescriptionFactory(io.confluent.ksql.rest.entity.SourceDescriptionFactory) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) KsqlStream(io.confluent.ksql.metastore.model.KsqlStream) Mockito.verify(org.mockito.Mockito.verify) SourceInfo(io.confluent.ksql.rest.entity.SourceInfo) KsqlStatementException(io.confluent.ksql.util.KsqlStatementException) Mockito.never(org.mockito.Mockito.never) Rule(org.junit.Rule) Collections(java.util.Collections) PreparedStatement(io.confluent.ksql.parser.KsqlParser.PreparedStatement) KsqlWarning(io.confluent.ksql.rest.entity.KsqlWarning) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SourceDescriptionList(io.confluent.ksql.rest.entity.SourceDescriptionList) MetricCollectors(io.confluent.ksql.metrics.MetricCollectors) KsqlWarning(io.confluent.ksql.rest.entity.KsqlWarning)

Aggregations

SourceDescriptionList (io.confluent.ksql.rest.entity.SourceDescriptionList)13 Test (org.junit.Test)12 MetricCollectors (io.confluent.ksql.metrics.MetricCollectors)11 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)7 ConfiguredStatement (io.confluent.ksql.statement.ConfiguredStatement)6 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 DataSource (io.confluent.ksql.metastore.model.DataSource)2 KsqlStream (io.confluent.ksql.metastore.model.KsqlStream)2 KsqlTable (io.confluent.ksql.metastore.model.KsqlTable)2 SourceName (io.confluent.ksql.name.SourceName)2 DescribeStreams (io.confluent.ksql.parser.tree.DescribeStreams)2 DescribeTables (io.confluent.ksql.parser.tree.DescribeTables)2 ListStreams (io.confluent.ksql.parser.tree.ListStreams)2 ListTables (io.confluent.ksql.parser.tree.ListTables)2 ShowColumns (io.confluent.ksql.parser.tree.ShowColumns)2 SessionProperties (io.confluent.ksql.rest.SessionProperties)2 KsqlEntity (io.confluent.ksql.rest.entity.KsqlEntity)2 KsqlWarning (io.confluent.ksql.rest.entity.KsqlWarning)2 QueryStatusCount (io.confluent.ksql.rest.entity.QueryStatusCount)2