use of io.confluent.ksql.engine.KsqlEngine in project ksql by confluentinc.
the class KsqlContext method create.
/**
* Create a KSQL context object with the given properties. A KSQL context has it's own metastore
* valid during the life of the object.
*/
public static KsqlContext create(final KsqlConfig ksqlConfig, final ProcessingLogContext processingLogContext, final MetricCollectors metricCollectors) {
Objects.requireNonNull(ksqlConfig, "ksqlConfig cannot be null.");
final ServiceContext serviceContext = ServiceContextFactory.create(ksqlConfig, DisabledKsqlClient::instance);
final MutableFunctionRegistry functionRegistry = new InternalFunctionRegistry();
UserFunctionLoader.newInstance(ksqlConfig, functionRegistry, ".", metricCollectors.getMetrics()).load();
final ServiceInfo serviceInfo = ServiceInfo.create(ksqlConfig);
final KsqlEngine engine = new KsqlEngine(serviceContext, processingLogContext, functionRegistry, serviceInfo, new SequentialQueryIdGenerator(), ksqlConfig, Collections.emptyList(), metricCollectors);
return new KsqlContext(serviceContext, ksqlConfig, engine, Injectors.DEFAULT);
}
use of io.confluent.ksql.engine.KsqlEngine in project ksql by confluentinc.
the class KsqlContextTestUtil method create.
public static KsqlContext create(final KsqlConfig ksqlConfig, final SchemaRegistryClient schemaRegistryClient, final FunctionRegistry functionRegistry) {
final KafkaClientSupplier clientSupplier = new DefaultKafkaClientSupplier();
final Admin adminClient = clientSupplier.getAdmin(ksqlConfig.getKsqlAdminClientConfigProps());
final KafkaTopicClient kafkaTopicClient = new KafkaTopicClientImpl(() -> adminClient);
final ServiceContext serviceContext = TestServiceContext.create(clientSupplier, adminClient, kafkaTopicClient, () -> schemaRegistryClient, new DefaultConnectClientFactory(ksqlConfig).get(Optional.empty(), Collections.emptyList(), Optional.empty()));
final String metricsPrefix = "instance-" + COUNTER.getAndIncrement() + "-";
final KsqlEngine engine = new KsqlEngine(serviceContext, ProcessingLogContext.create(), functionRegistry, ServiceInfo.create(ksqlConfig, metricsPrefix), new SequentialQueryIdGenerator(), ksqlConfig, Collections.emptyList(), new MetricCollectors());
return new KsqlContext(serviceContext, ksqlConfig, engine, Injectors.DEFAULT);
}
use of io.confluent.ksql.engine.KsqlEngine in project ksql by confluentinc.
the class KsqlTesterTest method setUp.
@Before
public void setUp() {
final MockSchemaRegistryClient srClient = new MockSchemaRegistryClient();
this.topicClient = new FakeKafkaTopicClient();
this.serviceContext = TestServiceContext.create(topicClient, () -> srClient);
this.config = new KsqlConfig(BASE_CONFIG);
this.formatInjector = new DefaultFormatInjector();
final MetaStoreImpl metaStore = new MetaStoreImpl(TestFunctionRegistry.INSTANCE.get());
final MetricCollectors metricCollectors = new MetricCollectors();
this.engine = new KsqlEngine(serviceContext, NoopProcessingLogContext.INSTANCE, metaStore, ServiceInfo.create(config), new SequentialQueryIdGenerator(), this.config, Collections.singletonList(new QueryEventListener() {
@Override
public void onDeregister(QueryMetadata query) {
final DriverAndProperties driverAndProperties = drivers.get(query.getQueryId());
closeDriver(driverAndProperties.driver, driverAndProperties.properties, false);
}
}), metricCollectors);
this.expectedException = null;
this.expectedMessage = null;
this.overrides = new HashMap<>();
this.driverPipeline = new TestDriverPipeline();
}
use of io.confluent.ksql.engine.KsqlEngine 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;
}
use of io.confluent.ksql.engine.KsqlEngine in project ksql by confluentinc.
the class TestExecutor method getKsqlEngine.
static KsqlEngine getKsqlEngine(final ServiceContext serviceContext, final Optional<String> extensionDir) {
final FunctionRegistry functionRegistry;
if (extensionDir.isPresent()) {
final MutableFunctionRegistry mutable = new InternalFunctionRegistry();
UdfLoaderUtil.load(mutable, extensionDir.get());
functionRegistry = mutable;
} else {
functionRegistry = TestFunctionRegistry.INSTANCE.get();
}
final MutableMetaStore metaStore = new MetaStoreImpl(functionRegistry);
final MetricCollectors metricCollectors = new MetricCollectors();
return new KsqlEngine(serviceContext, ProcessingLogContext.create(), "test_instance_", metaStore, (engine) -> new KsqlEngineMetrics("", engine, Collections.emptyMap(), Optional.empty(), metricCollectors), new SequentialQueryIdGenerator(), KsqlConfig.empty(), Collections.emptyList(), metricCollectors);
}
Aggregations