use of org.apache.kafka.streams.processor.internals.MockStreamsMetrics in project kafka by apache.
the class StreamThreadStateStoreProviderTest method createStreamsTask.
private StreamTask createStreamsTask(final StreamsConfig streamsConfig, final MockClientSupplier clientSupplier, final ProcessorTopology topology, final TaskId taskId) {
final Metrics metrics = new Metrics();
final LogContext logContext = new LogContext("test-stream-task ");
final Set<TopicPartition> partitions = Collections.singleton(new TopicPartition(topicName, taskId.partition()));
final ProcessorStateManager stateManager = new ProcessorStateManager(taskId, Task.TaskType.ACTIVE, StreamsConfigUtils.eosEnabled(streamsConfig), logContext, stateDirectory, new StoreChangelogReader(new MockTime(), streamsConfig, logContext, clientSupplier.adminClient, clientSupplier.restoreConsumer, new MockStateRestoreListener()), topology.storeToChangelogTopic(), partitions);
final RecordCollector recordCollector = new RecordCollectorImpl(logContext, taskId, new StreamsProducer(streamsConfig, "threadId", clientSupplier, new TaskId(0, 0), UUID.randomUUID(), logContext, Time.SYSTEM), streamsConfig.defaultProductionExceptionHandler(), new MockStreamsMetrics(metrics));
final StreamsMetricsImpl streamsMetrics = new MockStreamsMetrics(metrics);
final InternalProcessorContext context = new ProcessorContextImpl(taskId, streamsConfig, stateManager, streamsMetrics, null);
return new StreamTask(taskId, partitions, topology, clientSupplier.consumer, new TopologyConfig(null, streamsConfig, new Properties()).getTaskConfig(), streamsMetrics, stateDirectory, EasyMock.createNiceMock(ThreadCache.class), new MockTime(), stateManager, recordCollector, context, logContext);
}
use of org.apache.kafka.streams.processor.internals.MockStreamsMetrics in project kafka by apache.
the class ThreadCacheTest method shouldReturnNullIfKeyIsNull.
@Test
public void shouldReturnNullIfKeyIsNull() {
final ThreadCache threadCache = new ThreadCache(logContext, 10, new MockStreamsMetrics(new Metrics()));
threadCache.put(namespace, Bytes.wrap(new byte[] { 1 }), cleanEntry(new byte[] { 1 }));
assertNull(threadCache.get(namespace, null));
}
use of org.apache.kafka.streams.processor.internals.MockStreamsMetrics in project kafka by apache.
the class ThreadCacheTest method shouldEvictImmediatelyIfCacheSizeIsZero.
@Test
public void shouldEvictImmediatelyIfCacheSizeIsZero() {
final ThreadCache cache = new ThreadCache(logContext, 0, new MockStreamsMetrics(new Metrics()));
shouldEvictImmediatelyIfCacheSizeIsZeroOrVerySmall(cache);
}
use of org.apache.kafka.streams.processor.internals.MockStreamsMetrics in project kafka by apache.
the class ThreadCacheTest method shouldNotFlushCleanEntriesForNamespace.
@Test
public void shouldNotFlushCleanEntriesForNamespace() {
final ThreadCache cache = new ThreadCache(logContext, 100000, new MockStreamsMetrics(new Metrics()));
final List<byte[]> received = new ArrayList<>();
cache.addDirtyEntryFlushListener(namespace1, dirty -> {
for (final ThreadCache.DirtyEntry dirtyEntry : dirty) {
received.add(dirtyEntry.key().get());
}
});
final List<byte[]> toInsert = Arrays.asList(new byte[] { 0 }, new byte[] { 1 }, new byte[] { 2 });
for (final byte[] bytes : toInsert) {
cache.put(namespace1, Bytes.wrap(bytes), cleanEntry(bytes));
}
cache.put(namespace2, Bytes.wrap(new byte[] { 4 }), cleanEntry(new byte[] { 4 }));
cache.flush(namespace1);
assertEquals(Collections.emptyList(), received);
}
use of org.apache.kafka.streams.processor.internals.MockStreamsMetrics in project kafka by apache.
the class ThreadCacheTest method shouldPutAll.
@Test
public void shouldPutAll() {
final ThreadCache cache = new ThreadCache(logContext, 100000, new MockStreamsMetrics(new Metrics()));
cache.putAll(namespace, Arrays.asList(KeyValue.pair(Bytes.wrap(new byte[] { 0 }), dirtyEntry(new byte[] { 5 })), KeyValue.pair(Bytes.wrap(new byte[] { 1 }), dirtyEntry(new byte[] { 6 }))));
assertArrayEquals(new byte[] { 5 }, cache.get(namespace, Bytes.wrap(new byte[] { 0 })).value());
assertArrayEquals(new byte[] { 6 }, cache.get(namespace, Bytes.wrap(new byte[] { 1 })).value());
}
Aggregations