Search in sources :

Example 1 with StubKafkaService

use of io.confluent.ksql.test.tools.stubs.StubKafkaService in project ksql by confluentinc.

the class TestExecutorUtil method buildStreamsTopologyTestDrivers.

static List<TopologyTestDriverContainer> buildStreamsTopologyTestDrivers(final TestCase testCase, final ServiceContext serviceContext, final KsqlEngine ksqlEngine, final KsqlConfig ksqlConfig, final StubKafkaService stubKafkaService, final TestExecutionListener listener) {
    final KsqlConfig maybeUpdatedConfigs = testCase.applyPersistedProperties(ksqlConfig);
    final List<PersistentQueryAndSources> queryMetadataList = doBuildQueries(testCase, serviceContext, ksqlEngine, maybeUpdatedConfigs, stubKafkaService, listener);
    final List<TopologyTestDriverContainer> topologyTestDrivers = new ArrayList<>();
    for (final PersistentQueryAndSources persistentQueryAndSources : queryMetadataList) {
        final PersistentQueryMetadata persistentQueryMetadata = persistentQueryAndSources.getPersistentQueryMetadata();
        final Properties streamsProperties = new Properties();
        streamsProperties.putAll(persistentQueryMetadata.getStreamsProperties());
        final Topology topology = persistentQueryMetadata.getTopology();
        final TopologyTestDriver topologyTestDriver = new TopologyTestDriver(topology, streamsProperties, Instant.EPOCH);
        final List<Topic> sourceTopics = persistentQueryAndSources.getSources().stream().map(dataSource -> {
            stubKafkaService.requireTopicExists(dataSource.getKafkaTopicName());
            return stubKafkaService.getTopic(dataSource.getKafkaTopicName());
        }).collect(Collectors.toList());
        final Optional<Topic> sinkTopic = persistentQueryMetadata.getSinkName().map(name -> buildSinkTopic(ksqlEngine.getMetaStore().getSource(name), stubKafkaService, serviceContext.getSchemaRegistryClient()));
        testCase.setGeneratedTopologies(ImmutableList.of(persistentQueryMetadata.getTopologyDescription()));
        testCase.setGeneratedSchemas(persistentQueryMetadata.getQuerySchemas().getLoggerSchemaInfo());
        topologyTestDrivers.add(TopologyTestDriverContainer.of(topologyTestDriver, sourceTopics, sinkTopic));
    }
    return topologyTestDrivers;
}
Also used : DataSource(io.confluent.ksql.metastore.model.DataSource) KsqlPlan(io.confluent.ksql.engine.KsqlPlan) SessionProperties(io.confluent.ksql.rest.SessionProperties) StringDescription(org.hamcrest.StringDescription) SchemaRegistryClient(io.confluent.kafka.schemaregistry.client.SchemaRegistryClient) SourceName(io.confluent.ksql.name.SourceName) URL(java.net.URL) Matchers.not(org.hamcrest.Matchers.not) ServiceContext(io.confluent.ksql.services.ServiceContext) SchemaRegistryTopicSchemaSupplier(io.confluent.ksql.schema.ksql.inference.SchemaRegistryTopicSchemaSupplier) InjectorChain(io.confluent.ksql.statement.InjectorChain) KsqlConstants.getSRSubject(io.confluent.ksql.util.KsqlConstants.getSRSubject) ExecuteResult(io.confluent.ksql.KsqlExecutionContext.ExecuteResult) InsertValues(io.confluent.ksql.parser.tree.InsertValues) Map(java.util.Map) DefaultFormatInjector(io.confluent.ksql.format.DefaultFormatInjector) QueryId(io.confluent.ksql.query.QueryId) SchemaRegisterInjector(io.confluent.ksql.schema.ksql.inference.SchemaRegisterInjector) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) PlanJsonMapper(io.confluent.ksql.execution.json.PlanJsonMapper) FunctionRegistry(io.confluent.ksql.function.FunctionRegistry) Collection(java.util.Collection) ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) KsqlConfig(io.confluent.ksql.util.KsqlConfig) Instant(java.time.Instant) ParsedSchema(io.confluent.kafka.schemaregistry.ParsedSchema) DefaultSchemaInjector(io.confluent.ksql.schema.ksql.inference.DefaultSchemaInjector) Collectors(java.util.stream.Collectors) List(java.util.List) KsqlExecutionContext(io.confluent.ksql.KsqlExecutionContext) KsqlException(io.confluent.ksql.util.KsqlException) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) Builder(com.google.common.collect.ImmutableList.Builder) KsqlConstants(io.confluent.ksql.util.KsqlConstants) Topology(org.apache.kafka.streams.Topology) FormatFactory(io.confluent.ksql.serde.FormatFactory) KafkaTopicClient(io.confluent.ksql.services.KafkaTopicClient) KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) ArrayList(java.util.ArrayList) SessionConfig(io.confluent.ksql.config.SessionConfig) LinkedHashMap(java.util.LinkedHashMap) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) ConfiguredKsqlPlan(io.confluent.ksql.planner.plan.ConfiguredKsqlPlan) MetaStore(io.confluent.ksql.metastore.MetaStore) ParsedStatement(io.confluent.ksql.parser.KsqlParser.ParsedStatement) StubKafkaService(io.confluent.ksql.test.tools.stubs.StubKafkaService) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TopologyTestDriver(org.apache.kafka.streams.TopologyTestDriver) Matchers.empty(org.hamcrest.Matchers.empty) Properties(java.util.Properties) Iterator(java.util.Iterator) KsqlEngine(io.confluent.ksql.engine.KsqlEngine) MalformedURLException(java.net.MalformedURLException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SerdeFeature(io.confluent.ksql.serde.SerdeFeature) StubInsertValuesExecutor(io.confluent.ksql.engine.StubInsertValuesExecutor) IOException(java.io.IOException) KsqlStatementException(io.confluent.ksql.util.KsqlStatementException) Format(io.confluent.ksql.serde.Format) SqlFormatInjector(io.confluent.ksql.engine.SqlFormatInjector) KsqlTopic(io.confluent.ksql.execution.ddl.commands.KsqlTopic) VisibleForTesting(com.google.common.annotations.VisibleForTesting) SchemaMetadata(io.confluent.kafka.schemaregistry.client.SchemaMetadata) PreparedStatement(io.confluent.ksql.parser.KsqlParser.PreparedStatement) ArrayList(java.util.ArrayList) KsqlConfig(io.confluent.ksql.util.KsqlConfig) TopologyTestDriver(org.apache.kafka.streams.TopologyTestDriver) Topology(org.apache.kafka.streams.Topology) SessionProperties(io.confluent.ksql.rest.SessionProperties) Properties(java.util.Properties) KsqlTopic(io.confluent.ksql.execution.ddl.commands.KsqlTopic) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata)

Example 2 with StubKafkaService

use of io.confluent.ksql.test.tools.stubs.StubKafkaService in project ksql by confluentinc.

the class TestExecutor method create.

/**
 * Create instance.
 *
 * <p>If {@code validateResults} is {@code true} the test will fail if the results are as
 * expected. This is the norm. If {@code false} the test will not fail if the results differ. This
 * is useful when re-writing the historical plans.
 *
 * @param validateResults flag to indicate if results should be validated.
 * @param extensionDir Optional extension directory.
 * @return the executor.
 */
public static TestExecutor create(final boolean validateResults, final Optional<String> extensionDir) {
    final StubKafkaService kafkaService = StubKafkaService.create();
    final StubKafkaClientSupplier kafkaClientSupplier = new StubKafkaClientSupplier();
    final ServiceContext serviceContext = getServiceContext(kafkaClientSupplier);
    return new TestExecutor(kafkaService, serviceContext, getKsqlEngine(serviceContext, extensionDir), TestExecutorUtil::buildStreamsTopologyTestDrivers, validateResults);
}
Also used : StubKafkaService(io.confluent.ksql.test.tools.stubs.StubKafkaService) ServiceContext(io.confluent.ksql.services.ServiceContext) DefaultServiceContext(io.confluent.ksql.services.DefaultServiceContext) StubKafkaClientSupplier(io.confluent.ksql.test.tools.stubs.StubKafkaClientSupplier)

Aggregations

ServiceContext (io.confluent.ksql.services.ServiceContext)2 StubKafkaService (io.confluent.ksql.test.tools.stubs.StubKafkaService)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableList (com.google.common.collect.ImmutableList)1 Builder (com.google.common.collect.ImmutableList.Builder)1 ParsedSchema (io.confluent.kafka.schemaregistry.ParsedSchema)1 SchemaMetadata (io.confluent.kafka.schemaregistry.client.SchemaMetadata)1 SchemaRegistryClient (io.confluent.kafka.schemaregistry.client.SchemaRegistryClient)1 KsqlExecutionContext (io.confluent.ksql.KsqlExecutionContext)1 ExecuteResult (io.confluent.ksql.KsqlExecutionContext.ExecuteResult)1 SessionConfig (io.confluent.ksql.config.SessionConfig)1 KsqlEngine (io.confluent.ksql.engine.KsqlEngine)1 KsqlPlan (io.confluent.ksql.engine.KsqlPlan)1 SqlFormatInjector (io.confluent.ksql.engine.SqlFormatInjector)1 StubInsertValuesExecutor (io.confluent.ksql.engine.StubInsertValuesExecutor)1 KsqlTopic (io.confluent.ksql.execution.ddl.commands.KsqlTopic)1 PlanJsonMapper (io.confluent.ksql.execution.json.PlanJsonMapper)1 DefaultFormatInjector (io.confluent.ksql.format.DefaultFormatInjector)1 FunctionRegistry (io.confluent.ksql.function.FunctionRegistry)1