Search in sources :

Example 6 with MockStreamsMetrics

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

the class SegmentIteratorTest method before.

@Before
public void before() {
    final MockProcessorContext context = new MockProcessorContext(TestUtils.tempDirectory(), Serdes.String(), Serdes.String(), new NoOpRecordCollector(), new ThreadCache("testCache", 0, new MockStreamsMetrics(new Metrics())));
    segmentOne.openDB(context);
    segmentTwo.openDB(context);
    segmentOne.put(Bytes.wrap("a".getBytes()), "1".getBytes());
    segmentOne.put(Bytes.wrap("b".getBytes()), "2".getBytes());
    segmentTwo.put(Bytes.wrap("c".getBytes()), "3".getBytes());
    segmentTwo.put(Bytes.wrap("d".getBytes()), "4".getBytes());
}
Also used : MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) NoOpRecordCollector(org.apache.kafka.test.NoOpRecordCollector) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) MockProcessorContext(org.apache.kafka.test.MockProcessorContext) Before(org.junit.Before)

Example 7 with MockStreamsMetrics

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

the class SegmentsTest method createContext.

@Before
public void createContext() {
    context = new MockProcessorContext(TestUtils.tempDirectory(), Serdes.String(), Serdes.Long(), new NoOpRecordCollector(), new ThreadCache("testCache", 0, new MockStreamsMetrics(new Metrics())));
    segments = new Segments("test", 4 * 60 * 1000, NUM_SEGMENTS);
}
Also used : MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) NoOpRecordCollector(org.apache.kafka.test.NoOpRecordCollector) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) MockProcessorContext(org.apache.kafka.test.MockProcessorContext) Before(org.junit.Before)

Example 8 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() throws Exception {
    final ThreadCache cache = new ThreadCache("testCache", 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 9 with MockStreamsMetrics

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

the class RocksDBSegmentedBytesStoreTest method before.

@Before
public void before() {
    bytesStore = new RocksDBSegmentedBytesStore(storeName, retention, numSegments, new SessionKeySchema());
    stateDir = TestUtils.tempDirectory();
    final MockProcessorContext context = new MockProcessorContext(stateDir, Serdes.String(), Serdes.Long(), new NoOpRecordCollector(), new ThreadCache("testCache", 0, new MockStreamsMetrics(new Metrics())));
    bytesStore.init(context, bytesStore);
}
Also used : MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) NoOpRecordCollector(org.apache.kafka.test.NoOpRecordCollector) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) MockProcessorContext(org.apache.kafka.test.MockProcessorContext) Before(org.junit.Before)

Example 10 with MockStreamsMetrics

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

the class ThreadCacheTest method shouldNotLoopForEverWhenEvictingAndCurrentCacheIsEmpty.

@Test
public void shouldNotLoopForEverWhenEvictingAndCurrentCacheIsEmpty() throws Exception {
    final int maxCacheSizeInBytes = 100;
    final ThreadCache threadCache = new ThreadCache("testCache", maxCacheSizeInBytes, new MockStreamsMetrics(new Metrics()));
    // trigger a put into another cache on eviction from "name"
    threadCache.addDirtyEntryFlushListener("name", new ThreadCache.DirtyEntryFlushListener() {

        @Override
        public void apply(final List<ThreadCache.DirtyEntry> dirty) {
            // put an item into an empty cache when the total cache size
            // is already > than maxCacheSizeBytes
            threadCache.put("other", Bytes.wrap(new byte[] { 0 }), dirtyEntry(new byte[2]));
        }
    });
    threadCache.addDirtyEntryFlushListener("other", new ThreadCache.DirtyEntryFlushListener() {

        @Override
        public void apply(final List<ThreadCache.DirtyEntry> dirty) {
        //
        }
    });
    threadCache.addDirtyEntryFlushListener("another", new ThreadCache.DirtyEntryFlushListener() {

        @Override
        public void apply(final List<ThreadCache.DirtyEntry> dirty) {
        }
    });
    threadCache.put("another", Bytes.wrap(new byte[] { 1 }), dirtyEntry(new byte[1]));
    threadCache.put("name", Bytes.wrap(new byte[] { 1 }), dirtyEntry(new byte[1]));
    // Put a large item such that when the eldest item is removed
    // cache sizeInBytes() > maxCacheSizeBytes
    int remaining = (int) (maxCacheSizeInBytes - threadCache.sizeBytes());
    threadCache.put("name", Bytes.wrap(new byte[] { 2 }), dirtyEntry(new byte[remaining + 100]));
}
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)

Aggregations

Metrics (org.apache.kafka.common.metrics.Metrics)40 MockStreamsMetrics (org.apache.kafka.streams.processor.internals.MockStreamsMetrics)40 Test (org.junit.Test)26 Bytes (org.apache.kafka.common.utils.Bytes)14 Before (org.junit.Before)13 MockProcessorContext (org.apache.kafka.test.MockProcessorContext)11 NoOpRecordCollector (org.apache.kafka.test.NoOpRecordCollector)8 ArrayList (java.util.ArrayList)7 Serializer (org.apache.kafka.common.serialization.Serializer)3 ProcessorRecordContext (org.apache.kafka.streams.processor.internals.ProcessorRecordContext)3 KeyValue (org.apache.kafka.streams.KeyValue)2 File (java.io.File)1 ThreadCache (org.apache.kafka.streams.state.internals.ThreadCache)1