Search in sources :

Example 36 with KafkaMetric

use of org.apache.kafka.common.metrics.KafkaMetric in project kafka by apache.

the class ActiveTaskCreatorTest method shouldConstructThreadProducerMetric.

private void shouldConstructThreadProducerMetric() {
    createTasks();
    final MetricName testMetricName = new MetricName("test_metric", "", "", new HashMap<>());
    final Metric testMetric = new KafkaMetric(new Object(), testMetricName, (Measurable) (config, now) -> 0, null, new MockTime());
    mockClientSupplier.producers.get(0).setMockMetrics(testMetricName, testMetric);
    assertThat(mockClientSupplier.producers.size(), is(1));
    final Map<MetricName, Metric> producerMetrics = activeTaskCreator.producerMetrics();
    assertThat(producerMetrics.size(), is(1));
    assertThat(producerMetrics.get(testMetricName), is(testMetric));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) StreamsConfig(org.apache.kafka.streams.StreamsConfig) MockTime(org.apache.kafka.common.utils.MockTime) TaskId(org.apache.kafka.streams.processor.TaskId) Mock(org.easymock.Mock) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Assert.assertThrows(org.junit.Assert.assertThrows) RunWith(org.junit.runner.RunWith) EasyMock.mock(org.easymock.EasyMock.mock) HashMap(java.util.HashMap) StreamsException(org.apache.kafka.streams.errors.StreamsException) Utils.mkMap(org.apache.kafka.common.utils.Utils.mkMap) EasyMock.reset(org.easymock.EasyMock.reset) Matchers.closeTo(org.hamcrest.Matchers.closeTo) LogContext(org.apache.kafka.common.utils.LogContext) Map(java.util.Map) Metric(org.apache.kafka.common.Metric) MetricName(org.apache.kafka.common.MetricName) StreamsMetricsImpl(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl) EasyMockRunner(org.easymock.EasyMockRunner) EasyMock.replay(org.easymock.EasyMock.replay) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) IsNot.not(org.hamcrest.core.IsNot.not) TopicPartition(org.apache.kafka.common.TopicPartition) ThreadCache(org.apache.kafka.streams.state.internals.ThreadCache) Utils.mkSet(org.apache.kafka.common.utils.Utils.mkSet) Set(java.util.Set) Test(org.junit.Test) Measurable(org.apache.kafka.common.metrics.Measurable) UUID(java.util.UUID) EasyMock.expect(org.easymock.EasyMock.expect) Collectors(java.util.stream.Collectors) MockClientSupplier(org.apache.kafka.test.MockClientSupplier) File(java.io.File) TimestampExtractor(org.apache.kafka.streams.processor.TimestampExtractor) Metrics(org.apache.kafka.common.metrics.Metrics) Utils.mkEntry(org.apache.kafka.common.utils.Utils.mkEntry) TopologyConfig(org.apache.kafka.streams.processor.internals.namedtopology.TopologyConfig) KafkaMetric(org.apache.kafka.common.metrics.KafkaMetric) MockType(org.easymock.MockType) Collections(java.util.Collections) MockProducer(org.apache.kafka.clients.producer.MockProducer) MetricName(org.apache.kafka.common.MetricName) Metric(org.apache.kafka.common.Metric) KafkaMetric(org.apache.kafka.common.metrics.KafkaMetric) KafkaMetric(org.apache.kafka.common.metrics.KafkaMetric) MockTime(org.apache.kafka.common.utils.MockTime)

Example 37 with KafkaMetric

use of org.apache.kafka.common.metrics.KafkaMetric in project kafka by apache.

the class MeteredKeyValueStoreTest method shouldFlushInnerWhenFlushTimeRecords.

@Test
public void shouldFlushInnerWhenFlushTimeRecords() {
    inner.flush();
    expectLastCall().once();
    init();
    metered.flush();
    final KafkaMetric metric = metric("flush-rate");
    assertTrue((Double) metric.metricValue() > 0);
    verify(inner);
}
Also used : KafkaMetric(org.apache.kafka.common.metrics.KafkaMetric) Test(org.junit.Test)

Example 38 with KafkaMetric

use of org.apache.kafka.common.metrics.KafkaMetric in project kafka by apache.

the class MeteredKeyValueStoreTest method shouldWriteBytesToInnerStoreAndRecordPutMetric.

@Test
public void shouldWriteBytesToInnerStoreAndRecordPutMetric() {
    inner.put(eq(KEY_BYTES), aryEq(VALUE_BYTES));
    expectLastCall();
    init();
    metered.put(KEY, VALUE);
    final KafkaMetric metric = metric("put-rate");
    assertTrue((Double) metric.metricValue() > 0);
    verify(inner);
}
Also used : KafkaMetric(org.apache.kafka.common.metrics.KafkaMetric) Test(org.junit.Test)

Example 39 with KafkaMetric

use of org.apache.kafka.common.metrics.KafkaMetric in project kafka by apache.

the class MeteredKeyValueStoreTest method shouldGetRangeFromInnerStoreAndRecordRangeMetric.

@Test
public void shouldGetRangeFromInnerStoreAndRecordRangeMetric() {
    expect(inner.range(KEY_BYTES, KEY_BYTES)).andReturn(new KeyValueIteratorStub<>(Collections.singletonList(BYTE_KEY_VALUE_PAIR).iterator()));
    init();
    final KeyValueIterator<String, String> iterator = metered.range(KEY, KEY);
    assertThat(iterator.next().value, equalTo(VALUE));
    assertFalse(iterator.hasNext());
    iterator.close();
    final KafkaMetric metric = metric("range-rate");
    assertTrue((Double) metric.metricValue() > 0);
    verify(inner);
}
Also used : KafkaMetric(org.apache.kafka.common.metrics.KafkaMetric) Test(org.junit.Test)

Example 40 with KafkaMetric

use of org.apache.kafka.common.metrics.KafkaMetric in project kafka by apache.

the class MeteredKeyValueStoreTest method shouldGetBytesFromInnerStoreAndReturnGetMetric.

@Test
public void shouldGetBytesFromInnerStoreAndReturnGetMetric() {
    expect(inner.get(KEY_BYTES)).andReturn(VALUE_BYTES);
    init();
    assertThat(metered.get(KEY), equalTo(VALUE));
    final KafkaMetric metric = metric("get-rate");
    assertTrue((Double) metric.metricValue() > 0);
    verify(inner);
}
Also used : KafkaMetric(org.apache.kafka.common.metrics.KafkaMetric) Test(org.junit.Test)

Aggregations

KafkaMetric (org.apache.kafka.common.metrics.KafkaMetric)95 Test (org.junit.Test)73 MetricName (org.apache.kafka.common.MetricName)36 HashMap (java.util.HashMap)17 MemoryRecordsBuilder (org.apache.kafka.common.record.MemoryRecordsBuilder)14 LinkedHashMap (java.util.LinkedHashMap)12 ConsumerRecord (org.apache.kafka.clients.consumer.ConsumerRecord)12 Windowed (org.apache.kafka.streams.kstream.Windowed)12 Test (org.junit.jupiter.api.Test)11 TopicPartition (org.apache.kafka.common.TopicPartition)10 List (java.util.List)8 Cluster (org.apache.kafka.common.Cluster)8 Node (org.apache.kafka.common.Node)8 Sensor (org.apache.kafka.common.metrics.Sensor)8 LegacyRecord (org.apache.kafka.common.record.LegacyRecord)8 MemoryRecords (org.apache.kafka.common.record.MemoryRecords)8 Record (org.apache.kafka.common.record.Record)8 SimpleRecord (org.apache.kafka.common.record.SimpleRecord)8 Metrics (org.apache.kafka.common.metrics.Metrics)7 PartitionData (org.apache.kafka.common.requests.FetchRequest.PartitionData)7