use of io.confluent.ksql.statement.ConfiguredStatement in project ksql by confluentinc.
the class ListFunctionsExecutorTest method shouldListFunctions.
@Test
public void shouldListFunctions() {
// When:
final FunctionNameList functionList = (FunctionNameList) CUSTOM_EXECUTORS.listFunctions().execute((ConfiguredStatement<ListFunctions>) engine.configure("LIST FUNCTIONS;"), mock(SessionProperties.class), engine.getEngine(), engine.getServiceContext()).getEntity().orElseThrow(IllegalStateException::new);
// Then:
final Collection<SimpleFunctionInfo> functions = functionList.getFunctions();
assertThat(functions, hasItems(new SimpleFunctionInfo("TEST_UDF_1", FunctionType.SCALAR, FunctionCategory.OTHER), new SimpleFunctionInfo("TOPK", FunctionType.AGGREGATE, FunctionCategory.AGGREGATE), new SimpleFunctionInfo("MAX", FunctionType.AGGREGATE, FunctionCategory.AGGREGATE), new SimpleFunctionInfo("TEST_UDTF1", FunctionType.TABLE, FunctionCategory.TABLE), new SimpleFunctionInfo("TEST_UDTF2", FunctionType.TABLE, FunctionCategory.TABLE)));
}
use of io.confluent.ksql.statement.ConfiguredStatement in project ksql by confluentinc.
the class ListQueriesExecutorTest method shouldIncludeUnresponsiveIfShowQueriesExtendedFutureThrowsException.
@Test
public void shouldIncludeUnresponsiveIfShowQueriesExtendedFutureThrowsException() {
// Given
when(sessionProperties.getInternalRequest()).thenReturn(false);
final ConfiguredStatement<ListQueries> showQueries = (ConfiguredStatement<ListQueries>) engine.configure("SHOW QUERIES EXTENDED;");
final PersistentQueryMetadata metadata = givenPersistentQuery("id", RUNNING_QUERY_STATE);
final KsqlEngine engine = mock(KsqlEngine.class);
when(engine.getAllLiveQueries()).thenReturn(ImmutableList.of(metadata));
when(engine.getPersistentQueries()).thenReturn(ImmutableList.of(metadata));
when(ksqlClient.makeKsqlRequest(any(), any(), any())).thenThrow(new KsqlRestClientException("error"));
when(serviceContext.getKsqlClient()).thenReturn(ksqlClient);
// When
final Map<KsqlHostInfoEntity, KsqlQueryStatus> map = new HashMap<>();
map.put(LOCAL_KSQL_HOST_INFO_ENTITY, KsqlQueryStatus.RUNNING);
map.put(REMOTE_KSQL_HOST_INFO_ENTITY, KsqlQueryStatus.UNRESPONSIVE);
// When
final QueryDescriptionList queries = (QueryDescriptionList) CUSTOM_EXECUTORS.listQueries().execute(showQueries, sessionProperties, engine, serviceContext).getEntity().orElseThrow(IllegalStateException::new);
// Then
assertThat(queries.getQueryDescriptions(), containsInAnyOrder(QueryDescriptionFactory.forQueryMetadata(metadata, map)));
}
use of io.confluent.ksql.statement.ConfiguredStatement in project ksql by confluentinc.
the class ListQueriesExecutorTest method shouldListQueriesEmpty.
@Test
public void shouldListQueriesEmpty() {
// When
final Queries queries = (Queries) CUSTOM_EXECUTORS.listQueries().execute((ConfiguredStatement<ListQueries>) engine.configure("SHOW QUERIES;"), mock(SessionProperties.class), engine.getEngine(), engine.getServiceContext()).getEntity().orElseThrow(IllegalStateException::new);
assertThat(queries.getQueries(), is(empty()));
}
use of io.confluent.ksql.statement.ConfiguredStatement in project ksql by confluentinc.
the class ListQueriesExecutorTest method shouldListQueriesBasic.
@Test
public void shouldListQueriesBasic() {
// Given
final ConfiguredStatement<ListQueries> showQueries = (ConfiguredStatement<ListQueries>) engine.configure("SHOW QUERIES;");
final PersistentQueryMetadata metadata = givenPersistentQuery("id", RUNNING_QUERY_STATE);
final KsqlEngine engine = mock(KsqlEngine.class);
when(engine.getAllLiveQueries()).thenReturn(ImmutableList.of(metadata));
queryStatusCount.updateStatusCount(RUNNING_QUERY_STATE, 1);
// When
final Queries queries = (Queries) CUSTOM_EXECUTORS.listQueries().execute(showQueries, sessionProperties, engine, this.engine.getServiceContext()).getEntity().orElseThrow(IllegalStateException::new);
assertThat(queries.getQueries(), containsInAnyOrder(persistentQueryMetadataToRunningQuery(metadata, queryStatusCount)));
}
use of io.confluent.ksql.statement.ConfiguredStatement 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)));
}
Aggregations