use of org.apache.kafka.connect.sink.SinkRecord in project kafka by apache.
the class ValueToKeyTest method withSchema.
@Test
public void withSchema() {
final ValueToKey<SinkRecord> xform = new ValueToKey<>();
xform.configure(Collections.singletonMap("fields", "a,b"));
final Schema valueSchema = SchemaBuilder.struct().field("a", Schema.INT32_SCHEMA).field("b", Schema.INT32_SCHEMA).field("c", Schema.INT32_SCHEMA).build();
final Struct value = new Struct(valueSchema);
value.put("a", 1);
value.put("b", 2);
value.put("c", 3);
final SinkRecord record = new SinkRecord("", 0, null, null, valueSchema, value, 0);
final SinkRecord transformedRecord = xform.apply(record);
final Schema expectedKeySchema = SchemaBuilder.struct().field("a", Schema.INT32_SCHEMA).field("b", Schema.INT32_SCHEMA).build();
final Struct expectedKey = new Struct(expectedKeySchema).put("a", 1).put("b", 2);
assertEquals(expectedKeySchema, transformedRecord.keySchema());
assertEquals(expectedKey, transformedRecord.key());
}
use of org.apache.kafka.connect.sink.SinkRecord in project kafka by apache.
the class ValueToKeyTest method schemaless.
@Test
public void schemaless() {
final ValueToKey<SinkRecord> xform = new ValueToKey<>();
xform.configure(Collections.singletonMap("fields", "a,b"));
final HashMap<String, Integer> value = new HashMap<>();
value.put("a", 1);
value.put("b", 2);
value.put("c", 3);
final SinkRecord record = new SinkRecord("", 0, null, null, null, value, 0);
final SinkRecord transformedRecord = xform.apply(record);
final HashMap<String, Integer> expectedKey = new HashMap<>();
expectedKey.put("a", 1);
expectedKey.put("b", 2);
assertNull(transformedRecord.keySchema());
assertEquals(expectedKey, transformedRecord.key());
}
Aggregations