Search in sources :

Example 1 with MockMetricsReporter

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

the class KafkaProducerTest method testMetricsReporterAutoGeneratedClientId.

@Test
public void testMetricsReporterAutoGeneratedClientId() {
    Properties props = new Properties();
    props.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9999");
    props.setProperty(ProducerConfig.METRIC_REPORTER_CLASSES_CONFIG, MockMetricsReporter.class.getName());
    KafkaProducer<String, String> producer = new KafkaProducer<>(props, new StringSerializer(), new StringSerializer());
    MockMetricsReporter mockMetricsReporter = (MockMetricsReporter) producer.metrics.reporters().get(0);
    assertEquals(producer.getClientId(), mockMetricsReporter.clientId);
    producer.close();
}
Also used : MockMetricsReporter(org.apache.kafka.test.MockMetricsReporter) Properties(java.util.Properties) StringSerializer(org.apache.kafka.common.serialization.StringSerializer) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 2 with MockMetricsReporter

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

the class KafkaConsumerTest method testMetricsReporterAutoGeneratedClientId.

@Test
public void testMetricsReporterAutoGeneratedClientId() {
    Properties props = new Properties();
    props.setProperty(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9999");
    props.setProperty(ConsumerConfig.METRIC_REPORTER_CLASSES_CONFIG, MockMetricsReporter.class.getName());
    KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props, new StringDeserializer(), new StringDeserializer());
    MockMetricsReporter mockMetricsReporter = (MockMetricsReporter) consumer.metrics.reporters().get(0);
    assertEquals(consumer.getClientId(), mockMetricsReporter.clientId);
    consumer.close();
}
Also used : MockMetricsReporter(org.apache.kafka.test.MockMetricsReporter) StringDeserializer(org.apache.kafka.common.serialization.StringDeserializer) Properties(java.util.Properties) Test(org.junit.jupiter.api.Test)

Aggregations

Properties (java.util.Properties)2 MockMetricsReporter (org.apache.kafka.test.MockMetricsReporter)2 Test (org.junit.jupiter.api.Test)2 StringDeserializer (org.apache.kafka.common.serialization.StringDeserializer)1 StringSerializer (org.apache.kafka.common.serialization.StringSerializer)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1