Search in sources :

Example 31 with ConfiguredStatement

use of io.confluent.ksql.statement.ConfiguredStatement 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 32 with ConfiguredStatement

use of io.confluent.ksql.statement.ConfiguredStatement in project ksql by confluentinc.

the class ListTopicsExecutorTest method shouldListKafkaTopicsWithoutInternalTopics.

@Test
public void shouldListKafkaTopicsWithoutInternalTopics() {
    // Given:
    engine.givenKafkaTopic("topic1");
    engine.givenKafkaTopic("topic2");
    engine.givenKafkaTopic("_confluent_any_topic");
    // When:
    final KafkaTopicsList topicsList = (KafkaTopicsList) CUSTOM_EXECUTORS.listTopics().execute((ConfiguredStatement<ListTopics>) engine.configure("LIST TOPICS;"), mock(SessionProperties.class), engine.getEngine(), serviceContext).getEntity().orElseThrow(IllegalStateException::new);
    // Then:
    assertThat(topicsList.getTopics(), containsInAnyOrder(new KafkaTopicInfo("topic1", ImmutableList.of(1)), new KafkaTopicInfo("topic2", ImmutableList.of(1))));
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) KafkaTopicInfo(io.confluent.ksql.rest.entity.KafkaTopicInfo) KafkaTopicsList(io.confluent.ksql.rest.entity.KafkaTopicsList) Test(org.junit.Test)

Example 33 with ConfiguredStatement

use of io.confluent.ksql.statement.ConfiguredStatement in project ksql by confluentinc.

the class ListTopicsExecutorTest method shouldListKafkaTopicsThatDifferByCase.

@Test
public void shouldListKafkaTopicsThatDifferByCase() {
    // Given:
    engine.givenKafkaTopic("topic1");
    engine.givenKafkaTopic("toPIc1");
    // When:
    final KafkaTopicsList topicsList = (KafkaTopicsList) CUSTOM_EXECUTORS.listTopics().execute((ConfiguredStatement<ListTopics>) engine.configure("LIST TOPICS;"), mock(SessionProperties.class), engine.getEngine(), serviceContext).getEntity().orElseThrow(IllegalStateException::new);
    // Then:
    assertThat(topicsList.getTopics(), containsInAnyOrder(new KafkaTopicInfo("topic1", ImmutableList.of(1)), new KafkaTopicInfo("toPIc1", ImmutableList.of(1))));
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) KafkaTopicInfo(io.confluent.ksql.rest.entity.KafkaTopicInfo) KafkaTopicsList(io.confluent.ksql.rest.entity.KafkaTopicsList) Test(org.junit.Test)

Example 34 with ConfiguredStatement

use of io.confluent.ksql.statement.ConfiguredStatement in project ksql by confluentinc.

the class ListTopicsExecutorTest method shouldListKafkaTopicsExtended.

@Test
public void shouldListKafkaTopicsExtended() {
    // Given:
    engine.givenKafkaTopic("topic1");
    engine.givenKafkaTopic("topic2");
    final ListConsumerGroupsResult result = mock(ListConsumerGroupsResult.class);
    final KafkaFutureImpl<Collection<ConsumerGroupListing>> groups = new KafkaFutureImpl<>();
    when(result.all()).thenReturn(groups);
    when(adminClient.listConsumerGroups()).thenReturn(result);
    groups.complete(ImmutableList.of());
    // When:
    final KafkaTopicsListExtended topicsList = (KafkaTopicsListExtended) CUSTOM_EXECUTORS.listTopics().execute((ConfiguredStatement<ListTopics>) engine.configure("LIST TOPICS EXTENDED;"), mock(SessionProperties.class), engine.getEngine(), serviceContext).getEntity().orElseThrow(IllegalStateException::new);
    // Then:
    assertThat(topicsList.getTopics(), containsInAnyOrder(new KafkaTopicInfoExtended("topic1", ImmutableList.of(1), 0, 0), new KafkaTopicInfoExtended("topic2", ImmutableList.of(1), 0, 0)));
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) KafkaTopicInfoExtended(io.confluent.ksql.rest.entity.KafkaTopicInfoExtended) Collection(java.util.Collection) KafkaTopicsListExtended(io.confluent.ksql.rest.entity.KafkaTopicsListExtended) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) ListConsumerGroupsResult(org.apache.kafka.clients.admin.ListConsumerGroupsResult) Test(org.junit.Test)

Example 35 with ConfiguredStatement

use of io.confluent.ksql.statement.ConfiguredStatement in project ksql by confluentinc.

the class ExplainExecutorTest method shouldFailOnNonQueryExplain.

@Test
public void shouldFailOnNonQueryExplain() {
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> customExecutors.explain().execute((ConfiguredStatement<Explain>) engine.configure("Explain SHOW TOPICS;"), sessionProperties, engine.getEngine(), engine.getServiceContext()));
    // Then:
    assertThat(e.getMessage(), containsString("The provided statement does not run a ksql query"));
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Aggregations

ConfiguredStatement (io.confluent.ksql.statement.ConfiguredStatement)84 Test (org.junit.Test)57 KsqlException (io.confluent.ksql.util.KsqlException)23 Statement (io.confluent.ksql.parser.tree.Statement)22 PreparedStatement (io.confluent.ksql.parser.KsqlParser.PreparedStatement)19 Optional (java.util.Optional)19 ServiceContext (io.confluent.ksql.services.ServiceContext)18 PersistentQueryMetadata (io.confluent.ksql.util.PersistentQueryMetadata)18 KsqlEngine (io.confluent.ksql.engine.KsqlEngine)17 KsqlConfig (io.confluent.ksql.util.KsqlConfig)16 Map (java.util.Map)14 DataSource (io.confluent.ksql.metastore.model.DataSource)12 QueryId (io.confluent.ksql.query.QueryId)12 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)12 Collectors (java.util.stream.Collectors)12 ImmutableMap (com.google.common.collect.ImmutableMap)11 ListQueries (io.confluent.ksql.parser.tree.ListQueries)11 KsqlStatementException (io.confluent.ksql.util.KsqlStatementException)11 List (java.util.List)11 Query (io.confluent.ksql.parser.tree.Query)10