Search in sources :

Example 61 with ConfiguredStatement

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)));
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) FunctionNameList(io.confluent.ksql.rest.entity.FunctionNameList) SimpleFunctionInfo(io.confluent.ksql.rest.entity.SimpleFunctionInfo) Test(org.junit.Test)

Example 62 with ConfiguredStatement

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)));
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) KsqlEngine(io.confluent.ksql.engine.KsqlEngine) KsqlRestClientException(io.confluent.ksql.rest.client.exception.KsqlRestClientException) HashMap(java.util.HashMap) ListQueries(io.confluent.ksql.parser.tree.ListQueries) QueryDescriptionList(io.confluent.ksql.rest.entity.QueryDescriptionList) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) KsqlQueryStatus(io.confluent.ksql.util.KsqlConstants.KsqlQueryStatus) Test(org.junit.Test)

Example 63 with ConfiguredStatement

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()));
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) Queries(io.confluent.ksql.rest.entity.Queries) ListQueries(io.confluent.ksql.parser.tree.ListQueries) Test(org.junit.Test)

Example 64 with ConfiguredStatement

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)));
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) KsqlEngine(io.confluent.ksql.engine.KsqlEngine) Queries(io.confluent.ksql.rest.entity.Queries) ListQueries(io.confluent.ksql.parser.tree.ListQueries) ListQueries(io.confluent.ksql.parser.tree.ListQueries) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) Test(org.junit.Test)

Example 65 with ConfiguredStatement

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)));
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) KsqlEngine(io.confluent.ksql.engine.KsqlEngine) RunningQuery(io.confluent.ksql.rest.entity.RunningQuery) Queries(io.confluent.ksql.rest.entity.Queries) ListQueries(io.confluent.ksql.parser.tree.ListQueries) ListQueries(io.confluent.ksql.parser.tree.ListQueries) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) 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