use of io.confluent.ksql.rest.entity.RunningQuery in project ksql by confluentinc.
the class ListQueriesExecutorTest method shouldNotMergeDifferentRunningQueries.
@Test
public void shouldNotMergeDifferentRunningQueries() {
// Given
when(sessionProperties.getInternalRequest()).thenReturn(false);
final ConfiguredStatement<ListQueries> showQueries = (ConfiguredStatement<ListQueries>) engine.configure("SHOW QUERIES;");
final PersistentQueryMetadata localMetadata = givenPersistentQuery("id", RUNNING_QUERY_STATE);
final PersistentQueryMetadata remoteMetadata = givenPersistentQuery("different Id", RUNNING_QUERY_STATE);
final KsqlEngine engine = mock(KsqlEngine.class);
when(engine.getAllLiveQueries()).thenReturn(ImmutableList.of(localMetadata));
when(engine.getPersistentQueries()).thenReturn(ImmutableList.of(localMetadata));
final List<RunningQuery> remoteRunningQueries = Collections.singletonList(persistentQueryMetadataToRunningQuery(remoteMetadata, QueryStatusCount.fromStreamsStateCounts(Collections.singletonMap(RUNNING_QUERY_STATE, 1))));
when(remoteQueries.getQueries()).thenReturn(remoteRunningQueries);
when(ksqlEntityList.get(anyInt())).thenReturn(remoteQueries);
when(response.getResponse()).thenReturn(ksqlEntityList);
queryStatusCount.updateStatusCount(RUNNING_QUERY_STATE, 1);
// When
final Queries queries = (Queries) CUSTOM_EXECUTORS.listQueries().execute(showQueries, sessionProperties, engine, serviceContext).getEntity().orElseThrow(IllegalStateException::new);
// Then
assertThat(queries.getQueries(), containsInAnyOrder(persistentQueryMetadataToRunningQuery(localMetadata, queryStatusCount), persistentQueryMetadataToRunningQuery(remoteMetadata, queryStatusCount)));
}
use of io.confluent.ksql.rest.entity.RunningQuery in project ksql by confluentinc.
the class TestKsqlRestApp method closePersistentQueries.
public void closePersistentQueries(final Optional<BasicCredentials> credentials) {
try (final KsqlRestClient client = buildKsqlClient(credentials)) {
// Filter source tables queries because they cannot be terminated manually
final Set<String> queriesToTerminate = getPersistentQueries(client).stream().filter(query -> !query.getQueryString().startsWith("CREATE SOURCE TABLE")).map(RunningQuery::getId).map(QueryId::toString).collect(Collectors.toSet());
terminateQueries(queriesToTerminate, client);
}
}
use of io.confluent.ksql.rest.entity.RunningQuery in project ksql by confluentinc.
the class ListQueriesExecutorTest method shouldScatterGatherAndMergeShowQueries.
@Test
public void shouldScatterGatherAndMergeShowQueries() {
// Given
when(sessionProperties.getInternalRequest()).thenReturn(false);
final ConfiguredStatement<ListQueries> showQueries = (ConfiguredStatement<ListQueries>) engine.configure("SHOW QUERIES;");
final PersistentQueryMetadata localMetadata = givenPersistentQuery("id", RUNNING_QUERY_STATE);
final PersistentQueryMetadata remoteMetadata = givenPersistentQuery("id", ERROR_QUERY_STATE);
final KsqlEngine engine = mock(KsqlEngine.class);
when(engine.getAllLiveQueries()).thenReturn(ImmutableList.of(localMetadata));
when(engine.getPersistentQueries()).thenReturn(ImmutableList.of(localMetadata));
final List<RunningQuery> remoteRunningQueries = Collections.singletonList(persistentQueryMetadataToRunningQuery(remoteMetadata, QueryStatusCount.fromStreamsStateCounts(Collections.singletonMap(ERROR_QUERY_STATE, 1))));
when(remoteQueries.getQueries()).thenReturn(remoteRunningQueries);
when(ksqlEntityList.get(anyInt())).thenReturn(remoteQueries);
when(response.getResponse()).thenReturn(ksqlEntityList);
queryStatusCount.updateStatusCount(RUNNING_QUERY_STATE, 1);
queryStatusCount.updateStatusCount(ERROR_QUERY_STATE, 1);
// When
final Queries queries = (Queries) CUSTOM_EXECUTORS.listQueries().execute(showQueries, sessionProperties, engine, serviceContext).getEntity().orElseThrow(IllegalStateException::new);
// Then
assertThat(queries.getQueries(), containsInAnyOrder(persistentQueryMetadataToRunningQuery(localMetadata, queryStatusCount)));
}
use of io.confluent.ksql.rest.entity.RunningQuery in project ksql by confluentinc.
the class KsqlResourceTest method shouldDescribeStatement.
@Test
public void shouldDescribeStatement() {
// Given:
final List<RunningQuery> queries = createRunningQueries("CREATE STREAM described_stream AS SELECT * FROM test_stream;" + "CREATE STREAM down_stream AS SELECT * FROM described_stream;", emptyMap());
// When:
final SourceDescriptionEntity description = makeSingleRequest("DESCRIBE DESCRIBED_STREAM;", SourceDescriptionEntity.class);
// Then:
final SourceDescription expectedDescription = SourceDescriptionFactory.create(ksqlEngine.getMetaStore().getSource(SourceName.of("DESCRIBED_STREAM")), false, Collections.singletonList(queries.get(1)), Collections.singletonList(queries.get(0)), Optional.empty(), Collections.emptyList(), Collections.emptyList(), new MetricCollectors());
assertThat(description.getSourceDescription(), is(expectedDescription));
}
use of io.confluent.ksql.rest.entity.RunningQuery in project ksql by confluentinc.
the class ListSourceExecutorTest method shouldShowColumnsSource.
@Test
public void shouldShowColumnsSource() {
// Given:
engine.givenSource(DataSourceType.KSTREAM, "SOURCE");
final ExecuteResult result = engine.getEngine().execute(engine.getServiceContext(), engine.configure("CREATE STREAM SINK AS SELECT * FROM source;"));
final PersistentQueryMetadata metadata = (PersistentQueryMetadata) result.getQuery().orElseThrow(IllegalArgumentException::new);
final DataSource stream = engine.getEngine().getMetaStore().getSource(SourceName.of("SINK"));
// When:
final SourceDescriptionEntity sourceDescription = (SourceDescriptionEntity) CUSTOM_EXECUTORS.showColumns().execute(ConfiguredStatement.of(PreparedStatement.of("DESCRIBE SINK;", new ShowColumns(SourceName.of("SINK"), false)), SessionConfig.of(engine.getKsqlConfig(), ImmutableMap.of())), SESSION_PROPERTIES, engine.getEngine(), engine.getServiceContext()).getEntity().orElseThrow(IllegalStateException::new);
// Then:
final QueryStatusCount queryStatusCount = QueryStatusCount.fromStreamsStateCounts(Collections.singletonMap(metadata.getState(), 1));
assertThat(sourceDescription.getSourceDescription(), equalTo(SourceDescriptionFactory.create(stream, false, ImmutableList.of(), ImmutableList.of(new RunningQuery(metadata.getStatementString(), ImmutableSet.of(metadata.getSinkName().get().toString(FormatOptions.noEscape())), ImmutableSet.of(metadata.getResultTopic().get().getKafkaTopicName()), metadata.getQueryId(), queryStatusCount, KsqlConstants.KsqlQueryType.PERSISTENT)), Optional.empty(), ImmutableList.of(), ImmutableList.of(), new MetricCollectors())));
}
Aggregations