Search in sources :

Example 6 with StateSerdes

use of org.apache.kafka.streams.state.StateSerdes in project apache-kafka-on-k8s by banzaicloud.

the class ProcessorNodeTest method testMetrics.

@Test
public void testMetrics() {
    final StateSerdes anyStateSerde = StateSerdes.withBuiltinTypes("anyName", Bytes.class, Bytes.class);
    final Metrics metrics = new Metrics();
    final InternalMockProcessorContext context = new InternalMockProcessorContext(anyStateSerde, new RecordCollectorImpl(null, null, new LogContext("processnode-test "), new DefaultProductionExceptionHandler()), metrics);
    final ProcessorNode node = new ProcessorNode("name", new NoOpProcessor(), Collections.emptySet());
    node.init(context);
    String[] latencyOperations = { "process", "punctuate", "create", "destroy" };
    String throughputOperation = "forward";
    String groupName = "stream-processor-node-metrics";
    final Map<String, String> metricTags = new LinkedHashMap<>();
    metricTags.put("processor-node-id", node.name());
    metricTags.put("task-id", context.taskId().toString());
    for (String operation : latencyOperations) {
        assertNotNull(metrics.getSensor(operation));
    }
    assertNotNull(metrics.getSensor(throughputOperation));
    for (String opName : latencyOperations) {
        testSpecificMetrics(metrics, groupName, opName, metricTags);
    }
    assertNotNull(metrics.metrics().get(metrics.metricName(throughputOperation + "-rate", groupName, "The average number of occurrence of " + throughputOperation + " operation per second.", metricTags)));
    // test "all"
    metricTags.put("processor-node-id", "all");
    for (String opName : latencyOperations) {
        testSpecificMetrics(metrics, groupName, opName, metricTags);
    }
    assertNotNull(metrics.metrics().get(metrics.metricName(throughputOperation + "-rate", groupName, "The average number of occurrence of " + throughputOperation + " operation per second.", metricTags)));
    context.close();
}
Also used : Metrics(org.apache.kafka.common.metrics.Metrics) DefaultProductionExceptionHandler(org.apache.kafka.streams.errors.DefaultProductionExceptionHandler) LogContext(org.apache.kafka.common.utils.LogContext) StateSerdes(org.apache.kafka.streams.state.StateSerdes) InternalMockProcessorContext(org.apache.kafka.test.InternalMockProcessorContext) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 7 with StateSerdes

use of org.apache.kafka.streams.state.StateSerdes in project apache-kafka-on-k8s by banzaicloud.

the class RecordQueueTest method shouldNotThrowStreamsExceptionWhenKeyDeserializationFailsWithSkipHandler.

@Test
public void shouldNotThrowStreamsExceptionWhenKeyDeserializationFailsWithSkipHandler() throws Exception {
    final byte[] key = Serdes.Long().serializer().serialize("foo", 1L);
    final List<ConsumerRecord<byte[], byte[]>> records = Collections.singletonList(new ConsumerRecord<>("topic", 1, 1, 0L, TimestampType.CREATE_TIME, 0L, 0, 0, key, recordValue));
    final StateSerdes anyStateSerde = StateSerdes.withBuiltinTypes("anyName", Bytes.class, Bytes.class);
    queueThatSkipsDeserializeErrors.addRawRecords(records);
    assertEquals(0, queueThatSkipsDeserializeErrors.size());
}
Also used : StateSerdes(org.apache.kafka.streams.state.StateSerdes) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) Test(org.junit.Test)

Aggregations

StateSerdes (org.apache.kafka.streams.state.StateSerdes)7 Test (org.junit.Test)7 MockProcessorContext (org.apache.kafka.test.MockProcessorContext)5 MockProducer (org.apache.kafka.clients.producer.MockProducer)4 Serializer (org.apache.kafka.common.serialization.Serializer)4 StreamsException (org.apache.kafka.streams.errors.StreamsException)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 Metrics (org.apache.kafka.common.metrics.Metrics)2 LinkedHashMap (java.util.LinkedHashMap)1 ConsumerRecord (org.apache.kafka.clients.consumer.ConsumerRecord)1 Bytes (org.apache.kafka.common.utils.Bytes)1 LogContext (org.apache.kafka.common.utils.LogContext)1 DefaultProductionExceptionHandler (org.apache.kafka.streams.errors.DefaultProductionExceptionHandler)1 InternalMockProcessorContext (org.apache.kafka.test.InternalMockProcessorContext)1