Search in sources :

Example 1 with CommitOffsetDoFn

use of org.apache.beam.sdk.io.kafka.KafkaCommitOffset.CommitOffsetDoFn in project beam by apache.

the class KafkaCommitOffsetTest method testCommitOffsetDoFn.

@Test
public void testCommitOffsetDoFn() {
    Map<String, Object> configMap = new HashMap<>();
    configMap.put(ConsumerConfig.GROUP_ID_CONFIG, "group1");
    ReadSourceDescriptors<Object, Object> descriptors = ReadSourceDescriptors.read().withBootstrapServers("bootstrap_server").withConsumerConfigUpdates(configMap).withConsumerFactoryFn(new SerializableFunction<Map<String, Object>, Consumer<byte[], byte[]>>() {

        @Override
        public Consumer<byte[], byte[]> apply(Map<String, Object> input) {
            Assert.assertEquals("group1", input.get(ConsumerConfig.GROUP_ID_CONFIG));
            return consumer;
        }
    });
    CommitOffsetDoFn doFn = new CommitOffsetDoFn(descriptors);
    doFn.processElement(KV.of(KafkaSourceDescriptor.of(partition, null, null, null, null, null), 1L));
    Assert.assertEquals(2L, consumer.commit.get(partition).offset());
}
Also used : Consumer(org.apache.kafka.clients.consumer.Consumer) MockConsumer(org.apache.kafka.clients.consumer.MockConsumer) HashMap(java.util.HashMap) CommitOffsetDoFn(org.apache.beam.sdk.io.kafka.KafkaCommitOffset.CommitOffsetDoFn) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 CommitOffsetDoFn (org.apache.beam.sdk.io.kafka.KafkaCommitOffset.CommitOffsetDoFn)1 Consumer (org.apache.kafka.clients.consumer.Consumer)1 MockConsumer (org.apache.kafka.clients.consumer.MockConsumer)1 Test (org.junit.Test)1