Search in sources :

Example 11 with MockProcessorContext

use of org.apache.kafka.test.MockProcessorContext 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 12 with MockProcessorContext

use of org.apache.kafka.test.MockProcessorContext 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 13 with MockProcessorContext

use of org.apache.kafka.test.MockProcessorContext in project kafka by apache.

the class RocksDBKeyValueStoreSupplierTest method shouldCreateLoggingEnabledStoreWhenStoreLogged.

@Test
public void shouldCreateLoggingEnabledStoreWhenStoreLogged() throws Exception {
    store = createStore(true, false);
    final List<ProducerRecord> logged = new ArrayList<>();
    final NoOpRecordCollector collector = new NoOpRecordCollector() {

        @Override
        public <K, V> void send(final String topic, K key, V value, Integer partition, Long timestamp, Serializer<K> keySerializer, Serializer<V> valueSerializer) {
            logged.add(new ProducerRecord<K, V>(topic, partition, timestamp, key, value));
        }
    };
    final MockProcessorContext context = new MockProcessorContext(TestUtils.tempDirectory(), Serdes.String(), Serdes.String(), collector, cache);
    context.setTime(1);
    store.init(context, store);
    store.put("a", "b");
    assertFalse(logged.isEmpty());
}
Also used : NoOpRecordCollector(org.apache.kafka.test.NoOpRecordCollector) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) ArrayList(java.util.ArrayList) MockProcessorContext(org.apache.kafka.test.MockProcessorContext) Serializer(org.apache.kafka.common.serialization.Serializer) Test(org.junit.Test)

Example 14 with MockProcessorContext

use of org.apache.kafka.test.MockProcessorContext in project kafka by apache.

the class RocksDBKeyValueStoreTest method shouldPerformRangeQueriesWithCachingDisabled.

@Test
public void shouldPerformRangeQueriesWithCachingDisabled() throws Exception {
    final KeyValueStoreTestDriver<Integer, String> driver = KeyValueStoreTestDriver.create(Integer.class, String.class);
    final MockProcessorContext context = (MockProcessorContext) driver.context();
    final KeyValueStore<Integer, String> store = createStore(context, Integer.class, String.class, false, false);
    context.setTime(1L);
    store.put(1, "hi");
    store.put(2, "goodbye");
    final KeyValueIterator<Integer, String> range = store.range(1, 2);
    assertEquals("hi", range.next().value);
    assertEquals("goodbye", range.next().value);
    assertFalse(range.hasNext());
}
Also used : MockProcessorContext(org.apache.kafka.test.MockProcessorContext) Test(org.junit.Test)

Example 15 with MockProcessorContext

use of org.apache.kafka.test.MockProcessorContext 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)

Aggregations

MockProcessorContext (org.apache.kafka.test.MockProcessorContext)29 NoOpRecordCollector (org.apache.kafka.test.NoOpRecordCollector)17 Test (org.junit.Test)15 Metrics (org.apache.kafka.common.metrics.Metrics)13 Serializer (org.apache.kafka.common.serialization.Serializer)13 Before (org.junit.Before)13 MockStreamsMetrics (org.apache.kafka.streams.processor.internals.MockStreamsMetrics)11 ArrayList (java.util.ArrayList)6 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)6 StateSerdes (org.apache.kafka.streams.state.StateSerdes)5 MockProducer (org.apache.kafka.clients.producer.MockProducer)4 StreamsException (org.apache.kafka.streams.errors.StreamsException)4 Bytes (org.apache.kafka.common.utils.Bytes)3 ProcessorRecordContext (org.apache.kafka.streams.processor.internals.ProcessorRecordContext)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 SessionWindow (org.apache.kafka.streams.kstream.internals.SessionWindow)2 File (java.io.File)1 HashMap (java.util.HashMap)1 MetricName (org.apache.kafka.common.MetricName)1 TopicPartition (org.apache.kafka.common.TopicPartition)1