Search in sources :

Example 11 with TimestampType

use of org.apache.kafka.common.record.TimestampType in project kafka by apache.

the class WorkerSinkTaskTest method testTimestampPropagation.

@Test
public void testTimestampPropagation() throws Exception {
    final Long timestamp = System.currentTimeMillis();
    final TimestampType timestampType = TimestampType.CREATE_TIME;
    createTask(initialState);
    expectInitializeTask();
    expectTaskGetTopic(true);
    expectPollInitialAssignment();
    expectConsumerPoll(1, timestamp, timestampType);
    expectConversionAndTransformation(1);
    Capture<Collection<SinkRecord>> records = EasyMock.newCapture(CaptureType.ALL);
    sinkTask.put(EasyMock.capture(records));
    PowerMock.replayAll();
    workerTask.initialize(TASK_CONFIG);
    workerTask.initializeAndStart();
    // iter 1 -- initial assignment
    workerTask.iteration();
    // iter 2 -- deliver 1 record
    workerTask.iteration();
    SinkRecord record = records.getValue().iterator().next();
    assertEquals(timestamp, record.timestamp());
    assertEquals(timestampType, record.timestampType());
    PowerMock.verifyAll();
}
Also used : TimestampType(org.apache.kafka.common.record.TimestampType) Collection(java.util.Collection) SinkRecord(org.apache.kafka.connect.sink.SinkRecord) RetryWithToleranceOperatorTest(org.apache.kafka.connect.runtime.errors.RetryWithToleranceOperatorTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

TimestampType (org.apache.kafka.common.record.TimestampType)11 ConsumerRecord (org.apache.kafka.clients.consumer.ConsumerRecord)7 ArrayList (java.util.ArrayList)5 Collection (java.util.Collection)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 TopicPartition (org.apache.kafka.common.TopicPartition)5 Test (org.junit.Test)5 ByteBuffer (java.nio.ByteBuffer)4 List (java.util.List)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 RecordHeaders (org.apache.kafka.common.header.internals.RecordHeaders)4 TimeUnit (java.util.concurrent.TimeUnit)3 Collectors (java.util.stream.Collectors)3 KafkaException (org.apache.kafka.common.KafkaException)3 PartitionInfo (org.apache.kafka.common.PartitionInfo)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 Collections (java.util.Collections)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 PCollection (org.apache.beam.sdk.values.PCollection)2