Search in sources :

Example 26 with KafkaMetric

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

the class MeteredWindowStoreTest method shouldBackwardFetchAllFromInnerStoreAndRecordFetchMetrics.

@Test
public void shouldBackwardFetchAllFromInnerStoreAndRecordFetchMetrics() {
    expect(innerStoreMock.backwardFetchAll(1, 1)).andReturn(KeyValueIterators.emptyIterator());
    replay(innerStoreMock);
    store.init((StateStoreContext) context, store);
    // recorded on close;
    store.backwardFetchAll(ofEpochMilli(1), ofEpochMilli(1)).close();
    // it suffices to verify one fetch metric since all fetch metrics are recorded by the same sensor
    // and the sensor is tested elsewhere
    final KafkaMetric metric = metric("fetch-rate");
    assertThat((Double) metric.metricValue(), greaterThan(0.0));
    verify(innerStoreMock);
}
Also used : KafkaMetric(org.apache.kafka.common.metrics.KafkaMetric) Test(org.junit.Test)

Example 27 with KafkaMetric

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

the class MeteredWindowStoreTest method shouldFetchFromInnerStoreAndRecordFetchMetrics.

@Test
public void shouldFetchFromInnerStoreAndRecordFetchMetrics() {
    expect(innerStoreMock.fetch(Bytes.wrap("a".getBytes()), 1, 1)).andReturn(KeyValueIterators.emptyWindowStoreIterator());
    replay(innerStoreMock);
    store.init((StateStoreContext) context, store);
    // recorded on close;
    store.fetch("a", ofEpochMilli(1), ofEpochMilli(1)).close();
    // it suffices to verify one fetch metric since all fetch metrics are recorded by the same sensor
    // and the sensor is tested elsewhere
    final KafkaMetric metric = metric("fetch-rate");
    assertThat((Double) metric.metricValue(), greaterThan(0.0));
    verify(innerStoreMock);
}
Also used : KafkaMetric(org.apache.kafka.common.metrics.KafkaMetric) Test(org.junit.Test)

Example 28 with KafkaMetric

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

the class MeteredWindowStoreTest method shouldPutToInnerStoreAndRecordPutMetrics.

@Test
public void shouldPutToInnerStoreAndRecordPutMetrics() {
    final byte[] bytes = "a".getBytes();
    innerStoreMock.put(eq(Bytes.wrap(bytes)), anyObject(), eq(context.timestamp()));
    replay(innerStoreMock);
    store.init((StateStoreContext) context, store);
    store.put("a", "a", context.timestamp());
    // it suffices to verify one put metric since all put metrics are recorded by the same sensor
    // and the sensor is tested elsewhere
    final KafkaMetric metric = metric("put-rate");
    assertThat((Double) metric.metricValue(), greaterThan(0.0));
    verify(innerStoreMock);
}
Also used : KafkaMetric(org.apache.kafka.common.metrics.KafkaMetric) Test(org.junit.Test)

Example 29 with KafkaMetric

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

the class MeteredWindowStoreTest method shouldFetchRangeFromInnerStoreAndRecordFetchMetrics.

@Test
public void shouldFetchRangeFromInnerStoreAndRecordFetchMetrics() {
    expect(innerStoreMock.fetch(Bytes.wrap("a".getBytes()), Bytes.wrap("b".getBytes()), 1, 1)).andReturn(KeyValueIterators.emptyIterator());
    expect(innerStoreMock.fetch(null, Bytes.wrap("b".getBytes()), 1, 1)).andReturn(KeyValueIterators.emptyIterator());
    expect(innerStoreMock.fetch(Bytes.wrap("a".getBytes()), null, 1, 1)).andReturn(KeyValueIterators.emptyIterator());
    expect(innerStoreMock.fetch(null, null, 1, 1)).andReturn(KeyValueIterators.emptyIterator());
    replay(innerStoreMock);
    store.init((StateStoreContext) context, store);
    // recorded on close;
    store.fetch("a", "b", ofEpochMilli(1), ofEpochMilli(1)).close();
    // recorded on close;
    store.fetch(null, "b", ofEpochMilli(1), ofEpochMilli(1)).close();
    // recorded on close;
    store.fetch("a", null, ofEpochMilli(1), ofEpochMilli(1)).close();
    // recorded on close;
    store.fetch(null, null, ofEpochMilli(1), ofEpochMilli(1)).close();
    // it suffices to verify one fetch metric since all fetch metrics are recorded by the same sensor
    // and the sensor is tested elsewhere
    final KafkaMetric metric = metric("fetch-rate");
    assertThat((Double) metric.metricValue(), greaterThan(0.0));
    verify(innerStoreMock);
}
Also used : KafkaMetric(org.apache.kafka.common.metrics.KafkaMetric) Test(org.junit.Test)

Example 30 with KafkaMetric

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

the class MeteredWindowStoreTest method shouldBackwardFetchFromInnerStoreAndRecordFetchMetrics.

@Test
public void shouldBackwardFetchFromInnerStoreAndRecordFetchMetrics() {
    expect(innerStoreMock.backwardFetch(Bytes.wrap("a".getBytes()), Bytes.wrap("b".getBytes()), 1, 1)).andReturn(KeyValueIterators.emptyIterator());
    replay(innerStoreMock);
    store.init((StateStoreContext) context, store);
    // recorded on close;
    store.backwardFetch("a", "b", ofEpochMilli(1), ofEpochMilli(1)).close();
    // it suffices to verify one fetch metric since all fetch metrics are recorded by the same sensor
    // and the sensor is tested elsewhere
    final KafkaMetric metric = metric("fetch-rate");
    assertThat((Double) metric.metricValue(), greaterThan(0.0));
    verify(innerStoreMock);
}
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