Search in sources :

Example 41 with MockStreamsMetrics

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

the class ThreadCacheTest method shouldEvictImmediatelyIfCacheSizeIsVerySmall.

@Test
public void shouldEvictImmediatelyIfCacheSizeIsVerySmall() {
    final ThreadCache cache = new ThreadCache(logContext, 1, new MockStreamsMetrics(new Metrics()));
    shouldEvictImmediatelyIfCacheSizeIsZeroOrVerySmall(cache);
}
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) Test(org.junit.Test)

Example 42 with MockStreamsMetrics

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

the class ThreadCacheTest method shouldNotBlowUpOnNonExistentKeyWhenDeleting.

@Test
public void shouldNotBlowUpOnNonExistentKeyWhenDeleting() {
    final Bytes key = Bytes.wrap(new byte[] { 0 });
    final ThreadCache cache = new ThreadCache(logContext, 10000L, new MockStreamsMetrics(new Metrics()));
    cache.put(namespace, key, dirtyEntry(key.get()));
    assertNull(cache.delete(namespace, Bytes.wrap(new byte[] { 1 })));
}
Also used : Bytes(org.apache.kafka.common.utils.Bytes) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Test(org.junit.Test)

Example 43 with MockStreamsMetrics

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

the class ThreadCacheTest method shouldNotFlushAfterDelete.

@Test
public void shouldNotFlushAfterDelete() {
    final Bytes key = Bytes.wrap(new byte[] { 0 });
    final ThreadCache cache = new ThreadCache(logContext, 10000L, new MockStreamsMetrics(new Metrics()));
    final List<ThreadCache.DirtyEntry> received = new ArrayList<>();
    cache.addDirtyEntryFlushListener(namespace, received::addAll);
    cache.put(namespace, key, dirtyEntry(key.get()));
    assertEquals(key.get(), cache.delete(namespace, key).value());
    // flushing should have no further effect
    cache.flush(namespace);
    assertEquals(0, received.size());
    assertEquals(cache.flushes(), 1);
}
Also used : Bytes(org.apache.kafka.common.utils.Bytes) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) ArrayList(java.util.ArrayList) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Test(org.junit.Test)

Example 44 with MockStreamsMetrics

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

the class AbstractSessionBytesStoreTest method setUp.

@Before
public void setUp() {
    sessionStore = buildSessionStore(RETENTION_PERIOD, Serdes.String(), Serdes.Long());
    recordCollector = new MockRecordCollector();
    context = new InternalMockProcessorContext<>(TestUtils.tempDirectory(), Serdes.String(), Serdes.Long(), recordCollector, new ThreadCache(new LogContext("testCache"), 0, new MockStreamsMetrics(new Metrics())));
    context.setTime(1L);
    sessionStore.init((StateStoreContext) context, sessionStore);
}
Also used : MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) MockRecordCollector(org.apache.kafka.test.MockRecordCollector) LogContext(org.apache.kafka.common.utils.LogContext) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Before(org.junit.Before)

Example 45 with MockStreamsMetrics

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

the class AbstractRocksDBSegmentedBytesStoreTest method before.

@Before
public void before() {
    if (schema instanceof SessionKeySchema) {
        windows[0] = new SessionWindow(10L, 10L);
        windows[1] = new SessionWindow(500L, 1000L);
        windows[2] = new SessionWindow(1_000L, 1_500L);
        windows[3] = new SessionWindow(30_000L, 60_000L);
        // All four of the previous windows will go into segment 1.
        // The nextSegmentWindow is computed be a high enough time that when it gets written
        // to the segment store, it will advance stream time past the first segment's retention time and
        // expire it.
        nextSegmentWindow = new SessionWindow(segmentInterval + retention, segmentInterval + retention);
    }
    if (schema instanceof WindowKeySchema) {
        windows[0] = timeWindowForSize(10L, windowSizeForTimeWindow);
        windows[1] = timeWindowForSize(500L, windowSizeForTimeWindow);
        windows[2] = timeWindowForSize(1_000L, windowSizeForTimeWindow);
        windows[3] = timeWindowForSize(60_000L, windowSizeForTimeWindow);
        // All four of the previous windows will go into segment 1.
        // The nextSegmentWindow is computed be a high enough time that when it gets written
        // to the segment store, it will advance stream time past the first segment's retention time and
        // expire it.
        nextSegmentWindow = timeWindowForSize(segmentInterval + retention, windowSizeForTimeWindow);
    }
    bytesStore = getBytesStore();
    stateDir = TestUtils.tempDirectory();
    context = new InternalMockProcessorContext<>(stateDir, Serdes.String(), Serdes.Long(), new MockRecordCollector(), new ThreadCache(new LogContext("testCache "), 0, new MockStreamsMetrics(new Metrics())));
    bytesStore.init((StateStoreContext) context, bytesStore);
}
Also used : MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) MockRecordCollector(org.apache.kafka.test.MockRecordCollector) LogContext(org.apache.kafka.common.utils.LogContext) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) SessionWindow(org.apache.kafka.streams.kstream.internals.SessionWindow) Before(org.junit.Before)

Aggregations

MockStreamsMetrics (org.apache.kafka.streams.processor.internals.MockStreamsMetrics)103 Metrics (org.apache.kafka.common.metrics.Metrics)101 Test (org.junit.Test)59 Before (org.junit.Before)38 LogContext (org.apache.kafka.common.utils.LogContext)32 Bytes (org.apache.kafka.common.utils.Bytes)27 ArrayList (java.util.ArrayList)17 NoOpRecordCollector (org.apache.kafka.test.NoOpRecordCollector)15 InternalMockProcessorContext (org.apache.kafka.test.InternalMockProcessorContext)14 ProcessorRecordContext (org.apache.kafka.streams.processor.internals.ProcessorRecordContext)12 MockProcessorContext (org.apache.kafka.test.MockProcessorContext)10 File (java.io.File)7 RecordHeaders (org.apache.kafka.common.header.internals.RecordHeaders)7 MockTime (org.apache.kafka.common.utils.MockTime)7 KeyValue (org.apache.kafka.streams.KeyValue)7 MockRecordCollector (org.apache.kafka.test.MockRecordCollector)7 StreamsMetricsImpl (org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl)6 Properties (java.util.Properties)5 Serializer (org.apache.kafka.common.serialization.Serializer)4 StreamsConfig (org.apache.kafka.streams.StreamsConfig)4