@Override public void deleteTestTopic(String topic) { LOG.info("Deleting topic {}", topic); ZkClient zk = createZkClient(); AdminUtils.deleteTopic(zk, topic); zk.close(); }
@Test public void testKafkaConsumer09Read() throws IOException, StageException { int zkConnectionTimeout = 6000; int zkSessionTimeout = 6000; EmbeddedZookeeper zookeeper = new EmbeddedZookeeper(); String zkConnect = String.format("127.0.0.1:%d", zookeeper.port()); ZkUtils zkUtils = ZkUtils.apply( zkConnect, zkSessionTimeout, zkConnectionTimeout, JaasUtils.isZkSecurityEnabled()); int port = TestUtil.getFreePort(); KafkaServer kafkaServer = TestUtil.createKafkaServer(port, zkConnect); final String topic = "TestKafkaConsumer09_1"; final String message = "Hello StreamSets"; Source.Context sourceContext = ContextInfoCreator.createSourceContext( "s", false, OnRecordError.TO_ERROR, ImmutableList.of("a")); Map<String, Object> props = new HashMap<>(); props.put("auto.commit.interval.ms", "1000"); props.put("auto.offset.reset", "earliest"); props.put("session.timeout.ms", "30000"); SdcKafkaConsumer sdcKafkaConsumer = createSdcKafkaConsumer("localhost:" + port, topic, 1000, sourceContext, props, "test"); sdcKafkaConsumer.validate(new ArrayList<Stage.ConfigIssue>(), sourceContext); sdcKafkaConsumer.init(); // produce some messages to topic produce(topic, "localhost:" + port, message); // read List<MessageAndOffset> read = new ArrayList<>(); while (read.size() < 10) { MessageAndOffset messageAndOffset = sdcKafkaConsumer.read(); if (messageAndOffset != null) { read.add(messageAndOffset); } } // verify Assert.assertNotNull(read); Assert.assertEquals(10, read.size()); verify(read, message); // delete topic and shutdown AdminUtils.deleteTopic(zkUtils, topic); kafkaServer.shutdown(); zookeeper.shutdown(); }