use of org.apache.kafka.test.MockInternalNewProcessorContext in project kafka by apache.
the class KTableSuppressProcessorMetricsTest method shouldRecordMetricsWithBuiltInMetricsVersionLatest.
@Test
public void shouldRecordMetricsWithBuiltInMetricsVersionLatest() {
final String storeName = "test-store";
final StateStore buffer = new InMemoryTimeOrderedKeyValueBuffer.Builder<>(storeName, Serdes.String(), Serdes.Long()).withLoggingDisabled().build();
final KTableImpl<String, ?, Long> mock = EasyMock.mock(KTableImpl.class);
final Processor<String, Change<Long>, String, Change<Long>> processor = new KTableSuppressProcessorSupplier<>((SuppressedInternal<String>) Suppressed.<String>untilTimeLimit(Duration.ofDays(100), maxRecords(1)), storeName, mock).get();
streamsConfig.setProperty(StreamsConfig.BUILT_IN_METRICS_VERSION_CONFIG, StreamsConfig.METRICS_LATEST);
final MockInternalNewProcessorContext<String, Change<Long>> context = new MockInternalNewProcessorContext<>(streamsConfig, TASK_ID, TestUtils.tempDirectory());
final Time time = new SystemTime();
context.setCurrentNode(new ProcessorNode("testNode"));
context.setSystemTimeMs(time.milliseconds());
buffer.init((StateStoreContext) context, buffer);
processor.init(context);
final long timestamp = 100L;
context.setRecordMetadata("", 0, 0L);
context.setTimestamp(timestamp);
final String key = "longKey";
final Change<Long> value = new Change<>(null, ARBITRARY_LONG);
processor.process(new Record<>(key, value, timestamp));
final MetricName evictionRateMetric = evictionRateMetricLatest;
final MetricName evictionTotalMetric = evictionTotalMetricLatest;
final MetricName bufferSizeAvgMetric = bufferSizeAvgMetricLatest;
final MetricName bufferSizeMaxMetric = bufferSizeMaxMetricLatest;
final MetricName bufferCountAvgMetric = bufferCountAvgMetricLatest;
final MetricName bufferCountMaxMetric = bufferCountMaxMetricLatest;
{
final Map<MetricName, ? extends Metric> metrics = context.metrics().metrics();
verifyMetric(metrics, evictionRateMetric, is(0.0));
verifyMetric(metrics, evictionTotalMetric, is(0.0));
verifyMetric(metrics, bufferSizeAvgMetric, is(21.5));
verifyMetric(metrics, bufferSizeMaxMetric, is(43.0));
verifyMetric(metrics, bufferCountAvgMetric, is(0.5));
verifyMetric(metrics, bufferCountMaxMetric, is(1.0));
}
context.setRecordMetadata("", 0, 1L);
context.setTimestamp(timestamp + 1);
processor.process(new Record<>("key", value, timestamp + 1));
{
final Map<MetricName, ? extends Metric> metrics = context.metrics().metrics();
verifyMetric(metrics, evictionRateMetric, greaterThan(0.0));
verifyMetric(metrics, evictionTotalMetric, is(1.0));
verifyMetric(metrics, bufferSizeAvgMetric, is(41.0));
verifyMetric(metrics, bufferSizeMaxMetric, is(82.0));
verifyMetric(metrics, bufferCountAvgMetric, is(1.0));
verifyMetric(metrics, bufferCountMaxMetric, is(2.0));
}
}
Aggregations