Search in sources :

Example 76 with RecordHeaders

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();
}
Also used : RecordHeaders(org.apache.kafka.common.header.internals.RecordHeaders)

Example 77 with RecordHeaders

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"));
}
Also used : RecordHeaders(org.apache.kafka.common.header.internals.RecordHeaders) ByteArrayKafkaRecord(org.apache.beam.sdk.io.kafka.KafkaIO.ByteArrayKafkaRecord) ByteArrayKafkaRecord(org.apache.beam.sdk.io.kafka.KafkaIO.ByteArrayKafkaRecord) ByteString(org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString) Test(org.junit.Test)

Example 78 with RecordHeaders

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);
}
Also used : RecordHeaders(org.apache.kafka.common.header.internals.RecordHeaders) Test(org.junit.Test)

Example 79 with RecordHeaders

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());
}
Also used : RecordHeaders(org.apache.kafka.common.header.internals.RecordHeaders) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 80 with 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);
}
Also used : RecordHeaders(org.apache.kafka.common.header.internals.RecordHeaders) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

RecordHeaders (org.apache.kafka.common.header.internals.RecordHeaders)149 Test (org.junit.Test)107 ConsumerRecord (org.apache.kafka.clients.consumer.ConsumerRecord)49 ProcessorRecordContext (org.apache.kafka.streams.processor.internals.ProcessorRecordContext)41 Headers (org.apache.kafka.common.header.Headers)33 RecordHeader (org.apache.kafka.common.header.internals.RecordHeader)24 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)24 TopicPartition (org.apache.kafka.common.TopicPartition)22 Position (org.apache.kafka.streams.query.Position)17 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)12 ByteBuffer (java.nio.ByteBuffer)11 Struct (org.apache.kafka.connect.data.Struct)11 Test (org.junit.jupiter.api.Test)11 Header (org.apache.kafka.common.header.Header)10 LinkedHashMap (java.util.LinkedHashMap)9 Bytes (org.apache.kafka.common.utils.Bytes)9 StreamsException (org.apache.kafka.streams.errors.StreamsException)9 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)8 Metrics (org.apache.kafka.common.metrics.Metrics)8