use of org.apache.beam.sdk.io.kafka.KafkaIO.ByteArrayKafkaRecord in project beam by apache.
the class KafkaIOExternalTest method testKafkaRecordToExternalKafkaRecord.
@Test
public void testKafkaRecordToExternalKafkaRecord() throws Exception {
RecordHeaders headers = new RecordHeaders();
headers.add("dummyHeaderKey", "dummyHeaderVal".getBytes(StandardCharsets.UTF_8));
KafkaRecord<byte[], byte[]> kafkaRecord = new KafkaRecord("dummyTopic", 111, 222, 12345, KafkaTimestampType.LOG_APPEND_TIME, headers, "dummyKey".getBytes(StandardCharsets.UTF_8), "dummyValue".getBytes(StandardCharsets.UTF_8));
ByteArrayKafkaRecord byteArrayKafkaRecord = RowsWithMetadata.toExternalKafkaRecord(kafkaRecord);
assertEquals("dummyTopic", byteArrayKafkaRecord.topic);
assertEquals(111, byteArrayKafkaRecord.partition);
assertEquals(222, byteArrayKafkaRecord.offset);
assertEquals(12345, byteArrayKafkaRecord.timestamp);
assertEquals(KafkaTimestampType.LOG_APPEND_TIME.id, byteArrayKafkaRecord.timestampTypeId);
assertEquals(KafkaTimestampType.LOG_APPEND_TIME.name, byteArrayKafkaRecord.timestampTypeName);
assertEquals("dummyKey", new String(byteArrayKafkaRecord.key, "UTF-8"));
assertEquals("dummyValue", new String(byteArrayKafkaRecord.value, "UTF-8"));
assertEquals(1, byteArrayKafkaRecord.headers.size());
assertEquals("dummyHeaderKey", byteArrayKafkaRecord.headers.get(0).key);
assertEquals("dummyHeaderVal", new String(byteArrayKafkaRecord.headers.get(0).value, "UTF-8"));
}
Aggregations