use of org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl in project kafka by apache.
the class RocksDBMetricsRecorderGaugesTest method runAndVerifyBlockCacheMetricsWithSingleCache.
private void runAndVerifyBlockCacheMetricsWithSingleCache(final String propertyName) throws Exception {
final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(new Metrics(), "test-client", StreamsConfig.METRICS_LATEST, new MockTime());
final RocksDBMetricsRecorder recorder = new RocksDBMetricsRecorder(METRICS_SCOPE, STORE_NAME);
recorder.init(streamsMetrics, TASK_ID);
recorder.addValueProviders(SEGMENT_STORE_NAME_1, dbToAdd1, cacheToAdd1, statisticsToAdd1);
recorder.addValueProviders(SEGMENT_STORE_NAME_2, dbToAdd2, cacheToAdd1, statisticsToAdd2);
final long recordedValue = 5L;
expect(dbToAdd1.getAggregatedLongProperty(ROCKSDB_PROPERTIES_PREFIX + propertyName)).andStubReturn(recordedValue);
expect(dbToAdd2.getAggregatedLongProperty(ROCKSDB_PROPERTIES_PREFIX + propertyName)).andStubReturn(recordedValue);
replay(dbToAdd1, dbToAdd2);
verifyMetrics(streamsMetrics, propertyName, recordedValue);
}
use of org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl in project kafka by apache.
the class RocksDBMetricsRecorderGaugesTest method runAndVerifySumOfProperties.
private void runAndVerifySumOfProperties(final String propertyName) throws Exception {
final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(new Metrics(), "test-client", StreamsConfig.METRICS_LATEST, new MockTime());
final RocksDBMetricsRecorder recorder = new RocksDBMetricsRecorder(METRICS_SCOPE, STORE_NAME);
recorder.init(streamsMetrics, TASK_ID);
recorder.addValueProviders(SEGMENT_STORE_NAME_1, dbToAdd1, cacheToAdd1, statisticsToAdd1);
recorder.addValueProviders(SEGMENT_STORE_NAME_2, dbToAdd2, cacheToAdd2, statisticsToAdd2);
final long recordedValue1 = 5L;
final long recordedValue2 = 3L;
expect(dbToAdd1.getAggregatedLongProperty(ROCKSDB_PROPERTIES_PREFIX + propertyName)).andStubReturn(recordedValue1);
expect(dbToAdd2.getAggregatedLongProperty(ROCKSDB_PROPERTIES_PREFIX + propertyName)).andStubReturn(recordedValue2);
replay(dbToAdd1, dbToAdd2);
verifyMetrics(streamsMetrics, propertyName, recordedValue1 + recordedValue2);
}
use of org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl in project kafka by apache.
the class AbstractRocksDBSegmentedBytesStoreTest method shouldRestoreRecordsAndConsistencyVectorMultipleTopics.
@Test
public void shouldRestoreRecordsAndConsistencyVectorMultipleTopics() {
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(getChangelogRecordsMultipleTopics());
// 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("A"), Matchers.notNullValue());
assertThat(bytesStore.getPosition().getPartitionPositions("A"), hasEntry(0, 3L));
assertThat(bytesStore.getPosition().getPartitionPositions("B"), Matchers.notNullValue());
assertThat(bytesStore.getPosition().getPartitionPositions("B"), hasEntry(0, 2L));
}
use of org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl in project kafka by apache.
the class GlobalStateStoreProviderTest method before.
@Before
public void before() {
stores.put("kv-store", Stores.keyValueStoreBuilder(Stores.inMemoryKeyValueStore("kv-store"), Serdes.String(), Serdes.String()).build());
stores.put("ts-kv-store", Stores.timestampedKeyValueStoreBuilder(Stores.inMemoryKeyValueStore("ts-kv-store"), Serdes.String(), Serdes.String()).build());
stores.put("w-store", Stores.windowStoreBuilder(Stores.inMemoryWindowStore("w-store", Duration.ofMillis(10L), Duration.ofMillis(2L), false), Serdes.String(), Serdes.String()).build());
stores.put("ts-w-store", Stores.timestampedWindowStoreBuilder(Stores.inMemoryWindowStore("ts-w-store", Duration.ofMillis(10L), Duration.ofMillis(2L), false), Serdes.String(), Serdes.String()).build());
stores.put("s-store", Stores.sessionStoreBuilder(Stores.inMemorySessionStore("s-store", Duration.ofMillis(10L)), Serdes.String(), Serdes.String()).build());
final ProcessorContextImpl mockContext = niceMock(ProcessorContextImpl.class);
expect(mockContext.applicationId()).andStubReturn("appId");
expect(mockContext.metrics()).andStubReturn(new StreamsMetricsImpl(new Metrics(), "threadName", StreamsConfig.METRICS_LATEST, new MockTime()));
expect(mockContext.taskId()).andStubReturn(new TaskId(0, 0));
expect(mockContext.recordCollector()).andStubReturn(null);
expect(mockContext.appConfigs()).andStubReturn(CONFIGS);
expectSerdes(mockContext);
replay(mockContext);
for (final StateStore store : stores.values()) {
store.init((StateStoreContext) mockContext, null);
}
}
use of org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl in project kafka by apache.
the class AbstractRocksDBSegmentedBytesStoreTest method shouldNotThrowWhenRestoringOnMissingHeaders.
@Test
public void shouldNotThrowWhenRestoringOnMissingHeaders() {
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);
bytesStore.restoreAllInternal(getChangelogRecordsWithoutHeaders());
assertThat(bytesStore.getPosition(), is(Position.emptyPosition()));
}
Aggregations