use of org.apache.kafka.streams.processor.Processor in project apache-kafka-on-k8s by banzaicloud.
the class KStreamTransformValuesTest method shouldNotAllowValueTransformerToCallInternalProcessorContextMethods.
@Test
public void shouldNotAllowValueTransformerToCallInternalProcessorContextMethods() {
final BadValueTransformer badValueTransformer = new BadValueTransformer();
final KStreamTransformValues<Integer, Integer, Integer> transformValue = new KStreamTransformValues<>(new InternalValueTransformerWithKeySupplier<Integer, Integer, Integer>() {
@Override
public InternalValueTransformerWithKey<Integer, Integer, Integer> get() {
return new InternalValueTransformerWithKey<Integer, Integer, Integer>() {
@Override
public Integer punctuate(long timestamp) {
throw new StreamsException("ValueTransformerWithKey#punctuate should not be called.");
}
@Override
public void init(final ProcessorContext context) {
badValueTransformer.init(context);
}
@Override
public Integer transform(final Integer readOnlyKey, final Integer value) {
return badValueTransformer.transform(readOnlyKey, value);
}
@Override
public void close() {
badValueTransformer.close();
}
};
}
});
final Processor transformValueProcessor = transformValue.get();
transformValueProcessor.init(null);
try {
transformValueProcessor.process(null, 0);
fail("should not allow call to context.forward() within ValueTransformer");
} catch (final StreamsException e) {
// expected
}
try {
transformValueProcessor.process(null, 1);
fail("should not allow call to context.forward() within ValueTransformer");
} catch (final StreamsException e) {
// expected
}
try {
transformValueProcessor.process(null, 2);
fail("should not allow call to context.forward() within ValueTransformer");
} catch (final StreamsException e) {
// expected
}
try {
transformValueProcessor.process(null, 3);
fail("should not allow call to context.forward() within ValueTransformer");
} catch (final StreamsException e) {
// expected
}
try {
transformValueProcessor.punctuate(0);
fail("should not allow ValueTransformer#puntuate() to return not-null value");
} catch (final StreamsException e) {
// expected
}
}
use of org.apache.kafka.streams.processor.Processor in project apache-kafka-on-k8s by banzaicloud.
the class SimpleBenchmark method createKafkaStreamsWithSink.
private KafkaStreams createKafkaStreamsWithSink(String topic, final CountDownLatch latch) {
setStreamProperties("simple-benchmark-streams-with-sink");
StreamsBuilder builder = new StreamsBuilder();
KStream<Integer, byte[]> source = builder.stream(topic, Consumed.with(INTEGER_SERDE, BYTE_SERDE));
source.to(INTEGER_SERDE, BYTE_SERDE, SINK_TOPIC);
source.process(new ProcessorSupplier<Integer, byte[]>() {
@Override
public Processor<Integer, byte[]> get() {
return new AbstractProcessor<Integer, byte[]>() {
@Override
public void init(ProcessorContext context) {
}
@Override
public void process(Integer key, byte[] value) {
processedRecords.getAndIncrement();
processedBytes += value.length + Integer.SIZE;
if (processedRecords.get() == numRecords) {
latch.countDown();
}
}
@Override
public void punctuate(long timestamp) {
}
@Override
public void close() {
}
};
}
});
return createKafkaStreamsWithExceptionHandler(builder, props);
}
use of org.apache.kafka.streams.processor.Processor in project apache-kafka-on-k8s by banzaicloud.
the class SimpleBenchmark method createKafkaStreams.
private KafkaStreams createKafkaStreams(String topic, final CountDownLatch latch) {
setStreamProperties("simple-benchmark-streams");
StreamsBuilder builder = new StreamsBuilder();
KStream<Integer, byte[]> source = builder.stream(topic, Consumed.with(INTEGER_SERDE, BYTE_SERDE));
source.process(new ProcessorSupplier<Integer, byte[]>() {
@Override
public Processor<Integer, byte[]> get() {
return new AbstractProcessor<Integer, byte[]>() {
@Override
public void init(ProcessorContext context) {
}
@Override
public void process(Integer key, byte[] value) {
processedRecords.getAndIncrement();
processedBytes += value.length + Integer.SIZE;
if (processedRecords.get() == numRecords) {
latch.countDown();
}
}
@Override
public void punctuate(long timestamp) {
}
@Override
public void close() {
}
};
}
});
return createKafkaStreamsWithExceptionHandler(builder, props);
}
Aggregations