use of org.apache.kafka.streams.kstream.Predicate in project apache-kafka-on-k8s by banzaicloud.
the class KTableFilterTest method testQueryableSkipNullOnMaterialization.
@Test
public void testQueryableSkipNullOnMaterialization() {
// Do not explicitly set enableSendingOldValues. Let a further downstream stateful operator trigger it instead.
StreamsBuilder builder = new StreamsBuilder();
String topic1 = "topic1";
final Consumed<String, String> consumed = Consumed.with(stringSerde, stringSerde);
KTableImpl<String, String, String> table1 = (KTableImpl<String, String, String>) builder.table(topic1, consumed);
KTableImpl<String, String, String> table2 = (KTableImpl<String, String, String>) table1.filter(new Predicate<String, String>() {
@Override
public boolean test(String key, String value) {
return value.equalsIgnoreCase("accept");
}
}, "anyStoreNameFilter").groupBy(MockMapper.<String, String>noOpKeyValueMapper()).reduce(MockReducer.STRING_ADDER, MockReducer.STRING_REMOVER, "mock-result");
doTestSkipNullOnMaterialization(builder, table1, table2, topic1);
}
use of org.apache.kafka.streams.kstream.Predicate in project apache-kafka-on-k8s by banzaicloud.
the class KTableFilterTest method testQueryableNotSendingOldValue.
@Test
public void testQueryableNotSendingOldValue() {
StreamsBuilder builder = new StreamsBuilder();
String topic1 = "topic1";
KTableImpl<String, Integer, Integer> table1 = (KTableImpl<String, Integer, Integer>) builder.table(topic1, consumed);
KTableImpl<String, Integer, Integer> table2 = (KTableImpl<String, Integer, Integer>) table1.filter(new Predicate<String, Integer>() {
@Override
public boolean test(String key, Integer value) {
return (value % 2) == 0;
}
}, "anyStoreNameFilter");
doTestNotSendingOldValue(builder, table1, table2, topic1);
}
use of org.apache.kafka.streams.kstream.Predicate in project apache-kafka-on-k8s by banzaicloud.
the class KTableFilterTest method testSkipNullOnMaterialization.
@Test
public void testSkipNullOnMaterialization() {
// Do not explicitly set enableSendingOldValues. Let a further downstream stateful operator trigger it instead.
StreamsBuilder builder = new StreamsBuilder();
String topic1 = "topic1";
final Consumed<String, String> consumed = Consumed.with(stringSerde, stringSerde);
KTableImpl<String, String, String> table1 = (KTableImpl<String, String, String>) builder.table(topic1, consumed);
KTableImpl<String, String, String> table2 = (KTableImpl<String, String, String>) table1.filter(new Predicate<String, String>() {
@Override
public boolean test(String key, String value) {
return value.equalsIgnoreCase("accept");
}
}).groupBy(MockMapper.<String, String>noOpKeyValueMapper()).reduce(MockReducer.STRING_ADDER, MockReducer.STRING_REMOVER, "mock-result");
doTestSkipNullOnMaterialization(builder, table1, table2, topic1);
}
use of org.apache.kafka.streams.kstream.Predicate in project apache-kafka-on-k8s by banzaicloud.
the class KTableImplTest method testStateStore.
@Test
public void testStateStore() {
String topic1 = "topic1";
String topic2 = "topic2";
final StreamsBuilder builder = new StreamsBuilder();
KTableImpl<String, String, String> table1 = (KTableImpl<String, String, String>) builder.table(topic1, consumed);
KTableImpl<String, String, String> table2 = (KTableImpl<String, String, String>) builder.table(topic2, consumed);
KTableImpl<String, String, Integer> table1Mapped = (KTableImpl<String, String, Integer>) table1.mapValues(new ValueMapper<String, Integer>() {
@Override
public Integer apply(String value) {
return new Integer(value);
}
});
KTableImpl<String, Integer, Integer> table1MappedFiltered = (KTableImpl<String, Integer, Integer>) table1Mapped.filter(new Predicate<String, Integer>() {
@Override
public boolean test(String key, Integer value) {
return (value % 2) == 0;
}
});
table2.join(table1MappedFiltered, new ValueJoiner<String, Integer, String>() {
@Override
public String apply(String v1, Integer v2) {
return v1 + v2;
}
});
driver.setUp(builder, stateDir, null, null);
driver.setTime(0L);
// two state store should be created
assertEquals(2, driver.allStateStores().size());
}
use of org.apache.kafka.streams.kstream.Predicate in project apache-kafka-on-k8s by banzaicloud.
the class KTableMapValuesTest method testValueGetter.
@Test
public void testValueGetter() {
StreamsBuilder builder = new StreamsBuilder();
String topic1 = "topic1";
String topic2 = "topic2";
String storeName2 = "storeName2";
KTableImpl<String, String, String> table1 = (KTableImpl<String, String, String>) builder.table(topic1, consumed);
KTableImpl<String, String, Integer> table2 = (KTableImpl<String, String, Integer>) table1.mapValues(new ValueMapper<String, Integer>() {
@Override
public Integer apply(String value) {
return new Integer(value);
}
});
KTableImpl<String, Integer, Integer> table3 = (KTableImpl<String, Integer, Integer>) table2.filter(new Predicate<String, Integer>() {
@Override
public boolean test(String key, Integer value) {
return (value % 2) == 0;
}
});
KTableImpl<String, String, String> table4 = (KTableImpl<String, String, String>) table1.through(stringSerde, stringSerde, topic2, storeName2);
doTestValueGetter(builder, topic1, table1, table2, table3, table4);
}
Aggregations