use of io.confluent.ksql.services.ServiceContext in project ksql by confluentinc.
the class DistributingExecutorTest method setUp.
@Before
public void setUp() throws InterruptedException {
scnCounter = new AtomicLong();
when(schemaInjector.inject(any())).thenAnswer(inv -> inv.getArgument(0));
when(topicInjector.inject(any())).thenAnswer(inv -> inv.getArgument(0));
when(queue.enqueueCommand(any(), any(), any())).thenReturn(status);
when(status.tryWaitForFinalStatus(any())).thenReturn(SUCCESS_STATUS);
when(status.getCommandId()).thenReturn(CS_COMMAND);
when(status.getCommandSequenceNumber()).thenAnswer(inv -> scnCounter.incrementAndGet());
when(executionContext.getMetaStore()).thenReturn(metaStore);
when(executionContext.createSandbox(any())).thenReturn(sandboxContext);
when(commandRunnerWarning.get()).thenReturn("");
serviceContext = SandboxedServiceContext.create(TestServiceContext.create());
when(executionContext.getServiceContext()).thenReturn(serviceContext);
when(validatedCommandFactory.create(any(), any())).thenReturn(command);
when(queue.createTransactionalProducer()).thenReturn(transactionalProducer);
securityContext = new KsqlSecurityContext(Optional.empty(), serviceContext);
distributor = new DistributingExecutor(KSQL_CONFIG, queue, DURATION_10_MS, (ec, sc) -> InjectorChain.of(schemaInjector, topicInjector), Optional.of(authorizationValidator), validatedCommandFactory, errorHandler, commandRunnerWarning);
}
use of io.confluent.ksql.services.ServiceContext in project ksql by confluentinc.
the class InteractiveStatementExecutorTest method setUp.
@Before
public void setUp() {
ksqlConfig = KsqlConfigTestUtil.create(CLUSTER, ImmutableMap.of(StreamsConfig.APPLICATION_SERVER_CONFIG, "http://host:1234"));
final FakeKafkaTopicClient fakeKafkaTopicClient = new FakeKafkaTopicClient();
fakeKafkaTopicClient.createTopic("pageview_topic", 1, (short) 1, emptyMap());
fakeKafkaTopicClient.createTopic("foo", 1, (short) 1, emptyMap());
fakeKafkaTopicClient.createTopic("pageview_topic_json", 1, (short) 1, emptyMap());
serviceContext = TestServiceContext.create(fakeKafkaTopicClient);
final SpecificQueryIdGenerator hybridQueryIdGenerator = new SpecificQueryIdGenerator();
final MetricCollectors metricCollectors = new MetricCollectors();
ksqlEngine = KsqlEngineTestUtil.createKsqlEngine(serviceContext, new MetaStoreImpl(new InternalFunctionRegistry()), (engine) -> new KsqlEngineMetrics("", engine, Collections.emptyMap(), Optional.empty(), metricCollectors), hybridQueryIdGenerator, ksqlConfig, metricCollectors);
statementParser = new StatementParser(ksqlEngine);
statementExecutor = new InteractiveStatementExecutor(serviceContext, ksqlEngine, statementParser, hybridQueryIdGenerator, InternalTopicSerdes.deserializer(Command.class));
statementExecutorWithMocks = new InteractiveStatementExecutor(serviceContext, mockEngine, mockParser, mockQueryIdGenerator, commandDeserializer);
statementExecutor.configure(ksqlConfig);
statementExecutorWithMocks.configure(ksqlConfig);
plannedCommand = new Command(CREATE_STREAM_FOO_STATEMENT, emptyMap(), ksqlConfig.getAllConfigPropsWithSecretsObfuscated(), Optional.of(plan));
}
use of io.confluent.ksql.services.ServiceContext in project ksql by confluentinc.
the class KsqlResourceTest method setUp.
@Before
public void setUp() throws IOException, RestClientException {
commandStatus = new QueuedCommandStatus(0, new CommandStatusFuture(new CommandId(TOPIC, "whateva", CREATE)));
commandStatus1 = new QueuedCommandStatus(1, new CommandStatusFuture(new CommandId(TABLE, "something", DROP)));
final QueuedCommandStatus commandStatus2 = new QueuedCommandStatus(2, new CommandStatusFuture(new CommandId(STREAM, "something", EXECUTE)));
kafkaTopicClient = new FakeKafkaTopicClient();
kafkaConsumerGroupClient = new FakeKafkaConsumerGroupClient();
serviceContext = TestServiceContext.create(kafkaTopicClient, kafkaConsumerGroupClient);
schemaRegistryClient = serviceContext.getSchemaRegistryClient();
registerValueSchema(schemaRegistryClient);
ksqlRestConfig = new KsqlRestConfig(getDefaultKsqlConfig());
ksqlConfig = new KsqlConfig(ksqlRestConfig.getKsqlConfigProperties());
final KsqlExecutionContext.ExecuteResult result = mock(KsqlExecutionContext.ExecuteResult.class);
when(sandbox.execute(any(), any(ConfiguredKsqlPlan.class))).thenReturn(result);
when(result.getQuery()).thenReturn(Optional.empty());
MutableFunctionRegistry fnRegistry = new InternalFunctionRegistry();
final Metrics metrics = new Metrics();
UserFunctionLoader.newInstance(ksqlConfig, fnRegistry, ".", metrics).load();
metaStore = new MetaStoreImpl(fnRegistry);
final MetricCollectors metricCollectors = new MetricCollectors(metrics);
realEngine = KsqlEngineTestUtil.createKsqlEngine(serviceContext, metaStore, (engine) -> new KsqlEngineMetrics("", engine, Collections.emptyMap(), Optional.empty(), metricCollectors), new SequentialQueryIdGenerator(), ksqlConfig, metricCollectors);
securityContext = new KsqlSecurityContext(Optional.empty(), serviceContext);
when(commandRunner.getCommandQueue()).thenReturn(commandStore);
when(commandRunnerWarning.get()).thenReturn("");
when(commandStore.createTransactionalProducer()).thenReturn(transactionalProducer);
ksqlEngine = realEngine;
when(sandbox.getMetaStore()).thenAnswer(inv -> metaStore.copy());
addTestTopicAndSources();
when(commandStore.enqueueCommand(any(), any(), any(Producer.class))).thenReturn(commandStatus).thenReturn(commandStatus1).thenReturn(commandStatus2);
streamName = KsqlIdentifierTestUtil.uniqueIdentifierName();
when(schemaInjectorFactory.apply(any())).thenReturn(sandboxSchemaInjector);
when(schemaInjectorFactory.apply(serviceContext)).thenReturn(schemaInjector);
when(topicInjectorFactory.apply(any())).thenReturn(sandboxTopicInjector);
when(topicInjectorFactory.apply(ksqlEngine)).thenReturn(topicInjector);
when(sandboxSchemaInjector.inject(any())).thenAnswer(inv -> inv.getArgument(0));
when(schemaInjector.inject(any())).thenAnswer(inv -> inv.getArgument(0));
when(sandboxTopicInjector.inject(any())).thenAnswer(inv -> inv.getArgument(0));
when(topicInjector.inject(any())).thenAnswer(inv -> inv.getArgument(0));
when(errorsHandler.generateResponse(any(), any())).thenAnswer(new Answer<EndpointResponse>() {
@Override
public EndpointResponse answer(final InvocationOnMock invocation) throws Throwable {
final Object[] args = invocation.getArguments();
return (EndpointResponse) args[1];
}
});
setUpKsqlResource();
}
use of io.confluent.ksql.services.ServiceContext in project ksql by confluentinc.
the class KsqlResourceTest method givenKsqlConfigWith.
private void givenKsqlConfigWith(final Map<String, Object> additionalConfig) {
final Map<String, Object> config = ksqlRestConfig.getKsqlConfigProperties();
config.putAll(additionalConfig);
ksqlConfig = new KsqlConfig(config);
final MetricCollectors metricCollectors = new MetricCollectors();
ksqlEngine = KsqlEngineTestUtil.createKsqlEngine(serviceContext, metaStore, (engine) -> new KsqlEngineMetrics("", engine, Collections.emptyMap(), Optional.empty(), metricCollectors), new SequentialQueryIdGenerator(), ksqlConfig, metricCollectors);
setUpKsqlResource();
}
use of io.confluent.ksql.services.ServiceContext in project ksql by confluentinc.
the class ListSourceExecutorTest method shouldAddWarningsOnClientExceptionForStreamListing.
@Test
public void shouldAddWarningsOnClientExceptionForStreamListing() {
// Given:
final KsqlStream<?> stream1 = engine.givenSource(DataSourceType.KSTREAM, "stream1");
final KsqlStream<?> stream2 = engine.givenSource(DataSourceType.KSTREAM, "stream2");
final ServiceContext serviceContext = engine.getServiceContext();
serviceContext.getTopicClient().deleteTopics(ImmutableList.of("stream1", "stream2"));
// When:
final KsqlEntity entity = CUSTOM_EXECUTORS.listStreams().execute((ConfiguredStatement<ListStreams>) engine.configure("SHOW STREAMS EXTENDED;"), SESSION_PROPERTIES, engine.getEngine(), serviceContext).getEntity().orElseThrow(IllegalStateException::new);
// Then:
assertSourceListWithWarning(entity, stream1, stream2);
}
Aggregations