use of org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl in project kafka by apache.
the class StreamThreadTest method shouldConstructAdminMetrics.
@Test
public void shouldConstructAdminMetrics() {
final Node broker1 = new Node(0, "dummyHost-1", 1234);
final Node broker2 = new Node(1, "dummyHost-2", 1234);
final List<Node> cluster = Arrays.asList(broker1, broker2);
final MockAdminClient adminClient = new MockAdminClient.Builder().brokers(cluster).clusterId(null).build();
final Consumer<byte[], byte[]> consumer = EasyMock.createNiceMock(Consumer.class);
final ConsumerGroupMetadata consumerGroupMetadata = mock(ConsumerGroupMetadata.class);
expect(consumer.groupMetadata()).andStubReturn(consumerGroupMetadata);
expect(consumerGroupMetadata.groupInstanceId()).andReturn(Optional.empty());
EasyMock.replay(consumer, consumerGroupMetadata);
final TaskManager taskManager = EasyMock.createNiceMock(TaskManager.class);
final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, CLIENT_ID, StreamsConfig.METRICS_LATEST, mockTime);
final TopologyMetadata topologyMetadata = new TopologyMetadata(internalTopologyBuilder, config);
topologyMetadata.buildAndRewriteTopology();
final StreamThread thread = new StreamThread(mockTime, config, adminClient, consumer, consumer, null, null, taskManager, streamsMetrics, topologyMetadata, CLIENT_ID, new LogContext(""), new AtomicInteger(), new AtomicLong(Long.MAX_VALUE), new LinkedList<>(), null, HANDLER, null);
final MetricName testMetricName = new MetricName("test_metric", "", "", new HashMap<>());
final Metric testMetric = new KafkaMetric(new Object(), testMetricName, (Measurable) (config, now) -> 0, null, new MockTime());
EasyMock.replay(taskManager);
adminClient.setMockMetrics(testMetricName, testMetric);
final Map<MetricName, Metric> adminClientMetrics = thread.adminClientMetrics();
assertEquals(testMetricName, adminClientMetrics.get(testMetricName).metricName());
}
use of org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl in project kafka by apache.
the class StreamTaskTest method createStatelessTask.
private StreamTask createStatelessTask(final StreamsConfig config) {
final ProcessorTopology topology = withSources(asList(source1, source2, processorStreamTime, processorSystemTime), mkMap(mkEntry(topic1, source1), mkEntry(topic2, source2)));
source1.addChild(processorStreamTime);
source2.addChild(processorStreamTime);
source1.addChild(processorSystemTime);
source2.addChild(processorSystemTime);
EasyMock.expect(stateManager.changelogPartitions()).andReturn(Collections.emptySet());
EasyMock.expect(stateManager.changelogOffsets()).andReturn(Collections.emptyMap()).anyTimes();
EasyMock.expect(recordCollector.offsets()).andReturn(Collections.emptyMap()).anyTimes();
EasyMock.replay(stateManager, recordCollector);
final InternalProcessorContext context = new ProcessorContextImpl(taskId, config, stateManager, streamsMetrics, null);
return new StreamTask(taskId, partitions, topology, consumer, new TopologyConfig(null, config, new Properties()).getTaskConfig(), new StreamsMetricsImpl(metrics, "test", StreamsConfig.METRICS_LATEST, time), stateDirectory, cache, time, stateManager, recordCollector, context, logContext);
}
use of org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl in project kafka by apache.
the class StreamTaskTest method shouldThrowTopologyExceptionIfTaskCreatedForUnknownTopic.
@Test
public void shouldThrowTopologyExceptionIfTaskCreatedForUnknownTopic() {
final InternalProcessorContext context = new ProcessorContextImpl(taskId, createConfig("100"), stateManager, streamsMetrics, null);
final StreamsMetricsImpl metrics = new StreamsMetricsImpl(this.metrics, "test", StreamsConfig.METRICS_LATEST, time);
EasyMock.expect(stateManager.changelogPartitions()).andReturn(Collections.emptySet());
EasyMock.replay(stateManager);
// The processor topology is missing the topics
final ProcessorTopology topology = withSources(emptyList(), mkMap());
final TopologyException exception = assertThrows(TopologyException.class, () -> new StreamTask(taskId, partitions, topology, consumer, new TopologyConfig(null, createConfig("100"), new Properties()).getTaskConfig(), metrics, stateDirectory, cache, time, stateManager, recordCollector, context, logContext));
assertThat(exception.getMessage(), equalTo("Invalid topology: " + "Topic is unknown to the topology. This may happen if different KafkaStreams instances of the same " + "application execute different Topologies. Note that Topologies are only identical if all operators " + "are added in the same order."));
}
use of org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl in project kafka by apache.
the class StreamTaskTest method createStatelessTaskWithForwardingTopology.
private StreamTask createStatelessTaskWithForwardingTopology(final SourceNode<Integer, Integer> sourceNode) {
final ProcessorTopology topology = withSources(asList(sourceNode, processorStreamTime), singletonMap(topic1, sourceNode));
sourceNode.addChild(processorStreamTime);
EasyMock.expect(stateManager.changelogPartitions()).andReturn(Collections.emptySet());
EasyMock.expect(recordCollector.offsets()).andReturn(Collections.emptyMap()).anyTimes();
EasyMock.replay(stateManager, recordCollector);
final StreamsConfig config = createConfig();
final InternalProcessorContext context = new ProcessorContextImpl(taskId, config, stateManager, streamsMetrics, null);
return new StreamTask(taskId, singleton(partition1), topology, consumer, new TopologyConfig(null, config, new Properties()).getTaskConfig(), new StreamsMetricsImpl(metrics, "test", StreamsConfig.METRICS_LATEST, time), stateDirectory, cache, time, stateManager, recordCollector, context, logContext);
}
use of org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl in project kafka by apache.
the class AbstractRocksDBSegmentedBytesStoreTest method shouldRestoreRecordsAndConsistencyVectorSingleTopic.
@Test
public void shouldRestoreRecordsAndConsistencyVectorSingleTopic() {
final Properties props = StreamsTestUtils.getStreamsConfig();
props.put(InternalConfig.IQ_CONSISTENCY_OFFSET_VECTOR_ENABLED, true);
final File dir = TestUtils.tempDirectory();
context = new InternalMockProcessorContext<>(dir, Serdes.String(), Serdes.String(), new StreamsMetricsImpl(new Metrics(), "mock", StreamsConfig.METRICS_LATEST, new MockTime()), new StreamsConfig(props), MockRecordCollector::new, new ThreadCache(new LogContext("testCache "), 0, new MockStreamsMetrics(new Metrics())), Time.SYSTEM);
bytesStore = getBytesStore();
bytesStore.init((StateStoreContext) context, bytesStore);
// 0 segments initially.
assertEquals(0, bytesStore.getSegments().size());
bytesStore.restoreAllInternal(getChangelogRecords());
// 2 segments are created during restoration.
assertEquals(2, bytesStore.getSegments().size());
final String key = "a";
final List<KeyValue<Windowed<String>, Long>> expected = new ArrayList<>();
expected.add(new KeyValue<>(new Windowed<>(key, windows[0]), 50L));
expected.add(new KeyValue<>(new Windowed<>(key, windows[2]), 100L));
expected.add(new KeyValue<>(new Windowed<>(key, windows[3]), 200L));
final List<KeyValue<Windowed<String>, Long>> results = toList(bytesStore.all());
assertEquals(expected, results);
assertThat(bytesStore.getPosition(), Matchers.notNullValue());
assertThat(bytesStore.getPosition().getPartitionPositions(""), Matchers.notNullValue());
assertThat(bytesStore.getPosition().getPartitionPositions(""), hasEntry(0, 3L));
}
Aggregations