Search in sources :

Example 1 with MockConsumerInterceptor

use of org.apache.kafka.test.MockConsumerInterceptor in project kafka by apache.

the class KafkaConsumerTest method testInterceptorConstructorClose.

@Test
public void testInterceptorConstructorClose() throws Exception {
    try {
        Properties props = new Properties();
        // test with client ID assigned by KafkaConsumer
        props.setProperty(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9999");
        props.setProperty(ConsumerConfig.INTERCEPTOR_CLASSES_CONFIG, MockConsumerInterceptor.class.getName());
        KafkaConsumer<String, String> consumer = new KafkaConsumer<String, String>(props, new StringDeserializer(), new StringDeserializer());
        assertEquals(1, MockConsumerInterceptor.INIT_COUNT.get());
        assertEquals(0, MockConsumerInterceptor.CLOSE_COUNT.get());
        consumer.close();
        assertEquals(1, MockConsumerInterceptor.INIT_COUNT.get());
        assertEquals(1, MockConsumerInterceptor.CLOSE_COUNT.get());
        // Cluster metadata will only be updated on calling poll.
        Assert.assertNull(MockConsumerInterceptor.CLUSTER_META.get());
    } finally {
        // cleanup since we are using mutable static variables in MockConsumerInterceptor
        MockConsumerInterceptor.resetCounters();
    }
}
Also used : StringDeserializer(org.apache.kafka.common.serialization.StringDeserializer) Properties(java.util.Properties) MockConsumerInterceptor(org.apache.kafka.test.MockConsumerInterceptor) Test(org.junit.Test)

Aggregations

Properties (java.util.Properties)1 StringDeserializer (org.apache.kafka.common.serialization.StringDeserializer)1 MockConsumerInterceptor (org.apache.kafka.test.MockConsumerInterceptor)1 Test (org.junit.Test)1