use of org.apache.kafka.streams.processor.api.RecordMetadata in project kafka by apache.
the class StoreQueryUtils method updatePosition.
public static void updatePosition(final Position position, final StateStoreContext stateStoreContext) {
if (stateStoreContext != null && stateStoreContext.recordMetadata().isPresent()) {
final RecordMetadata meta = stateStoreContext.recordMetadata().get();
position.withComponent(meta.topic(), meta.partition(), meta.offset());
}
}
use of org.apache.kafka.streams.processor.api.RecordMetadata in project kafka by apache.
the class MockProcessorContextAPITest method shouldCaptureApplicationAndRecordMetadata.
@Test
public void shouldCaptureApplicationAndRecordMetadata() {
final Properties config = mkProperties(mkMap(mkEntry(StreamsConfig.APPLICATION_ID_CONFIG, "testMetadata"), mkEntry(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "")));
final Processor<String, Object, String, Object> processor = new Processor<String, Object, String, Object>() {
private ProcessorContext<String, Object> context;
@Override
public void init(final ProcessorContext<String, Object> context) {
this.context = context;
}
@Override
public void process(final Record<String, Object> record) {
context.forward(new Record<String, Object>("appId", context.applicationId(), 0L));
context.forward(new Record<String, Object>("taskId", context.taskId(), 0L));
if (context.recordMetadata().isPresent()) {
final RecordMetadata recordMetadata = context.recordMetadata().get();
context.forward(new Record<String, Object>("topic", recordMetadata.topic(), 0L));
context.forward(new Record<String, Object>("partition", recordMetadata.partition(), 0L));
context.forward(new Record<String, Object>("offset", recordMetadata.offset(), 0L));
}
context.forward(new Record<String, Object>("record", record, 0L));
}
};
final MockProcessorContext<String, Object> context = new MockProcessorContext<>(config);
processor.init(context);
processor.process(new Record<>("foo", 5L, 0L));
{
final List<CapturedForward<? extends String, ?>> forwarded = context.forwarded();
final List<CapturedForward<? extends String, ?>> expected = asList(new CapturedForward<>(new Record<>("appId", "testMetadata", 0L)), new CapturedForward<>(new Record<>("taskId", new TaskId(0, 0), 0L)), new CapturedForward<>(new Record<>("record", new Record<>("foo", 5L, 0L), 0L)));
assertThat(forwarded, is(expected));
}
context.resetForwards();
context.setRecordMetadata("t1", 0, 0L);
processor.process(new Record<>("foo", 5L, 0L));
{
final List<CapturedForward<? extends String, ?>> forwarded = context.forwarded();
final List<CapturedForward<? extends String, ?>> expected = asList(new CapturedForward<>(new Record<>("appId", "testMetadata", 0L)), new CapturedForward<>(new Record<>("taskId", new TaskId(0, 0), 0L)), new CapturedForward<>(new Record<>("topic", "t1", 0L)), new CapturedForward<>(new Record<>("partition", 0, 0L)), new CapturedForward<>(new Record<>("offset", 0L, 0L)), new CapturedForward<>(new Record<>("record", new Record<>("foo", 5L, 0L), 0L)));
assertThat(forwarded, is(expected));
}
}
Aggregations