本文整理汇总了Java中org.apache.kafka.common.serialization.Serdes.Integer方法的典型用法代码示例。如果您正苦于以下问题:Java Serdes.Integer方法的具体用法?Java Serdes.Integer怎么用?Java Serdes.Integer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.kafka.common.serialization.Serdes
的用法示例。
在下文中一共展示了Serdes.Integer方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doTestKTable
import org.apache.kafka.common.serialization.Serdes; //导入方法依赖的package包/类
private void doTestKTable(final KStreamBuilder builder, final KTable<String, Integer> table2,
final KTable<String, Integer> table3, final String topic1) {
MockProcessorSupplier<String, Integer> proc2 = new MockProcessorSupplier<>();
MockProcessorSupplier<String, Integer> proc3 = new MockProcessorSupplier<>();
table2.toStream().process(proc2);
table3.toStream().process(proc3);
driver = new KStreamTestDriver(builder, stateDir, Serdes.String(), Serdes.Integer());
driver.process(topic1, "A", 1);
driver.process(topic1, "B", 2);
driver.process(topic1, "C", 3);
driver.process(topic1, "D", 4);
driver.flushState();
driver.process(topic1, "A", null);
driver.process(topic1, "B", null);
driver.flushState();
proc2.checkAndClearProcessResult("A:null", "B:2", "C:null", "D:4", "A:null", "B:null");
proc3.checkAndClearProcessResult("A:1", "B:null", "C:3", "D:null", "A:null", "B:null");
}
示例2: doNotChangeOutputOrder
import org.apache.kafka.common.serialization.Serdes; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void doNotChangeOutputOrder() throws EmptyOutputSizeException, NoTopologyException, EmptyInputException {
List<Message<Integer, Integer>> input = of(1, 2, 3, 4, 5, 6, 7)
.map(i -> new Message<>(i, i))
.collect(toList());
Serde<Integer> integerSerde = Serdes.Integer();
List<Message<Integer, Integer>> output = Mockafka
.builder()
.topology(builder ->
builder.stream(integerSerde, integerSerde, "numbersTopic")
.filter((key, value) -> value % 2 == 1)
.to(integerSerde, integerSerde, "oddNumbersTopic")
)
.input("numbersTopic", integerSerde, integerSerde, input.toArray(new Message[]{}))
.output("oddNumbersTopic", integerSerde, integerSerde, 4);
List<Message<Integer, Integer>> expected = Arrays.asList(new Message<>(1, 1), new Message<>(3, 3), new Message<>(5, 5), new Message<>(7, 7));
assertEquals(4, output.size());
assertEquals(expected, output);
}
示例3: test
import org.apache.kafka.common.serialization.Serdes; //导入方法依赖的package包/类
@Test
public void test() throws Exception {
Map<String, Object> senderProps = KafkaTestUtils.producerProps(embeddedKafka);
Properties config = new Properties();
config.put(StreamsConfig.APPLICATION_ID_CONFIG, "stream-app");
config.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, senderProps.get("bootstrap.servers"));
config.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.Integer().getClass());
config.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.String().getClass());
Producer<Integer, String> producer = createProducer();
ProducerRecord<Integer, String> record = new ProducerRecord<>("stream-test", 1, "test");
producer.send(record);
final Serde<String> stringSerde = Serdes.String();
final Serde<Integer> intSerde = Serdes.Integer();
KStreamBuilder builder = new KStreamBuilder();
KStream<Integer, String> kStream = builder
.stream(intSerde, stringSerde, "stream-test");
kStream.map((key, value) -> new KeyValue<>(key, value + "map")).to("stream-out");
KafkaStreams streams = new KafkaStreams(builder, new StreamsConfig(config),
new TracingKafkaClientSupplier(mockTracer));
streams.start();
await().atMost(15, TimeUnit.SECONDS).until(reportedSpansSize(), equalTo(3));
streams.close();
producer.close();
List<MockSpan> spans = mockTracer.finishedSpans();
assertEquals(3, spans.size());
checkSpans(spans);
assertNull(mockTracer.activeSpan());
}
示例4: doShouldReduce
import org.apache.kafka.common.serialization.Serdes; //导入方法依赖的package包/类
private void doShouldReduce(final KTable<String, Integer> reduced, final String topic) throws Exception {
final Map<String, Integer> results = new HashMap<>();
reduced.foreach(new ForeachAction<String, Integer>() {
@Override
public void apply(final String key, final Integer value) {
results.put(key, value);
}
});
driver = new KStreamTestDriver(builder, TestUtils.tempDirectory(), Serdes.String(), Serdes.Integer());
driver.setTime(10L);
driver.process(topic, "A", 1.1);
driver.process(topic, "B", 2.2);
driver.flushState();
assertEquals(Integer.valueOf(1), results.get("A"));
assertEquals(Integer.valueOf(2), results.get("B"));
driver.process(topic, "A", 2.6);
driver.process(topic, "B", 1.3);
driver.process(topic, "A", 5.7);
driver.process(topic, "B", 6.2);
driver.flushState();
assertEquals(Integer.valueOf(5), results.get("A"));
assertEquals(Integer.valueOf(6), results.get("B"));
}
示例5: doTestNotSendingOldValue
import org.apache.kafka.common.serialization.Serdes; //导入方法依赖的package包/类
private void doTestNotSendingOldValue(final KStreamBuilder builder,
final KTableImpl<String, Integer, Integer> table1,
final KTableImpl<String, Integer, Integer> table2,
final String topic1) throws IOException {
MockProcessorSupplier<String, Integer> proc1 = new MockProcessorSupplier<>();
MockProcessorSupplier<String, Integer> proc2 = new MockProcessorSupplier<>();
builder.addProcessor("proc1", proc1, table1.name);
builder.addProcessor("proc2", proc2, table2.name);
driver = new KStreamTestDriver(builder, stateDir, Serdes.String(), Serdes.Integer());
driver.process(topic1, "A", 1);
driver.process(topic1, "B", 1);
driver.process(topic1, "C", 1);
driver.flushState();
proc1.checkAndClearProcessResult("A:(1<-null)", "B:(1<-null)", "C:(1<-null)");
proc2.checkAndClearProcessResult("A:(null<-null)", "B:(null<-null)", "C:(null<-null)");
driver.process(topic1, "A", 2);
driver.process(topic1, "B", 2);
driver.flushState();
proc1.checkAndClearProcessResult("A:(2<-null)", "B:(2<-null)");
proc2.checkAndClearProcessResult("A:(2<-null)", "B:(2<-null)");
driver.process(topic1, "A", 3);
driver.flushState();
proc1.checkAndClearProcessResult("A:(3<-null)");
proc2.checkAndClearProcessResult("A:(null<-null)");
driver.process(topic1, "A", null);
driver.process(topic1, "B", null);
driver.flushState();
proc1.checkAndClearProcessResult("A:(null<-null)", "B:(null<-null)");
proc2.checkAndClearProcessResult("A:(null<-null)", "B:(null<-null)");
}
示例6: doTestSendingOldValue
import org.apache.kafka.common.serialization.Serdes; //导入方法依赖的package包/类
private void doTestSendingOldValue(final KStreamBuilder builder,
final KTableImpl<String, Integer, Integer> table1,
final KTableImpl<String, Integer, Integer> table2,
final String topic1) throws IOException {
table2.enableSendingOldValues();
MockProcessorSupplier<String, Integer> proc1 = new MockProcessorSupplier<>();
MockProcessorSupplier<String, Integer> proc2 = new MockProcessorSupplier<>();
builder.addProcessor("proc1", proc1, table1.name);
builder.addProcessor("proc2", proc2, table2.name);
driver = new KStreamTestDriver(builder, stateDir, Serdes.String(), Serdes.Integer());
driver.process(topic1, "A", 1);
driver.process(topic1, "B", 1);
driver.process(topic1, "C", 1);
driver.flushState();
proc1.checkAndClearProcessResult("A:(1<-null)", "B:(1<-null)", "C:(1<-null)");
proc2.checkEmptyAndClearProcessResult();
driver.process(topic1, "A", 2);
driver.process(topic1, "B", 2);
driver.flushState();
proc1.checkAndClearProcessResult("A:(2<-1)", "B:(2<-1)");
proc2.checkAndClearProcessResult("A:(2<-null)", "B:(2<-null)");
driver.process(topic1, "A", 3);
driver.flushState();
proc1.checkAndClearProcessResult("A:(3<-2)");
proc2.checkAndClearProcessResult("A:(null<-2)");
driver.process(topic1, "A", null);
driver.process(topic1, "B", null);
driver.flushState();
proc1.checkAndClearProcessResult("A:(null<-3)", "B:(null<-2)");
proc2.checkAndClearProcessResult("B:(null<-2)");
}
示例7: createWindowStore
import org.apache.kafka.common.serialization.Serdes; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private <K, V> WindowStore<K, V> createWindowStore(ProcessorContext context, final boolean enableCaching, final boolean retainDuplicates) {
final RocksDBWindowStoreSupplier supplier = new RocksDBWindowStoreSupplier<>(windowName, retentionPeriod, numSegments, retainDuplicates, Serdes.Integer(), Serdes.String(),
WINDOW_SIZE, true, Collections.<String, String>emptyMap(), enableCaching);
final WindowStore<K, V> store = (WindowStore<K, V>) supplier.get();
store.init(context, store);
return store;
}
示例8: doTestValueGetter
import org.apache.kafka.common.serialization.Serdes; //导入方法依赖的package包/类
private void doTestValueGetter(final KStreamBuilder builder,
final KTableImpl<String, Integer, Integer> table2,
final KTableImpl<String, Integer, Integer> table3,
final String topic1) throws IOException {
KTableValueGetterSupplier<String, Integer> getterSupplier2 = table2.valueGetterSupplier();
KTableValueGetterSupplier<String, Integer> getterSupplier3 = table3.valueGetterSupplier();
driver = new KStreamTestDriver(builder, stateDir, Serdes.String(), Serdes.Integer());
KTableValueGetter<String, Integer> getter2 = getterSupplier2.get();
KTableValueGetter<String, Integer> getter3 = getterSupplier3.get();
getter2.init(driver.context());
getter3.init(driver.context());
driver.process(topic1, "A", 1);
driver.process(topic1, "B", 1);
driver.process(topic1, "C", 1);
assertNull(getter2.get("A"));
assertNull(getter2.get("B"));
assertNull(getter2.get("C"));
assertEquals(1, (int) getter3.get("A"));
assertEquals(1, (int) getter3.get("B"));
assertEquals(1, (int) getter3.get("C"));
driver.process(topic1, "A", 2);
driver.process(topic1, "B", 2);
assertEquals(2, (int) getter2.get("A"));
assertEquals(2, (int) getter2.get("B"));
assertNull(getter2.get("C"));
assertNull(getter3.get("A"));
assertNull(getter3.get("B"));
assertEquals(1, (int) getter3.get("C"));
driver.process(topic1, "A", 3);
assertNull(getter2.get("A"));
assertEquals(2, (int) getter2.get("B"));
assertNull(getter2.get("C"));
assertEquals(3, (int) getter3.get("A"));
assertNull(getter3.get("B"));
assertEquals(1, (int) getter3.get("C"));
driver.process(topic1, "A", null);
driver.process(topic1, "B", null);
assertNull(getter2.get("A"));
assertNull(getter2.get("B"));
assertNull(getter2.get("C"));
assertNull(getter3.get("A"));
assertNull(getter3.get("B"));
assertEquals(1, (int) getter3.get("C"));
}