Search in sources :

Example 6 with DefaultProductionExceptionHandler

use of org.apache.kafka.streams.errors.DefaultProductionExceptionHandler in project apache-kafka-on-k8s by banzaicloud.

the class RecordCollectorTest method testStreamPartitioner.

@Test
public void testStreamPartitioner() {
    final RecordCollectorImpl collector = new RecordCollectorImpl(new MockProducer<>(cluster, true, new DefaultPartitioner(), byteArraySerializer, byteArraySerializer), "RecordCollectorTest-TestStreamPartitioner", new LogContext("RecordCollectorTest-TestStreamPartitioner "), new DefaultProductionExceptionHandler());
    collector.send("topic1", "3", "0", null, stringSerializer, stringSerializer, streamPartitioner);
    collector.send("topic1", "9", "0", null, stringSerializer, stringSerializer, streamPartitioner);
    collector.send("topic1", "27", "0", null, stringSerializer, stringSerializer, streamPartitioner);
    collector.send("topic1", "81", "0", null, stringSerializer, stringSerializer, streamPartitioner);
    collector.send("topic1", "243", "0", null, stringSerializer, stringSerializer, streamPartitioner);
    collector.send("topic1", "28", "0", null, stringSerializer, stringSerializer, streamPartitioner);
    collector.send("topic1", "82", "0", null, stringSerializer, stringSerializer, streamPartitioner);
    collector.send("topic1", "244", "0", null, stringSerializer, stringSerializer, streamPartitioner);
    collector.send("topic1", "245", "0", null, stringSerializer, stringSerializer, streamPartitioner);
    final Map<TopicPartition, Long> offsets = collector.offsets();
    assertEquals((Long) 4L, offsets.get(new TopicPartition("topic1", 0)));
    assertEquals((Long) 2L, offsets.get(new TopicPartition("topic1", 1)));
    assertEquals((Long) 0L, offsets.get(new TopicPartition("topic1", 2)));
}
Also used : DefaultPartitioner(org.apache.kafka.clients.producer.internals.DefaultPartitioner) DefaultProductionExceptionHandler(org.apache.kafka.streams.errors.DefaultProductionExceptionHandler) TopicPartition(org.apache.kafka.common.TopicPartition) LogContext(org.apache.kafka.common.utils.LogContext) Test(org.junit.Test)

Example 7 with DefaultProductionExceptionHandler

use of org.apache.kafka.streams.errors.DefaultProductionExceptionHandler in project apache-kafka-on-k8s by banzaicloud.

the class RecordCollectorTest method shouldThrowIfTopicIsUnknownWithDefaultExceptionHandler.

@SuppressWarnings("unchecked")
@Test(expected = StreamsException.class)
public void shouldThrowIfTopicIsUnknownWithDefaultExceptionHandler() {
    final RecordCollector collector = new RecordCollectorImpl(new MockProducer(cluster, true, new DefaultPartitioner(), byteArraySerializer, byteArraySerializer) {

        @Override
        public List<PartitionInfo> partitionsFor(final String topic) {
            return Collections.EMPTY_LIST;
        }
    }, "test", logContext, new DefaultProductionExceptionHandler());
    collector.send("topic1", "3", "0", null, stringSerializer, stringSerializer, streamPartitioner);
}
Also used : MockProducer(org.apache.kafka.clients.producer.MockProducer) DefaultPartitioner(org.apache.kafka.clients.producer.internals.DefaultPartitioner) DefaultProductionExceptionHandler(org.apache.kafka.streams.errors.DefaultProductionExceptionHandler) List(java.util.List) Test(org.junit.Test)

Example 8 with DefaultProductionExceptionHandler

use of org.apache.kafka.streams.errors.DefaultProductionExceptionHandler in project apache-kafka-on-k8s by banzaicloud.

the class RecordCollectorTest method testSpecificPartition.

@Test
public void testSpecificPartition() {
    final RecordCollectorImpl collector = new RecordCollectorImpl(new MockProducer<>(cluster, true, new DefaultPartitioner(), byteArraySerializer, byteArraySerializer), "RecordCollectorTest-TestSpecificPartition", new LogContext("RecordCollectorTest-TestSpecificPartition "), new DefaultProductionExceptionHandler());
    collector.send("topic1", "999", "0", 0, null, stringSerializer, stringSerializer);
    collector.send("topic1", "999", "0", 0, null, stringSerializer, stringSerializer);
    collector.send("topic1", "999", "0", 0, null, stringSerializer, stringSerializer);
    collector.send("topic1", "999", "0", 1, null, stringSerializer, stringSerializer);
    collector.send("topic1", "999", "0", 1, null, stringSerializer, stringSerializer);
    collector.send("topic1", "999", "0", 2, null, stringSerializer, stringSerializer);
    final Map<TopicPartition, Long> offsets = collector.offsets();
    assertEquals((Long) 2L, offsets.get(new TopicPartition("topic1", 0)));
    assertEquals((Long) 1L, offsets.get(new TopicPartition("topic1", 1)));
    assertEquals((Long) 0L, offsets.get(new TopicPartition("topic1", 2)));
    // ignore StreamPartitioner
    collector.send("topic1", "999", "0", 0, null, stringSerializer, stringSerializer);
    collector.send("topic1", "999", "0", 1, null, stringSerializer, stringSerializer);
    collector.send("topic1", "999", "0", 2, null, stringSerializer, stringSerializer);
    assertEquals((Long) 3L, offsets.get(new TopicPartition("topic1", 0)));
    assertEquals((Long) 2L, offsets.get(new TopicPartition("topic1", 1)));
    assertEquals((Long) 1L, offsets.get(new TopicPartition("topic1", 2)));
}
Also used : DefaultPartitioner(org.apache.kafka.clients.producer.internals.DefaultPartitioner) DefaultProductionExceptionHandler(org.apache.kafka.streams.errors.DefaultProductionExceptionHandler) TopicPartition(org.apache.kafka.common.TopicPartition) LogContext(org.apache.kafka.common.utils.LogContext) Test(org.junit.Test)

Aggregations

DefaultProductionExceptionHandler (org.apache.kafka.streams.errors.DefaultProductionExceptionHandler)8 Test (org.junit.Test)8 DefaultPartitioner (org.apache.kafka.clients.producer.internals.DefaultPartitioner)7 MockProducer (org.apache.kafka.clients.producer.MockProducer)5 Future (java.util.concurrent.Future)4 Callback (org.apache.kafka.clients.producer.Callback)4 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)4 KafkaException (org.apache.kafka.common.KafkaException)4 LogContext (org.apache.kafka.common.utils.LogContext)3 StreamsException (org.apache.kafka.streams.errors.StreamsException)3 TopicPartition (org.apache.kafka.common.TopicPartition)2 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Metrics (org.apache.kafka.common.metrics.Metrics)1 StateSerdes (org.apache.kafka.streams.state.StateSerdes)1 InternalMockProcessorContext (org.apache.kafka.test.InternalMockProcessorContext)1