Search in sources :

Example 1 with KeyValueStoreMaterializer

use of org.apache.kafka.streams.kstream.internals.KeyValueStoreMaterializer in project apache-kafka-on-k8s by banzaicloud.

the class KeyValueStoreMaterializerTest method shouldCreateBuilderThatBuildsStoreWithLoggingDisabled.

@Test
public void shouldCreateBuilderThatBuildsStoreWithLoggingDisabled() {
    final MaterializedInternal<String, String, KeyValueStore<Bytes, byte[]>> materialized = new MaterializedInternal<>(Materialized.<String, String, KeyValueStore<Bytes, byte[]>>as("store").withLoggingDisabled(), nameProvider, storePrefix);
    final KeyValueStoreMaterializer<String, String> materializer = new KeyValueStoreMaterializer<>(materialized);
    final StoreBuilder<KeyValueStore<String, String>> builder = materializer.materialize();
    final KeyValueStore<String, String> store = builder.build();
    final WrappedStateStore caching = (WrappedStateStore) ((WrappedStateStore) store).wrappedStore();
    assertThat(caching, instanceOf(CachedStateStore.class));
    assertThat(caching.wrappedStore(), not(instanceOf(ChangeLoggingKeyValueBytesStore.class)));
}
Also used : WrappedStateStore(org.apache.kafka.streams.state.internals.WrappedStateStore) CachedStateStore(org.apache.kafka.streams.state.internals.CachedStateStore) KeyValueStore(org.apache.kafka.streams.state.KeyValueStore) InMemoryKeyValueStore(org.apache.kafka.streams.state.internals.InMemoryKeyValueStore) MaterializedInternal(org.apache.kafka.streams.kstream.internals.MaterializedInternal) KeyValueStoreMaterializer(org.apache.kafka.streams.kstream.internals.KeyValueStoreMaterializer) Test(org.junit.Test)

Example 2 with KeyValueStoreMaterializer

use of org.apache.kafka.streams.kstream.internals.KeyValueStoreMaterializer in project apache-kafka-on-k8s by banzaicloud.

the class KeyValueStoreMaterializerTest method shouldCreateKeyValueStoreWithTheProvidedInnerStore.

@Test
public void shouldCreateKeyValueStoreWithTheProvidedInnerStore() {
    final KeyValueBytesStoreSupplier supplier = EasyMock.createNiceMock(KeyValueBytesStoreSupplier.class);
    final InMemoryKeyValueStore<Bytes, byte[]> store = new InMemoryKeyValueStore<>("name", Serdes.Bytes(), Serdes.ByteArray());
    EasyMock.expect(supplier.name()).andReturn("name").anyTimes();
    EasyMock.expect(supplier.get()).andReturn(store);
    EasyMock.replay(supplier);
    final MaterializedInternal<String, Integer, KeyValueStore<Bytes, byte[]>> materialized = new MaterializedInternal<>(Materialized.<String, Integer>as(supplier), nameProvider, storePrefix);
    final KeyValueStoreMaterializer<String, Integer> materializer = new KeyValueStoreMaterializer<>(materialized);
    final StoreBuilder<KeyValueStore<String, Integer>> builder = materializer.materialize();
    final KeyValueStore<String, Integer> built = builder.build();
    final StateStore inner = ((WrappedStateStore) built).inner();
    assertThat(inner, CoreMatchers.<StateStore>equalTo(store));
}
Also used : WrappedStateStore(org.apache.kafka.streams.state.internals.WrappedStateStore) WrappedStateStore(org.apache.kafka.streams.state.internals.WrappedStateStore) CachedStateStore(org.apache.kafka.streams.state.internals.CachedStateStore) StateStore(org.apache.kafka.streams.processor.StateStore) KeyValueStore(org.apache.kafka.streams.state.KeyValueStore) InMemoryKeyValueStore(org.apache.kafka.streams.state.internals.InMemoryKeyValueStore) Bytes(org.apache.kafka.common.utils.Bytes) KeyValueBytesStoreSupplier(org.apache.kafka.streams.state.KeyValueBytesStoreSupplier) MaterializedInternal(org.apache.kafka.streams.kstream.internals.MaterializedInternal) KeyValueStoreMaterializer(org.apache.kafka.streams.kstream.internals.KeyValueStoreMaterializer) InMemoryKeyValueStore(org.apache.kafka.streams.state.internals.InMemoryKeyValueStore) Test(org.junit.Test)

Example 3 with KeyValueStoreMaterializer

use of org.apache.kafka.streams.kstream.internals.KeyValueStoreMaterializer in project apache-kafka-on-k8s by banzaicloud.

the class GlobalStreamThreadTest method before.

@SuppressWarnings("unchecked")
@Before
public void before() {
    final MaterializedInternal<Object, Object, KeyValueStore<Bytes, byte[]>> materialized = new MaterializedInternal<>(Materialized.<Object, Object, KeyValueStore<Bytes, byte[]>>with(null, null), new InternalNameProvider() {

        @Override
        public String newProcessorName(String prefix) {
            return "processorName";
        }

        @Override
        public String newStoreName(String prefix) {
            return GLOBAL_STORE_NAME;
        }
    }, "store-");
    builder.addGlobalStore((StoreBuilder) new KeyValueStoreMaterializer<>(materialized).materialize().withLoggingDisabled(), "sourceName", null, null, null, GLOBAL_STORE_TOPIC_NAME, "processorName", new KTableSource<>(GLOBAL_STORE_NAME));
    final HashMap<String, Object> properties = new HashMap<>();
    properties.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "blah");
    properties.put(StreamsConfig.APPLICATION_ID_CONFIG, "blah");
    properties.put(StreamsConfig.STATE_DIR_CONFIG, TestUtils.tempDirectory().getAbsolutePath());
    config = new StreamsConfig(properties);
    globalStreamThread = new GlobalStreamThread(builder.buildGlobalStateTopology(), config, mockConsumer, new StateDirectory(config, time), 0, new Metrics(), new MockTime(), "clientId", stateRestoreListener);
}
Also used : HashMap(java.util.HashMap) KeyValueStore(org.apache.kafka.streams.state.KeyValueStore) InternalNameProvider(org.apache.kafka.streams.kstream.internals.InternalNameProvider) Bytes(org.apache.kafka.common.utils.Bytes) Metrics(org.apache.kafka.common.metrics.Metrics) MaterializedInternal(org.apache.kafka.streams.kstream.internals.MaterializedInternal) KeyValueStoreMaterializer(org.apache.kafka.streams.kstream.internals.KeyValueStoreMaterializer) MockTime(org.apache.kafka.common.utils.MockTime) StreamsConfig(org.apache.kafka.streams.StreamsConfig) Before(org.junit.Before)

Example 4 with KeyValueStoreMaterializer

use of org.apache.kafka.streams.kstream.internals.KeyValueStoreMaterializer in project apache-kafka-on-k8s by banzaicloud.

the class KeyValueStoreMaterializerTest method shouldCreateBuilderThatBuildsStoreWithCachingDisabled.

@Test
public void shouldCreateBuilderThatBuildsStoreWithCachingDisabled() {
    final MaterializedInternal<String, String, KeyValueStore<Bytes, byte[]>> materialized = new MaterializedInternal<>(Materialized.<String, String, KeyValueStore<Bytes, byte[]>>as("store").withCachingDisabled(), nameProvider, storePrefix);
    final KeyValueStoreMaterializer<String, String> materializer = new KeyValueStoreMaterializer<>(materialized);
    final StoreBuilder<KeyValueStore<String, String>> builder = materializer.materialize();
    final KeyValueStore<String, String> store = builder.build();
    final WrappedStateStore logging = (WrappedStateStore) ((WrappedStateStore) store).wrappedStore();
    assertThat(logging, instanceOf(ChangeLoggingKeyValueBytesStore.class));
}
Also used : WrappedStateStore(org.apache.kafka.streams.state.internals.WrappedStateStore) ChangeLoggingKeyValueBytesStore(org.apache.kafka.streams.state.internals.ChangeLoggingKeyValueBytesStore) KeyValueStore(org.apache.kafka.streams.state.KeyValueStore) InMemoryKeyValueStore(org.apache.kafka.streams.state.internals.InMemoryKeyValueStore) MaterializedInternal(org.apache.kafka.streams.kstream.internals.MaterializedInternal) KeyValueStoreMaterializer(org.apache.kafka.streams.kstream.internals.KeyValueStoreMaterializer) Test(org.junit.Test)

Example 5 with KeyValueStoreMaterializer

use of org.apache.kafka.streams.kstream.internals.KeyValueStoreMaterializer in project apache-kafka-on-k8s by banzaicloud.

the class KeyValueStoreMaterializerTest method shouldCreateBuilderThatBuildsMeteredStoreWithCachingAndLoggingEnabled.

@Test
public void shouldCreateBuilderThatBuildsMeteredStoreWithCachingAndLoggingEnabled() {
    final MaterializedInternal<String, String, KeyValueStore<Bytes, byte[]>> materialized = new MaterializedInternal<>(Materialized.<String, String, KeyValueStore<Bytes, byte[]>>as("store"), nameProvider, storePrefix);
    final KeyValueStoreMaterializer<String, String> materializer = new KeyValueStoreMaterializer<>(materialized);
    final StoreBuilder<KeyValueStore<String, String>> builder = materializer.materialize();
    final KeyValueStore<String, String> store = builder.build();
    final WrappedStateStore caching = (WrappedStateStore) ((WrappedStateStore) store).wrappedStore();
    final StateStore logging = caching.wrappedStore();
    assertThat(store, instanceOf(MeteredKeyValueBytesStore.class));
    assertThat(caching, instanceOf(CachedStateStore.class));
    assertThat(logging, instanceOf(ChangeLoggingKeyValueBytesStore.class));
}
Also used : WrappedStateStore(org.apache.kafka.streams.state.internals.WrappedStateStore) MeteredKeyValueBytesStore(org.apache.kafka.streams.state.internals.MeteredKeyValueBytesStore) CachedStateStore(org.apache.kafka.streams.state.internals.CachedStateStore) WrappedStateStore(org.apache.kafka.streams.state.internals.WrappedStateStore) CachedStateStore(org.apache.kafka.streams.state.internals.CachedStateStore) StateStore(org.apache.kafka.streams.processor.StateStore) KeyValueStore(org.apache.kafka.streams.state.KeyValueStore) InMemoryKeyValueStore(org.apache.kafka.streams.state.internals.InMemoryKeyValueStore) Bytes(org.apache.kafka.common.utils.Bytes) ChangeLoggingKeyValueBytesStore(org.apache.kafka.streams.state.internals.ChangeLoggingKeyValueBytesStore) MaterializedInternal(org.apache.kafka.streams.kstream.internals.MaterializedInternal) KeyValueStoreMaterializer(org.apache.kafka.streams.kstream.internals.KeyValueStoreMaterializer) Test(org.junit.Test)

Aggregations

KeyValueStoreMaterializer (org.apache.kafka.streams.kstream.internals.KeyValueStoreMaterializer)6 MaterializedInternal (org.apache.kafka.streams.kstream.internals.MaterializedInternal)6 KeyValueStore (org.apache.kafka.streams.state.KeyValueStore)6 InMemoryKeyValueStore (org.apache.kafka.streams.state.internals.InMemoryKeyValueStore)5 WrappedStateStore (org.apache.kafka.streams.state.internals.WrappedStateStore)5 Test (org.junit.Test)5 Bytes (org.apache.kafka.common.utils.Bytes)4 CachedStateStore (org.apache.kafka.streams.state.internals.CachedStateStore)4 StateStore (org.apache.kafka.streams.processor.StateStore)3 ChangeLoggingKeyValueBytesStore (org.apache.kafka.streams.state.internals.ChangeLoggingKeyValueBytesStore)2 HashMap (java.util.HashMap)1 Metrics (org.apache.kafka.common.metrics.Metrics)1 MockTime (org.apache.kafka.common.utils.MockTime)1 StreamsConfig (org.apache.kafka.streams.StreamsConfig)1 InternalNameProvider (org.apache.kafka.streams.kstream.internals.InternalNameProvider)1 KeyValueBytesStoreSupplier (org.apache.kafka.streams.state.KeyValueBytesStoreSupplier)1 MeteredKeyValueBytesStore (org.apache.kafka.streams.state.internals.MeteredKeyValueBytesStore)1 Before (org.junit.Before)1