use of org.apache.kafka.connect.sink.SinkRecord in project kafka by apache.
the class HoistFieldTest method schemaless.
@Test
public void schemaless() {
final HoistField<SinkRecord> xform = new HoistField.Key<>();
xform.configure(Collections.singletonMap("field", "magic"));
final SinkRecord record = new SinkRecord("test", 0, null, 42, null, null, 0);
final SinkRecord transformedRecord = xform.apply(record);
assertNull(transformedRecord.keySchema());
assertEquals(Collections.singletonMap("magic", 42), transformedRecord.key());
}
use of org.apache.kafka.connect.sink.SinkRecord in project kafka by apache.
the class ReplaceFieldTest method schemaless.
@Test
public void schemaless() {
final ReplaceField<SinkRecord> xform = new ReplaceField.Value<>();
final Map<String, String> props = new HashMap<>();
props.put("blacklist", "dont");
props.put("renames", "abc:xyz,foo:bar");
xform.configure(props);
final Map<String, Object> value = new HashMap<>();
value.put("dont", "whatever");
value.put("abc", 42);
value.put("foo", true);
value.put("etc", "etc");
final SinkRecord record = new SinkRecord("test", 0, null, null, null, value, 0);
final SinkRecord transformedRecord = xform.apply(record);
final Map updatedValue = (Map) transformedRecord.value();
assertEquals(3, updatedValue.size());
assertEquals(42, updatedValue.get("xyz"));
assertEquals(true, updatedValue.get("bar"));
assertEquals("etc", updatedValue.get("etc"));
}
use of org.apache.kafka.connect.sink.SinkRecord in project kafka by apache.
the class ReplaceFieldTest method withSchema.
@Test
public void withSchema() {
final ReplaceField<SinkRecord> xform = new ReplaceField.Value<>();
final Map<String, String> props = new HashMap<>();
props.put("whitelist", "abc,foo");
props.put("renames", "abc:xyz,foo:bar");
xform.configure(props);
final Schema schema = SchemaBuilder.struct().field("dont", Schema.STRING_SCHEMA).field("abc", Schema.INT32_SCHEMA).field("foo", Schema.BOOLEAN_SCHEMA).field("etc", Schema.STRING_SCHEMA).build();
final Struct value = new Struct(schema);
value.put("dont", "whatever");
value.put("abc", 42);
value.put("foo", true);
value.put("etc", "etc");
final SinkRecord record = new SinkRecord("test", 0, null, null, schema, value, 0);
final SinkRecord transformedRecord = xform.apply(record);
final Struct updatedValue = (Struct) transformedRecord.value();
assertEquals(2, updatedValue.schema().fields().size());
assertEquals(new Integer(42), updatedValue.getInt32("xyz"));
assertEquals(true, updatedValue.getBoolean("bar"));
}
use of org.apache.kafka.connect.sink.SinkRecord in project kafka by apache.
the class SetSchemaMetadataTest method schemaNameUpdate.
@Test
public void schemaNameUpdate() {
final SetSchemaMetadata<SinkRecord> xform = new SetSchemaMetadata.Value<>();
xform.configure(Collections.singletonMap("schema.name", "foo"));
final SinkRecord record = new SinkRecord("", 0, null, null, SchemaBuilder.struct().build(), null, 0);
final SinkRecord updatedRecord = xform.apply(record);
assertEquals("foo", updatedRecord.valueSchema().name());
}
use of org.apache.kafka.connect.sink.SinkRecord in project kafka by apache.
the class SetSchemaMetadataTest method schemaVersionUpdate.
@Test
public void schemaVersionUpdate() {
final SetSchemaMetadata<SinkRecord> xform = new SetSchemaMetadata.Value<>();
xform.configure(Collections.singletonMap("schema.version", 42));
final SinkRecord record = new SinkRecord("", 0, null, null, SchemaBuilder.struct().build(), null, 0);
final SinkRecord updatedRecord = xform.apply(record);
assertEquals(new Integer(42), updatedRecord.valueSchema().version());
}
Aggregations