use of org.apache.kafka.streams.state.KeyValueBytesStoreSupplier in project kafka by apache.
the class MockProcessorContextStateStoreTest method parameters.
public static Stream<Arguments> parameters() {
final List<Boolean> booleans = asList(true, false);
final List<Arguments> values = new ArrayList<>();
for (final Boolean timestamped : booleans) {
for (final Boolean caching : booleans) {
for (final Boolean logging : booleans) {
final List<KeyValueBytesStoreSupplier> keyValueBytesStoreSuppliers = asList(Stores.inMemoryKeyValueStore("kv" + timestamped + caching + logging), Stores.persistentKeyValueStore("kv" + timestamped + caching + logging), Stores.persistentTimestampedKeyValueStore("kv" + timestamped + caching + logging));
for (final KeyValueBytesStoreSupplier supplier : keyValueBytesStoreSuppliers) {
final StoreBuilder<? extends KeyValueStore<String, ?>> builder;
if (timestamped) {
builder = Stores.timestampedKeyValueStoreBuilder(supplier, Serdes.String(), Serdes.Long());
} else {
builder = Stores.keyValueStoreBuilder(supplier, Serdes.String(), Serdes.Long());
}
if (caching) {
builder.withCachingEnabled();
} else {
builder.withCachingDisabled();
}
if (logging) {
builder.withLoggingEnabled(Collections.emptyMap());
} else {
builder.withLoggingDisabled();
}
values.add(Arguments.of(builder, timestamped, caching, logging));
}
}
}
}
for (final Boolean timestamped : booleans) {
for (final Boolean caching : booleans) {
for (final Boolean logging : booleans) {
final List<WindowBytesStoreSupplier> windowBytesStoreSuppliers = asList(Stores.inMemoryWindowStore("w" + timestamped + caching + logging, Duration.ofSeconds(1), Duration.ofSeconds(1), false), Stores.persistentWindowStore("w" + timestamped + caching + logging, Duration.ofSeconds(1), Duration.ofSeconds(1), false), Stores.persistentTimestampedWindowStore("w" + timestamped + caching + logging, Duration.ofSeconds(1), Duration.ofSeconds(1), false));
for (final WindowBytesStoreSupplier supplier : windowBytesStoreSuppliers) {
final StoreBuilder<? extends WindowStore<String, ?>> builder;
if (timestamped) {
builder = Stores.timestampedWindowStoreBuilder(supplier, Serdes.String(), Serdes.Long());
} else {
builder = Stores.windowStoreBuilder(supplier, Serdes.String(), Serdes.Long());
}
if (caching) {
builder.withCachingEnabled();
} else {
builder.withCachingDisabled();
}
if (logging) {
builder.withLoggingEnabled(Collections.emptyMap());
} else {
builder.withLoggingDisabled();
}
values.add(Arguments.of(builder, timestamped, caching, logging));
}
}
}
}
for (final Boolean caching : booleans) {
for (final Boolean logging : booleans) {
final List<SessionBytesStoreSupplier> sessionBytesStoreSuppliers = asList(Stores.inMemorySessionStore("s" + caching + logging, Duration.ofSeconds(1)), Stores.persistentSessionStore("s" + caching + logging, Duration.ofSeconds(1)));
for (final SessionBytesStoreSupplier supplier : sessionBytesStoreSuppliers) {
final StoreBuilder<? extends SessionStore<String, ?>> builder = Stores.sessionStoreBuilder(supplier, Serdes.String(), Serdes.Long());
if (caching) {
builder.withCachingEnabled();
} else {
builder.withCachingDisabled();
}
if (logging) {
builder.withLoggingEnabled(Collections.emptyMap());
} else {
builder.withLoggingDisabled();
}
values.add(Arguments.of(builder, false, caching, logging));
}
}
}
return values.stream();
}
use of org.apache.kafka.streams.state.KeyValueBytesStoreSupplier in project kafkastreams-cep by fhussonnois.
the class QueryStoreBuilders method getAggregateStateStores.
/**
* Build all {@link StoreBuilder} used to store aggregate states for stages.
*
* @return a new collection of {@link StoreBuilder}.
*/
public StoreBuilder<AggregatesStore<K>> getAggregateStateStores() {
final String storeName = QueryStores.getQueryAggregateStatesStoreName(queryName);
KeyValueBytesStoreSupplier storeSupplier = Stores.persistentKeyValueStore(storeName);
return QueryStores.aggregatesStoreBuilder(storeSupplier);
}
use of org.apache.kafka.streams.state.KeyValueBytesStoreSupplier in project apache-kafka-on-k8s by banzaicloud.
the class KeyValueStoreMaterializer method materialize.
/**
* @return StoreBuilder
*/
public StoreBuilder<KeyValueStore<K, V>> materialize() {
KeyValueBytesStoreSupplier supplier = (KeyValueBytesStoreSupplier) materialized.storeSupplier();
if (supplier == null) {
final String name = materialized.storeName();
supplier = Stores.persistentKeyValueStore(name);
}
final StoreBuilder<KeyValueStore<K, V>> builder = Stores.keyValueStoreBuilder(supplier, materialized.keySerde(), materialized.valueSerde());
if (materialized.loggingEnabled()) {
builder.withLoggingEnabled(materialized.logConfig());
} else {
builder.withLoggingDisabled();
}
if (materialized.cachingEnabled()) {
builder.withCachingEnabled();
}
return builder;
}
use of org.apache.kafka.streams.state.KeyValueBytesStoreSupplier in project kafka by apache.
the class KTableEfficientRangeQueryTest method getStoreConfig.
private Materialized<String, String, KeyValueStore<Bytes, byte[]>> getStoreConfig(final StoreType type, final String name, final boolean cachingEnabled, final boolean loggingEnabled) {
final Supplier<KeyValueBytesStoreSupplier> createStore = () -> {
if (type == StoreType.InMemory) {
return Stores.inMemoryKeyValueStore(TABLE_NAME);
} else if (type == StoreType.RocksDB) {
return Stores.persistentKeyValueStore(TABLE_NAME);
} else if (type == StoreType.Timed) {
return Stores.persistentTimestampedKeyValueStore(TABLE_NAME);
} else {
return Stores.inMemoryKeyValueStore(TABLE_NAME);
}
};
final KeyValueBytesStoreSupplier stateStoreSupplier = createStore.get();
final Materialized<String, String, KeyValueStore<Bytes, byte[]>> stateStoreConfig = Materialized.<String, String>as(stateStoreSupplier).withKeySerde(Serdes.String()).withValueSerde(Serdes.String());
if (cachingEnabled) {
stateStoreConfig.withCachingEnabled();
} else {
stateStoreConfig.withCachingDisabled();
}
if (loggingEnabled) {
stateStoreConfig.withLoggingEnabled(new HashMap<String, String>());
} else {
stateStoreConfig.withLoggingDisabled();
}
return stateStoreConfig;
}
use of org.apache.kafka.streams.state.KeyValueBytesStoreSupplier in project kafka by apache.
the class IQv2IntegrationTest method shouldNotRequireQueryHandler.
@Test
public void shouldNotRequireQueryHandler() {
final KeyQuery<Integer, ValueAndTimestamp<Integer>> query = KeyQuery.withKey(1);
final int partition = 1;
final Set<Integer> partitions = singleton(partition);
final StateQueryRequest<ValueAndTimestamp<Integer>> request = inStore(STORE_NAME).withQuery(query).withPartitions(partitions);
final StreamsBuilder builder = new StreamsBuilder();
builder.table(INPUT_TOPIC_NAME, Consumed.with(Serdes.Integer(), Serdes.Integer()), Materialized.as(new KeyValueBytesStoreSupplier() {
@Override
public String name() {
return STORE_NAME;
}
@Override
public KeyValueStore<Bytes, byte[]> get() {
return new KeyValueStore<Bytes, byte[]>() {
private boolean open = false;
private Map<Bytes, byte[]> map = new HashMap<>();
private Position position;
private StateStoreContext context;
@Override
public void put(final Bytes key, final byte[] value) {
map.put(key, value);
StoreQueryUtils.updatePosition(position, context);
}
@Override
public byte[] putIfAbsent(final Bytes key, final byte[] value) {
StoreQueryUtils.updatePosition(position, context);
return map.putIfAbsent(key, value);
}
@Override
public void putAll(final List<KeyValue<Bytes, byte[]>> entries) {
StoreQueryUtils.updatePosition(position, context);
for (final KeyValue<Bytes, byte[]> entry : entries) {
map.put(entry.key, entry.value);
}
}
@Override
public byte[] delete(final Bytes key) {
StoreQueryUtils.updatePosition(position, context);
return map.remove(key);
}
@Override
public String name() {
return STORE_NAME;
}
@Deprecated
@Override
public void init(final ProcessorContext context, final StateStore root) {
throw new UnsupportedOperationException();
}
@Override
public void init(final StateStoreContext context, final StateStore root) {
context.register(root, (key, value) -> put(Bytes.wrap(key), value));
this.open = true;
this.position = Position.emptyPosition();
this.context = context;
}
@Override
public void flush() {
}
@Override
public void close() {
this.open = false;
map.clear();
}
@Override
public boolean persistent() {
return false;
}
@Override
public boolean isOpen() {
return open;
}
@Override
public Position getPosition() {
return position;
}
@Override
public byte[] get(final Bytes key) {
return map.get(key);
}
@Override
public KeyValueIterator<Bytes, byte[]> range(final Bytes from, final Bytes to) {
throw new UnsupportedOperationException();
}
@Override
public KeyValueIterator<Bytes, byte[]> all() {
throw new UnsupportedOperationException();
}
@Override
public long approximateNumEntries() {
return map.size();
}
};
}
@Override
public String metricsScope() {
return "nonquery";
}
}));
kafkaStreams = new KafkaStreams(builder.build(), streamsConfiguration());
kafkaStreams.cleanUp();
kafkaStreams.start();
final StateQueryResult<ValueAndTimestamp<Integer>> result = IntegrationTestUtils.iqv2WaitForResult(kafkaStreams, request);
final QueryResult<ValueAndTimestamp<Integer>> queryResult = result.getPartitionResults().get(partition);
assertThat(queryResult.isFailure(), is(true));
assertThat(queryResult.getFailureReason(), is(FailureReason.UNKNOWN_QUERY_TYPE));
assertThat(queryResult.getFailureMessage(), matchesPattern("This store (.*) doesn't know how to execute the given query (.*)." + " Contact the store maintainer if you need support for a new query type."));
}
Aggregations