Search in sources :

Example 26 with MetricCollectors

use of io.confluent.ksql.metrics.MetricCollectors in project ksql by confluentinc.

the class SourceDescriptionFactoryTest method shouldReturnSourceConstraints.

@Test
public void shouldReturnSourceConstraints() {
    // Given:
    final String kafkaTopicName = "kafka";
    final DataSource dataSource = buildDataSource(kafkaTopicName, Optional.empty());
    // When
    final SourceDescription sourceDescription = SourceDescriptionFactory.create(dataSource, true, Collections.emptyList(), Collections.emptyList(), Optional.empty(), Collections.emptyList(), ImmutableList.of("s1", "s2"), new MetricCollectors());
    // Then:
    assertThat(sourceDescription.getSourceConstraints(), hasItems("s1", "s2"));
}
Also used : MetricCollectors(io.confluent.ksql.metrics.MetricCollectors) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DataSource(io.confluent.ksql.metastore.model.DataSource) Test(org.junit.Test)

Example 27 with MetricCollectors

use of io.confluent.ksql.metrics.MetricCollectors in project ksql by confluentinc.

the class StandaloneExecutorFunctionalTest method setUp.

@SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
    queryFile = TMP.newFile().toPath();
    final Map<String, Object> properties = ImmutableMap.<String, Object>builder().putAll(KsqlConfigTestUtil.baseTestConfig()).put(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG, TEST_HARNESS.kafkaBootstrapServers()).put(KsqlConfig.SCHEMA_REGISTRY_URL_PROPERTY, "http://foo:8080").build();
    final Function<KsqlConfig, ServiceContext> serviceContextFactory = config -> TestServiceContext.create(new KsqlConfig(properties), TEST_HARNESS.getServiceContext().getSchemaRegistryClientFactory());
    standalone = StandaloneExecutorFactory.create((Map) properties, queryFile.toString(), ".", serviceContextFactory, KafkaConfigStore::new, activeQuerySupplier -> versionChecker, StandaloneExecutor::new, new MetricCollectors());
    s1 = KsqlIdentifierTestUtil.uniqueIdentifierName("S1");
    s2 = KsqlIdentifierTestUtil.uniqueIdentifierName("S2");
    t1 = KsqlIdentifierTestUtil.uniqueIdentifierName("T1");
}
Also used : PhysicalSchema(io.confluent.ksql.schema.ksql.PhysicalSchema) MethodSorters(org.junit.runners.MethodSorters) BeforeClass(org.junit.BeforeClass) ColumnName(io.confluent.ksql.name.ColumnName) JSON(io.confluent.ksql.serde.FormatFactory.JSON) Mock(org.mockito.Mock) Assert.assertThrows(org.junit.Assert.assertThrows) ServiceContext(io.confluent.ksql.services.ServiceContext) RunWith(org.junit.runner.RunWith) KsqlIdentifierTestUtil(io.confluent.ksql.test.util.KsqlIdentifierTestUtil) MetricCollectors(io.confluent.ksql.metrics.MetricCollectors) AVRO(io.confluent.ksql.serde.FormatFactory.AVRO) Function(java.util.function.Function) KafkaConfigStore(io.confluent.ksql.rest.server.computation.KafkaConfigStore) Map(java.util.Map) After(org.junit.After) KsqlTestFolder(io.confluent.ksql.test.util.KsqlTestFolder) OrderDataProvider(io.confluent.ksql.util.OrderDataProvider) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) SerdeFeatures(io.confluent.ksql.serde.SerdeFeatures) ClassRule(org.junit.ClassRule) Path(java.nio.file.Path) Before(org.junit.Before) CommonClientConfigs(org.apache.kafka.clients.CommonClientConfigs) SystemColumns(io.confluent.ksql.schema.ksql.SystemColumns) ImmutableMap(com.google.common.collect.ImmutableMap) Files(java.nio.file.Files) IntegrationTest(io.confluent.common.utils.IntegrationTest) KAFKA(io.confluent.ksql.serde.FormatFactory.KAFKA) IOException(java.io.IOException) Test(org.junit.Test) KsqlConfig(io.confluent.ksql.util.KsqlConfig) Category(org.junit.experimental.categories.Category) IntegrationTestHarness(io.confluent.ksql.integration.IntegrationTestHarness) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) StandardCharsets(java.nio.charset.StandardCharsets) TestServiceContext(io.confluent.ksql.services.TestServiceContext) KsqlConfigTestUtil(io.confluent.ksql.KsqlConfigTestUtil) VersionCheckerAgent(io.confluent.ksql.version.metrics.VersionCheckerAgent) KsqlException(io.confluent.ksql.util.KsqlException) FixMethodOrder(org.junit.FixMethodOrder) Matchers.containsString(org.hamcrest.Matchers.containsString) SqlTypes(io.confluent.ksql.schema.ksql.types.SqlTypes) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) TemporaryFolder(org.junit.rules.TemporaryFolder) ServiceContext(io.confluent.ksql.services.ServiceContext) TestServiceContext(io.confluent.ksql.services.TestServiceContext) MetricCollectors(io.confluent.ksql.metrics.MetricCollectors) KsqlConfig(io.confluent.ksql.util.KsqlConfig) Matchers.containsString(org.hamcrest.Matchers.containsString) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Before(org.junit.Before)

Example 28 with MetricCollectors

use of io.confluent.ksql.metrics.MetricCollectors in project ksql by confluentinc.

the class TemporaryEngine method before.

@Override
protected void before() {
    final InternalFunctionRegistry functionRegistry = new InternalFunctionRegistry();
    metaStore = new MetaStoreImpl(functionRegistry);
    serviceContext = TestServiceContext.create();
    engine = (KsqlEngineTestUtil.createKsqlEngine(getServiceContext(), metaStore, new MetricCollectors()));
    ksqlConfig = KsqlConfigTestUtil.create("localhost:9092", ImmutableMap.<String, Object>builder().putAll(configs).put("ksql.command.topic.suffix", "commands").put(KsqlRestConfig.LISTENERS_CONFIG, "http://localhost:8088").build());
    final SqlTypeParser typeParser = SqlTypeParser.create(TypeRegistry.EMPTY);
    final Optional<Metrics> noMetrics = Optional.empty();
    final UdfLoader udfLoader = new UdfLoader(functionRegistry, noMetrics, typeParser, true);
    udfLoader.loadUdfFromClass(TestUdf1.class, "test");
    final UdtfLoader udtfLoader = new UdtfLoader(functionRegistry, noMetrics, typeParser, true);
    udtfLoader.loadUdtfFromClass(TestUdtf1.class, "whatever");
    udtfLoader.loadUdtfFromClass(TestUdtf2.class, "whatever");
}
Also used : Metrics(org.apache.kafka.common.metrics.Metrics) MetaStoreImpl(io.confluent.ksql.metastore.MetaStoreImpl) MetricCollectors(io.confluent.ksql.metrics.MetricCollectors) SqlTypeParser(io.confluent.ksql.schema.ksql.SqlTypeParser) InternalFunctionRegistry(io.confluent.ksql.function.InternalFunctionRegistry) UdfLoader(io.confluent.ksql.function.UdfLoader) UdtfLoader(io.confluent.ksql.function.UdtfLoader)

Example 29 with MetricCollectors

use of io.confluent.ksql.metrics.MetricCollectors in project ksql by confluentinc.

the class RecoveryTest method createKsqlEngine.

private KsqlEngine createKsqlEngine(final QueryIdGenerator queryIdGenerator) {
    final KsqlEngineMetrics engineMetrics = mock(KsqlEngineMetrics.class);
    when(engineMetrics.getQueryEventListener()).thenReturn(mock(QueryEventListener.class));
    return KsqlEngineTestUtil.createKsqlEngine(serviceContext, new MetaStoreImpl(new InternalFunctionRegistry()), ignored -> engineMetrics, queryIdGenerator, ksqlConfig, new MetricCollectors());
}
Also used : KsqlEngineMetrics(io.confluent.ksql.internal.KsqlEngineMetrics) QueryEventListener(io.confluent.ksql.engine.QueryEventListener) MetaStoreImpl(io.confluent.ksql.metastore.MetaStoreImpl) MetricCollectors(io.confluent.ksql.metrics.MetricCollectors) InternalFunctionRegistry(io.confluent.ksql.function.InternalFunctionRegistry)

Example 30 with MetricCollectors

use of io.confluent.ksql.metrics.MetricCollectors 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));
}
Also used : CoreMatchers(org.hamcrest.CoreMatchers) KsqlPlan(io.confluent.ksql.engine.KsqlPlan) InternalFunctionRegistry(io.confluent.ksql.function.InternalFunctionRegistry) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Matchers.not(org.hamcrest.Matchers.not) KsqlEngineTestUtil(io.confluent.ksql.engine.KsqlEngineTestUtil) ServiceContext(io.confluent.ksql.services.ServiceContext) CommandId(io.confluent.ksql.rest.entity.CommandId) ArgumentMatcher(org.mockito.ArgumentMatcher) Pair(io.confluent.ksql.util.Pair) ExecuteResult(io.confluent.ksql.KsqlExecutionContext.ExecuteResult) Map(java.util.Map) After(org.junit.After) QueryId(io.confluent.ksql.query.QueryId) FakeKafkaTopicClient(io.confluent.ksql.services.FakeKafkaTopicClient) ClassRule(org.junit.ClassRule) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) ZooKeeperClientException(kafka.zookeeper.ZooKeeperClientException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) CommandStatus(io.confluent.ksql.rest.entity.CommandStatus) ImmutableMap(com.google.common.collect.ImmutableMap) DropStream(io.confluent.ksql.parser.tree.DropStream) StatementParser(io.confluent.ksql.rest.server.StatementParser) ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) KsqlConfig(io.confluent.ksql.util.KsqlConfig) TestServiceContext(io.confluent.ksql.services.TestServiceContext) MetaStoreImpl(io.confluent.ksql.metastore.MetaStoreImpl) List(java.util.List) TerminateQuery(io.confluent.ksql.parser.tree.TerminateQuery) Status(io.confluent.ksql.rest.entity.CommandStatus.Status) KsqlEngineMetrics(io.confluent.ksql.internal.KsqlEngineMetrics) KsqlException(io.confluent.ksql.util.KsqlException) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) Statement(io.confluent.ksql.parser.tree.Statement) Retry(io.confluent.ksql.integration.Retry) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) Mockito.eq(org.mockito.Mockito.eq) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) StreamsConfig(org.apache.kafka.streams.StreamsConfig) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) Action(io.confluent.ksql.rest.entity.CommandId.Action) EmbeddedSingleNodeKafkaCluster(io.confluent.ksql.test.util.EmbeddedSingleNodeKafkaCluster) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Mock(org.mockito.Mock) Assert.assertThrows(org.junit.Assert.assertThrows) RunWith(org.junit.runner.RunWith) SpecificQueryIdGenerator(io.confluent.ksql.query.id.SpecificQueryIdGenerator) MetricCollectors(io.confluent.ksql.metrics.MetricCollectors) CreateStreamAsSelect(io.confluent.ksql.parser.tree.CreateStreamAsSelect) ArrayList(java.util.ArrayList) SessionConfig(io.confluent.ksql.config.SessionConfig) CreateStream(io.confluent.ksql.parser.tree.CreateStream) ArgumentCaptor(org.mockito.ArgumentCaptor) ImmutableList(com.google.common.collect.ImmutableList) ConfiguredKsqlPlan(io.confluent.ksql.planner.plan.ConfiguredKsqlPlan) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Deserializer(org.apache.kafka.common.serialization.Deserializer) Before(org.junit.Before) Collections.emptyMap(java.util.Collections.emptyMap) InOrder(org.mockito.InOrder) KsqlEngine(io.confluent.ksql.engine.KsqlEngine) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Type(io.confluent.ksql.rest.entity.CommandId.Type) KsqlStatementException(io.confluent.ksql.util.KsqlStatementException) TimeUnit(java.util.concurrent.TimeUnit) RuleChain(org.junit.rules.RuleChain) KsqlConfigTestUtil(io.confluent.ksql.KsqlConfigTestUtil) Mockito(org.mockito.Mockito) Assert(org.junit.Assert) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) PreparedStatement(io.confluent.ksql.parser.KsqlParser.PreparedStatement) KsqlEngineMetrics(io.confluent.ksql.internal.KsqlEngineMetrics) StatementParser(io.confluent.ksql.rest.server.StatementParser) MetaStoreImpl(io.confluent.ksql.metastore.MetaStoreImpl) FakeKafkaTopicClient(io.confluent.ksql.services.FakeKafkaTopicClient) MetricCollectors(io.confluent.ksql.metrics.MetricCollectors) SpecificQueryIdGenerator(io.confluent.ksql.query.id.SpecificQueryIdGenerator) InternalFunctionRegistry(io.confluent.ksql.function.InternalFunctionRegistry) Before(org.junit.Before)

Aggregations

MetricCollectors (io.confluent.ksql.metrics.MetricCollectors)46 Test (org.junit.Test)29 KsqlConfig (io.confluent.ksql.util.KsqlConfig)15 SourceDescriptionList (io.confluent.ksql.rest.entity.SourceDescriptionList)13 Before (org.junit.Before)13 InternalFunctionRegistry (io.confluent.ksql.function.InternalFunctionRegistry)12 MetaStoreImpl (io.confluent.ksql.metastore.MetaStoreImpl)10 DataSource (io.confluent.ksql.metastore.model.DataSource)10 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)10 KsqlEngine (io.confluent.ksql.engine.KsqlEngine)9 ServiceContext (io.confluent.ksql.services.ServiceContext)9 SequentialQueryIdGenerator (io.confluent.ksql.query.id.SequentialQueryIdGenerator)8 ConfiguredStatement (io.confluent.ksql.statement.ConfiguredStatement)8 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 SourceDescriptionEntity (io.confluent.ksql.rest.entity.SourceDescriptionEntity)7 TestServiceContext (io.confluent.ksql.services.TestServiceContext)7 Collections (java.util.Collections)7 Map (java.util.Map)7 Optional (java.util.Optional)7