Search in sources :

Example 46 with StreamsMetricsImpl

use of org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl in project kafka by apache.

the class StreamThreadTest method shouldEnforceRebalanceAfterNextScheduledProbingRebalanceTime.

@Test
public void shouldEnforceRebalanceAfterNextScheduledProbingRebalanceTime() throws InterruptedException {
    final StreamsConfig config = new StreamsConfig(configProps(false));
    internalTopologyBuilder.buildTopology();
    final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, APPLICATION_ID, config.getString(StreamsConfig.BUILT_IN_METRICS_VERSION_CONFIG), mockTime);
    final Consumer<byte[], byte[]> mockConsumer = EasyMock.createNiceMock(Consumer.class);
    expect(mockConsumer.poll(anyObject())).andStubReturn(ConsumerRecords.empty());
    final ConsumerGroupMetadata consumerGroupMetadata = mock(ConsumerGroupMetadata.class);
    expect(mockConsumer.groupMetadata()).andStubReturn(consumerGroupMetadata);
    expect(consumerGroupMetadata.groupInstanceId()).andReturn(Optional.empty());
    EasyMock.replay(consumerGroupMetadata);
    final EasyMockConsumerClientSupplier mockClientSupplier = new EasyMockConsumerClientSupplier(mockConsumer);
    mockClientSupplier.setCluster(createCluster());
    EasyMock.replay(mockConsumer);
    final TopologyMetadata topologyMetadata = new TopologyMetadata(internalTopologyBuilder, config);
    topologyMetadata.buildAndRewriteTopology();
    final StreamThread thread = StreamThread.create(topologyMetadata, config, mockClientSupplier, mockClientSupplier.getAdmin(config.getAdminConfigs(CLIENT_ID)), PROCESS_ID, CLIENT_ID, streamsMetrics, mockTime, streamsMetadataState, 0, stateDirectory, new MockStateRestoreListener(), threadIdx, null, null);
    mockConsumer.enforceRebalance();
    mockClientSupplier.nextRebalanceMs().set(mockTime.milliseconds() - 1L);
    thread.start();
    TestUtils.waitForCondition(() -> thread.state() == StreamThread.State.STARTING, 10 * 1000, "Thread never started.");
    TestUtils.retryOnExceptionWithTimeout(() -> verify(mockConsumer));
    thread.shutdown();
    TestUtils.waitForCondition(() -> thread.state() == StreamThread.State.DEAD, 10 * 1000, "Thread never shut down.");
}
Also used : ConsumerGroupMetadata(org.apache.kafka.clients.consumer.ConsumerGroupMetadata) MockStateRestoreListener(org.apache.kafka.test.MockStateRestoreListener) StreamsMetricsImpl(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl) StreamsConfig(org.apache.kafka.streams.StreamsConfig) Test(org.junit.Test)

Example 47 with StreamsMetricsImpl

use of org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl in project kafka by apache.

the class NamedCacheTest method setUp.

@Before
public void setUp() {
    final Metrics innerMetrics = new Metrics();
    final StreamsMetricsImpl metrics = new MockStreamsMetrics(innerMetrics);
    cache = new NamedCache("dummy-name", metrics);
}
Also used : MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) StreamsMetricsImpl(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl) Before(org.junit.Before)

Example 48 with StreamsMetricsImpl

use of org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl in project kafka by apache.

the class MeteredWindowStoreTest method setUp.

@Before
public void setUp() {
    final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, "test", StreamsConfig.METRICS_LATEST, new MockTime());
    context = new InternalMockProcessorContext<>(TestUtils.tempDirectory(), Serdes.String(), Serdes.Long(), streamsMetrics, new StreamsConfig(StreamsTestUtils.getStreamsConfig()), MockRecordCollector::new, new ThreadCache(new LogContext("testCache "), 0, streamsMetrics), Time.SYSTEM);
    tags = mkMap(mkEntry(THREAD_ID_TAG_KEY, threadId), mkEntry("task-id", context.taskId().toString()), mkEntry(STORE_TYPE + "-state-id", STORE_NAME));
}
Also used : LogContext(org.apache.kafka.common.utils.LogContext) StreamsMetricsImpl(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl) MockTime(org.apache.kafka.common.utils.MockTime) StreamsConfig(org.apache.kafka.streams.StreamsConfig) Before(org.junit.Before)

Example 49 with StreamsMetricsImpl

use of org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl in project kafka by apache.

the class MeteredSessionStoreTest method before.

@Before
public void before() {
    final Time mockTime = new MockTime();
    store = new MeteredSessionStore<>(innerStore, STORE_TYPE, Serdes.String(), Serdes.String(), mockTime);
    metrics.config().recordLevel(Sensor.RecordingLevel.DEBUG);
    expect(context.applicationId()).andStubReturn(APPLICATION_ID);
    expect(context.metrics()).andStubReturn(new StreamsMetricsImpl(metrics, "test", StreamsConfig.METRICS_LATEST, mockTime));
    expect(context.taskId()).andStubReturn(taskId);
    expect(context.changelogFor(STORE_NAME)).andStubReturn(CHANGELOG_TOPIC);
    expect(innerStore.name()).andStubReturn(STORE_NAME);
    tags = mkMap(mkEntry(THREAD_ID_TAG_KEY, threadId), mkEntry("task-id", taskId.toString()), mkEntry(STORE_TYPE + "-state-id", STORE_NAME));
}
Also used : MockTime(org.apache.kafka.common.utils.MockTime) Time(org.apache.kafka.common.utils.Time) StreamsMetricsImpl(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl) MockTime(org.apache.kafka.common.utils.MockTime) Before(org.junit.Before)

Example 50 with StreamsMetricsImpl

use of org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl in project kafka by apache.

the class TaskManagerTest method setUpTaskManager.

private void setUpTaskManager(final StreamsConfigUtils.ProcessingMode processingMode) {
    taskManager = new TaskManager(time, changeLogReader, UUID.randomUUID(), "taskManagerTest", new StreamsMetricsImpl(new Metrics(), "clientId", StreamsConfig.METRICS_LATEST, time), activeTaskCreator, standbyTaskCreator, new TopologyMetadata(topologyBuilder, new DummyStreamsConfig(processingMode)), adminClient, stateDirectory);
    taskManager.setMainConsumer(consumer);
    reset(topologyBuilder);
    expect(topologyBuilder.hasNamedTopology()).andStubReturn(false);
    activeTaskCreator.removeRevokedUnknownTasks(anyObject());
    expectLastCall().asStub();
    standbyTaskCreator.removeRevokedUnknownTasks(anyObject());
    expectLastCall().asStub();
}
Also used : Metrics(org.apache.kafka.common.metrics.Metrics) DummyStreamsConfig(org.apache.kafka.streams.processor.internals.testutil.DummyStreamsConfig) StreamsMetricsImpl(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl)

Aggregations

StreamsMetricsImpl (org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl)54 Test (org.junit.Test)31 Metrics (org.apache.kafka.common.metrics.Metrics)22 MockTime (org.apache.kafka.common.utils.MockTime)22 LogContext (org.apache.kafka.common.utils.LogContext)18 StreamsConfig (org.apache.kafka.streams.StreamsConfig)18 TaskId (org.apache.kafka.streams.processor.TaskId)16 ConsumerGroupMetadata (org.apache.kafka.clients.consumer.ConsumerGroupMetadata)14 Properties (java.util.Properties)12 Before (org.junit.Before)11 File (java.io.File)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 AtomicLong (java.util.concurrent.atomic.AtomicLong)9 LinkedList (java.util.LinkedList)8 Set (java.util.Set)8 MockConsumer (org.apache.kafka.clients.consumer.MockConsumer)8 TopicPartition (org.apache.kafka.common.TopicPartition)8 MockStateRestoreListener (org.apache.kafka.test.MockStateRestoreListener)8 HashMap (java.util.HashMap)7 KeyValue (org.apache.kafka.streams.KeyValue)7