Github user chtyim commented on a diff in the pull request: https://github.com/apache/twill/pull/16#discussion_r94817038 --- Diff: twill-core/src/test/java/org/apache/twill/kafka/client/KafkaTest.java --- @@ -189,6 +194,49 @@ public void finished() { } @Test + public void testKafkaClientSkipNext() throws Exception { + String topic = "testClient"; + // Publish 30 messages with indecies the same as offsets within the range 0 - 29 + Thread t1 = createPublishThread(kafkaClient, topic, Compression.GZIP, "GZIP Testing message", 10); + t1.start(); + t1.join(); + Thread t2 = createPublishThread(kafkaClient, topic, Compression.NONE, "Testing message", 10, 10); + t2.start(); + t2.join(); + Thread t3 = createPublishThread(kafkaClient, topic, Compression.SNAPPY, "Snappy Testing message", 10, 20); + t3.start(); + t3.join(); + + final CountDownLatch stopLatch = new CountDownLatch(1); + final BlockingQueue<Long> offsetQueue = new LinkedBlockingQueue<>(); + Cancellable cancel = kafkaClient.getConsumer().prepare().add(topic, 0, 0).consume( + new KafkaConsumer.MessageCallback() { + @Override + public long onReceived(long startOffset, Iterator<FetchedMessage> messages) { + if (messages.hasNext()) { + offsetQueue.offer(startOffset); + FetchedMessage message = messages.next(); + LOG.info(Charsets.UTF_8.decode(message.getPayload()).toString()); + return message.getNextOffset() + 1; + } + return startOffset; + } + + @Override + public void finished() { + stopLatch.countDown(); + } + }); + // 15 messages should be in the queue since onReceived returns `message.getNextOffset() + 1` as next offset to read + for (int i = 0; i < 30; i += 2) { + Assert.assertTrue(i == offsetQueue.poll(60, TimeUnit.SECONDS)); + } + Assert.assertEquals(0, offsetQueue.size()); --- End diff -- should do a `Assert.assertNull(offsetQueue.poll(2, TimeUnit.SECONDS))` instead.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---