use of org.apache.kafka.streams.state.SessionStore in project kafka by apache.
the class SessionWindowedKStreamImplTest method shouldMaterializeAggregated.
@Test
public void shouldMaterializeAggregated() {
stream.aggregate(MockInitializer.STRING_INIT, MockAggregator.TOSTRING_ADDER, sessionMerger, Materialized.<String, String, SessionStore<Bytes, byte[]>>as("aggregated").withValueSerde(Serdes.String()));
try (final TopologyTestDriver driver = new TopologyTestDriver(builder.build(), props)) {
processData(driver);
final SessionStore<String, String> sessionStore = driver.getSessionStore("aggregated");
final List<KeyValue<Windowed<String>, String>> data = StreamsTestUtils.toList(sessionStore.fetch("1", "2"));
assertThat(data, equalTo(Arrays.asList(KeyValue.pair(new Windowed<>("1", new SessionWindow(10, 15)), "0+0+1+2"), KeyValue.pair(new Windowed<>("1", new SessionWindow(600, 600)), "0+3"), KeyValue.pair(new Windowed<>("2", new SessionWindow(599, 600)), "0+0+1+2"))));
}
}
use of org.apache.kafka.streams.state.SessionStore in project kafka by apache.
the class MetricsIntegrationTest method shouldAddMetricsForSessionStore.
@Test
public void shouldAddMetricsForSessionStore() throws Exception {
final Duration inactivityGap = Duration.ofMillis(50);
builder.stream(STREAM_INPUT, Consumed.with(Serdes.Integer(), Serdes.String())).groupByKey().windowedBy(SessionWindows.with(inactivityGap).grace(Duration.ZERO)).aggregate(() -> 0L, (aggKey, newValue, aggValue) -> aggValue, (aggKey, leftAggValue, rightAggValue) -> leftAggValue, Materialized.<Integer, Long, SessionStore<Bytes, byte[]>>as(SESSION_AGGREGATED_STREAM_STORE).withValueSerde(Serdes.Long()).withRetention(inactivityGap)).toStream().map((key, value) -> KeyValue.pair(value, value)).to(STREAM_OUTPUT_1, Produced.with(Serdes.Long(), Serdes.Long()));
produceRecordsForTwoSegments(inactivityGap);
startApplication();
verifyStateMetric(State.RUNNING);
checkSessionStoreMetrics();
closeApplication();
checkMetricsDeregistration();
}
use of org.apache.kafka.streams.state.SessionStore in project kafka by apache.
the class SessionStoreFetchTest method getStoreConfig.
private Materialized<String, Long, SessionStore<Bytes, byte[]>> getStoreConfig(final StoreType type, final String name, final boolean cachingEnabled, final boolean loggingEnabled) {
final Supplier<SessionBytesStoreSupplier> createStore = () -> {
if (type == StoreType.InMemory) {
return Stores.inMemorySessionStore(STORE_NAME, Duration.ofMillis(RETENTION_MS));
} else if (type == StoreType.RocksDB) {
return Stores.persistentSessionStore(STORE_NAME, Duration.ofMillis(RETENTION_MS));
} else {
return Stores.inMemorySessionStore(STORE_NAME, Duration.ofMillis(RETENTION_MS));
}
};
final SessionBytesStoreSupplier stateStoreSupplier = createStore.get();
final Materialized<String, Long, SessionStore<Bytes, byte[]>> stateStoreConfig = Materialized.<String, Long>as(stateStoreSupplier).withKeySerde(Serdes.String()).withValueSerde(Serdes.Long());
if (cachingEnabled) {
stateStoreConfig.withCachingEnabled();
} else {
stateStoreConfig.withCachingDisabled();
}
if (loggingEnabled) {
stateStoreConfig.withLoggingEnabled(new HashMap<String, String>());
} else {
stateStoreConfig.withLoggingDisabled();
}
return stateStoreConfig;
}
Aggregations