use of org.apache.kafka.common.header.internals.RecordHeaders in project pinpoint by naver.
the class ProducerAddHeaderInterceptorTest method getHeadersWhenSampled.
private Header[] getHeadersWhenSampled() {
doReturn(trace).when(traceContext).currentRawTraceObject();
doReturn(true).when(trace).canSampled();
doReturn(traceId).when(trace).getTraceId();
doReturn(nextId).when(traceId).getNextTraceId();
doReturn(recorder).when(trace).currentSpanEventRecorder();
doReturn(apiVersions).when(apiVersionsGetter)._$PINPOINT$_getApiVersions();
doReturn(RecordBatch.MAGIC_VALUE_V2).when(apiVersions).maxUsableProduceMagic();
doReturn("test").when(nextId).getTransactionId();
doReturn(0L).when(nextId).getSpanId();
doReturn(0L).when(nextId).getParentSpanId();
short s = 0;
doReturn(s).when(nextId).getFlags();
ProducerAddHeaderInterceptor interceptor = new ProducerAddHeaderInterceptor(traceContext);
RecordHeaders recordHeader = new RecordHeaders();
Object[] args = new Object[] { recordHeader };
interceptor.before(apiVersionsGetter, args);
return recordHeader.toArray();
}
use of org.apache.kafka.common.header.internals.RecordHeaders 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"));
}
use of org.apache.kafka.common.header.internals.RecordHeaders in project beam by apache.
the class KafkaRecordCoderTest method testKafkaRecordSerializableWithHeaders.
@Test
public void testKafkaRecordSerializableWithHeaders() throws IOException {
RecordHeaders headers = new RecordHeaders();
headers.add("headerKey", "headerVal".getBytes(StandardCharsets.UTF_8));
verifySerialization(headers);
}
use of org.apache.kafka.common.header.internals.RecordHeaders in project beam by apache.
the class ProducerRecordCoderTest method testProducerRecordStructuralValueWithoutHeadersApi.
@Test
public void testProducerRecordStructuralValueWithoutHeadersApi() throws IOException {
RecordHeaders headers = new RecordHeaders();
headers.add("headerKey", "headerVal".getBytes(UTF_8));
ProducerRecordCoder producerRecordCoder = ProducerRecordCoder.of(ByteArrayCoder.of(), ByteArrayCoder.of());
ProducerRecord<byte[], byte[]> producerRecord = new ProducerRecord<>("topic", 1, null, "key".getBytes(UTF_8), "value".getBytes(UTF_8), headers);
mockStatic(ConsumerSpEL.class);
when(ConsumerSpEL.hasHeaders()).thenReturn(false);
ProducerRecord testProducerRecord = (ProducerRecord) producerRecordCoder.structuralValue(producerRecord);
assertEquals(testProducerRecord.headers(), new RecordHeaders());
}
use of org.apache.kafka.common.header.internals.RecordHeaders in project beam by apache.
the class ProducerRecordCoderTest method testProducerRecordStructuralValueWithHeadersApi.
@Test
public void testProducerRecordStructuralValueWithHeadersApi() throws IOException {
RecordHeaders headers = new RecordHeaders();
headers.add("headerKey", "headerVal".getBytes(UTF_8));
ProducerRecordCoder producerRecordCoder = ProducerRecordCoder.of(ByteArrayCoder.of(), ByteArrayCoder.of());
ProducerRecord<byte[], byte[]> producerRecord = new ProducerRecord<>("topic", 1, null, "key".getBytes(UTF_8), "value".getBytes(UTF_8), headers);
ProducerRecord testProducerRecord = (ProducerRecord) producerRecordCoder.structuralValue(producerRecord);
assertEquals(testProducerRecord.headers(), headers);
}
Aggregations