use of io.confluent.ksql.util.KafkaTopicClientImpl in project ksql by confluentinc.
the class IntegrationTestHarness method start.
public void start() throws Exception {
embeddedKafkaCluster = new EmbeddedSingleNodeKafkaCluster();
embeddedKafkaCluster.start();
Map<String, Object> configMap = new HashMap<>();
configMap.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, embeddedKafkaCluster.bootstrapServers());
configMap.put("application.id", "KSQL");
configMap.put("commit.interval.ms", 0);
configMap.put("cache.max.bytes.buffering", 0);
configMap.put("auto.offset.reset", "earliest");
configMap.put(StreamsConfig.STATE_DIR_CONFIG, TestUtils.tempDirectory().getPath());
this.ksqlConfig = new KsqlConfig(configMap);
this.adminClient = AdminClient.create(ksqlConfig.getKsqlAdminClientConfigProps());
this.topicClient = new KafkaTopicClientImpl(adminClient);
}
use of io.confluent.ksql.util.KafkaTopicClientImpl in project ksql by confluentinc.
the class JsonFormatTest method before.
@Before
public void before() throws Exception {
Map<String, Object> configMap = new HashMap<>();
configMap.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, CLUSTER.bootstrapServers());
configMap.put("application.id", "KSQL");
configMap.put("commit.interval.ms", 0);
configMap.put("cache.max.bytes.buffering", 0);
configMap.put("auto.offset.reset", "earliest");
KsqlConfig ksqlConfig = new KsqlConfig(configMap);
adminClient = AdminClient.create(ksqlConfig.getKsqlAdminClientConfigProps());
topicClient = new KafkaTopicClientImpl(adminClient);
ksqlEngine = new KsqlEngine(ksqlConfig, topicClient);
metaStore = ksqlEngine.getMetaStore();
createInitTopics();
produceInitData();
execInitCreateStreamQueries();
}
use of io.confluent.ksql.util.KafkaTopicClientImpl in project ksql by confluentinc.
the class SecureIntegrationTest method before.
@Before
public void before() throws Exception {
SECURE_CLUSTER.clearAcls();
outputTopic = "TEST_" + COUNTER.incrementAndGet();
topicClient = new KafkaTopicClientImpl(AdminClient.create(new KsqlConfig(getKsqlConfig(SUPER_USER)).getKsqlAdminClientConfigProps()));
produceInitData();
}
use of io.confluent.ksql.util.KafkaTopicClientImpl in project ksql by confluentinc.
the class WindowingIntTest method shouldAggregateWithNoWindow.
@Test
public void shouldAggregateWithNoWindow() throws Exception {
testHarness.publishTestData(topicName, dataProvider, now);
final String streamName = "NOWINDOW_AGGTEST";
final String queryString = String.format("CREATE TABLE %s AS SELECT %s FROM ORDERS WHERE ITEMID = 'ITEM_1' GROUP BY ITEMID;", streamName, "ITEMID, COUNT(ITEMID), SUM(ORDERUNITS)");
ksqlContext.sql(queryString);
Schema resultSchema = ksqlContext.getMetaStore().getSource(streamName).getSchema();
final GenericRow expected = new GenericRow(Arrays.asList(null, null, "ITEM_1", 2, /**
* 2 x items *
*/
20.0));
final Map<String, GenericRow> results = new HashMap<>();
TestUtils.waitForCondition(() -> {
final Map<String, GenericRow> aggregateResults = testHarness.consumeData(streamName, resultSchema, 1, new StringDeserializer(), MAX_POLL_PER_ITERATION);
final GenericRow actual = aggregateResults.get("ITEM_1");
return expected.equals(actual);
}, 60000, "didn't receive correct results within timeout");
AdminClient adminClient = AdminClient.create(testHarness.ksqlConfig.getKsqlStreamConfigProps());
KafkaTopicClient topicClient = new KafkaTopicClientImpl(adminClient);
Set<String> topicBeforeCleanup = topicClient.listTopicNames();
assertThat("Expected to have 5 topics instead have : " + topicBeforeCleanup.size(), topicBeforeCleanup.size(), equalTo(5));
QueryMetadata queryMetadata = ksqlContext.getRunningQueries().iterator().next();
queryMetadata.close();
Set<String> topicsAfterCleanUp = topicClient.listTopicNames();
assertThat("Expected to see 3 topics after clean up but seeing " + topicsAfterCleanUp.size(), topicsAfterCleanUp.size(), equalTo(3));
assertThat(topicClient.getTopicCleanupPolicy(streamName), equalTo(KafkaTopicClient.TopicCleanupPolicy.COMPACT));
}
use of io.confluent.ksql.util.KafkaTopicClientImpl in project ksql by confluentinc.
the class WindowingIntTest method shouldAggregateSessionWindow.
@Test
public void shouldAggregateSessionWindow() throws Exception {
testHarness.publishTestData(topicName, dataProvider, now);
final String streamName = "SESSION_AGGTEST";
final String queryString = String.format("CREATE TABLE %s AS SELECT %s FROM ORDERS WINDOW %s GROUP BY ORDERID;", streamName, "ORDERID, COUNT(*), SUM(ORDERUNITS)", "SESSION (10 SECONDS)");
ksqlContext.sql(queryString);
Schema resultSchema = ksqlContext.getMetaStore().getSource(streamName).getSchema();
GenericRow expectedResults = new GenericRow(Arrays.asList(null, null, "ORDER_6", 6, /**
* 2 x items *
*/
420.0));
final Map<String, GenericRow> results = new HashMap<>();
TestUtils.waitForCondition(() -> {
final Map<Windowed<String>, GenericRow> windowedResults = testHarness.consumeData(streamName, resultSchema, datasetOneMetaData.size(), new TimeWindowedDeserializer<>(new StringDeserializer()), 1000);
updateResults(results, windowedResults);
final GenericRow actual = results.get("ORDER_6");
return expectedResults.equals(actual) && results.size() == 6;
}, 60000, "didn't receive correct results within timeout");
AdminClient adminClient = AdminClient.create(testHarness.ksqlConfig.getKsqlStreamConfigProps());
KafkaTopicClient topicClient = new KafkaTopicClientImpl(adminClient);
Set<String> topicBeforeCleanup = topicClient.listTopicNames();
assertThat("Expected to have 5 topics instead have : " + topicBeforeCleanup.size(), topicBeforeCleanup.size(), equalTo(5));
QueryMetadata queryMetadata = ksqlContext.getRunningQueries().iterator().next();
queryMetadata.close();
Set<String> topicsAfterCleanUp = topicClient.listTopicNames();
assertThat("Expected to see 3 topics after clean up but seeing " + topicsAfterCleanUp.size(), topicsAfterCleanUp.size(), equalTo(3));
assertThat(topicClient.getTopicCleanupPolicy(streamName), equalTo(KafkaTopicClient.TopicCleanupPolicy.DELETE));
}
Aggregations