Search in sources :

Example 41 with InternalMockProcessorContext

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

the class ListValueStoreTest method setup.

@Before
public void setup() {
    listStore = buildStore(Serdes.Integer(), Serdes.String());
    final MockRecordCollector recordCollector = new MockRecordCollector();
    final InternalMockProcessorContext<Integer, String> context = new InternalMockProcessorContext<>(baseDir, Serdes.String(), Serdes.Integer(), recordCollector, new ThreadCache(new LogContext("testCache"), 0, new MockStreamsMetrics(new Metrics())));
    context.setTime(1L);
    listStore.init((StateStoreContext) context, listStore);
}
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) InternalMockProcessorContext(org.apache.kafka.test.InternalMockProcessorContext) Before(org.junit.Before)

Example 42 with InternalMockProcessorContext

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

the class RocksDBStoreTest method shouldThrowProcessorStateExceptionOnOpeningReadOnlyDir.

@Test
public void shouldThrowProcessorStateExceptionOnOpeningReadOnlyDir() {
    final File tmpDir = TestUtils.tempDirectory();
    final InternalMockProcessorContext tmpContext = new InternalMockProcessorContext(tmpDir, new StreamsConfig(StreamsTestUtils.getStreamsConfig()));
    assertTrue(tmpDir.setReadOnly());
    assertThrows(ProcessorStateException.class, () -> rocksDBStore.openDB(tmpContext.appConfigs(), tmpContext.stateDir()));
}
Also used : InternalMockProcessorContext(org.apache.kafka.test.InternalMockProcessorContext) File(java.io.File) StreamsConfig(org.apache.kafka.streams.StreamsConfig) Test(org.junit.Test)

Example 43 with InternalMockProcessorContext

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

the class RocksDBStoreTest method shouldCallRocksDbConfigSetter.

@Test
public void shouldCallRocksDbConfigSetter() {
    MockRocksDbConfigSetter.called = false;
    final Properties props = StreamsTestUtils.getStreamsConfig();
    props.put(StreamsConfig.ROCKSDB_CONFIG_SETTER_CLASS_CONFIG, MockRocksDbConfigSetter.class);
    final Object param = new Object();
    props.put("abc.def", param);
    final InternalMockProcessorContext context = new InternalMockProcessorContext(dir, Serdes.String(), Serdes.String(), new StreamsConfig(props));
    rocksDBStore.init((StateStoreContext) context, rocksDBStore);
    assertTrue(MockRocksDbConfigSetter.called);
    assertThat(MockRocksDbConfigSetter.configMap.get("abc.def"), equalTo(param));
}
Also used : Properties(java.util.Properties) InternalMockProcessorContext(org.apache.kafka.test.InternalMockProcessorContext) StreamsConfig(org.apache.kafka.streams.StreamsConfig) Test(org.junit.Test)

Example 44 with InternalMockProcessorContext

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

the class RocksDBStoreTest method shouldHandleToggleOfEnablingBloomFilters.

@Test
public void shouldHandleToggleOfEnablingBloomFilters() {
    final Properties props = StreamsTestUtils.getStreamsConfig();
    props.put(StreamsConfig.ROCKSDB_CONFIG_SETTER_CLASS_CONFIG, TestingBloomFilterRocksDBConfigSetter.class);
    dir = TestUtils.tempDirectory();
    context = new InternalMockProcessorContext(dir, Serdes.String(), Serdes.String(), new StreamsConfig(props));
    enableBloomFilters = false;
    rocksDBStore.init((StateStoreContext) context, rocksDBStore);
    final List<String> expectedValues = new ArrayList<>();
    expectedValues.add("a");
    expectedValues.add("b");
    expectedValues.add("c");
    final List<KeyValue<byte[], byte[]>> keyValues = getKeyValueEntries();
    for (final KeyValue<byte[], byte[]> keyValue : keyValues) {
        rocksDBStore.put(new Bytes(keyValue.key), keyValue.value);
    }
    int expectedIndex = 0;
    for (final KeyValue<byte[], byte[]> keyValue : keyValues) {
        final byte[] valBytes = rocksDBStore.get(new Bytes(keyValue.key));
        assertThat(new String(valBytes, UTF_8), is(expectedValues.get(expectedIndex++)));
    }
    assertFalse(TestingBloomFilterRocksDBConfigSetter.bloomFiltersSet);
    rocksDBStore.close();
    expectedIndex = 0;
    // reopen with Bloom Filters enabled
    // should open fine without errors
    enableBloomFilters = true;
    rocksDBStore.init((StateStoreContext) context, rocksDBStore);
    for (final KeyValue<byte[], byte[]> keyValue : keyValues) {
        final byte[] valBytes = rocksDBStore.get(new Bytes(keyValue.key));
        assertThat(new String(valBytes, UTF_8), is(expectedValues.get(expectedIndex++)));
    }
    assertTrue(TestingBloomFilterRocksDBConfigSetter.bloomFiltersSet);
}
Also used : Bytes(org.apache.kafka.common.utils.Bytes) KeyValue(org.apache.kafka.streams.KeyValue) ArrayList(java.util.ArrayList) Properties(java.util.Properties) InternalMockProcessorContext(org.apache.kafka.test.InternalMockProcessorContext) StreamsConfig(org.apache.kafka.streams.StreamsConfig) Test(org.junit.Test)

Aggregations

InternalMockProcessorContext (org.apache.kafka.test.InternalMockProcessorContext)44 Test (org.junit.Test)23 LogContext (org.apache.kafka.common.utils.LogContext)20 Metrics (org.apache.kafka.common.metrics.Metrics)19 Before (org.junit.Before)17 MockStreamsMetrics (org.apache.kafka.streams.processor.internals.MockStreamsMetrics)14 NoOpRecordCollector (org.apache.kafka.test.NoOpRecordCollector)14 StreamsConfig (org.apache.kafka.streams.StreamsConfig)10 Properties (java.util.Properties)8 Bytes (org.apache.kafka.common.utils.Bytes)8 StateStore (org.apache.kafka.streams.processor.StateStore)7 File (java.io.File)6 MockTime (org.apache.kafka.common.utils.MockTime)6 ProcessorRecordContext (org.apache.kafka.streams.processor.internals.ProcessorRecordContext)6 ArrayList (java.util.ArrayList)5 RecordHeaders (org.apache.kafka.common.header.internals.RecordHeaders)5 Serializer (org.apache.kafka.common.serialization.Serializer)5 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)4 MetricName (org.apache.kafka.common.MetricName)4 HashMap (java.util.HashMap)3