Search in sources :

Example 11 with RecordPublisher

use of org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordPublisher in project flink by apache.

the class FanOutRecordPublisherTest method testToSdkV1Records.

@Test
public void testToSdkV1Records() throws Exception {
    Date now = new Date();
    byte[] data = new byte[] { 0, 1, 2, 3 };
    Record record = Record.builder().approximateArrivalTimestamp(now.toInstant()).partitionKey("pk").sequenceNumber("sn").data(SdkBytes.fromByteArray(data)).build();
    KinesisProxyV2Interface kinesis = singletonShard(createSubscribeToShardEvent(record));
    RecordPublisher publisher = createRecordPublisher(kinesis, latest());
    TestConsumer consumer = new TestConsumer();
    publisher.run(consumer);
    UserRecord actual = consumer.getRecordBatches().get(0).getDeaggregatedRecords().get(0);
    assertFalse(actual.isAggregated());
    assertEquals(now, actual.getApproximateArrivalTimestamp());
    assertEquals("sn", actual.getSequenceNumber());
    assertEquals("pk", actual.getPartitionKey());
    assertThat(toByteArray(actual.getData()), Matchers.equalTo(data));
}
Also used : RecordPublisher(org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordPublisher) UserRecord(com.amazonaws.services.kinesis.clientlibrary.types.UserRecord) UserRecord(com.amazonaws.services.kinesis.clientlibrary.types.UserRecord) Record(software.amazon.awssdk.services.kinesis.model.Record) KinesisProxyV2Interface(org.apache.flink.streaming.connectors.kinesis.proxy.KinesisProxyV2Interface) Date(java.util.Date) TestConsumer(org.apache.flink.streaming.connectors.kinesis.testutils.TestUtils.TestConsumer) Test(org.junit.Test)

Example 12 with RecordPublisher

use of org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordPublisher in project flink by apache.

the class FanOutRecordPublisherTest method testToSdkV2StartingPositionAtSequenceNumber.

@Test
public void testToSdkV2StartingPositionAtSequenceNumber() throws Exception {
    SingleShardFanOutKinesisV2 kinesis = emptyShard();
    RecordPublisher publisher = createRecordPublisher(kinesis, StartingPosition.restartFromSequenceNumber(AGGREGATED_SEQUENCE_NUMBER));
    publisher.run(new TestConsumer());
    assertEquals(DUMMY_SEQUENCE, kinesis.getStartingPositionForSubscription(0).sequenceNumber());
    assertEquals(AT_SEQUENCE_NUMBER, kinesis.getStartingPositionForSubscription(0).type());
}
Also used : RecordPublisher(org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordPublisher) SingleShardFanOutKinesisV2(org.apache.flink.streaming.connectors.kinesis.testutils.FakeKinesisFanOutBehavioursFactory.SingleShardFanOutKinesisV2) TestConsumer(org.apache.flink.streaming.connectors.kinesis.testutils.TestUtils.TestConsumer) Test(org.junit.Test)

Example 13 with RecordPublisher

use of org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordPublisher in project flink by apache.

the class FanOutRecordPublisherTest method testShardConsumerRetriesIfLimitExceededExceptionThrownFromSubscription.

@Test
public void testShardConsumerRetriesIfLimitExceededExceptionThrownFromSubscription() throws Exception {
    LimitExceededException exception = LimitExceededException.builder().build();
    SubscriptionErrorKinesisV2 kinesis = FakeKinesisFanOutBehavioursFactory.errorDuringSubscription(exception);
    RecordPublisher recordPublisher = createRecordPublisher(kinesis);
    TestConsumer consumer = new TestConsumer();
    RecordPublisherRunResult result = recordPublisher.run(consumer);
    // An exception is thrown after the 5th record in each subscription, therefore we expect to
    // receive 5 records
    assertEquals(5, consumer.getRecordBatches().size());
    assertEquals(1, kinesis.getNumberOfSubscribeToShardInvocations());
    // INCOMPLETE is returned to indicate the shard is not complete
    assertEquals(INCOMPLETE, result);
}
Also used : RecordPublisher(org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordPublisher) RecordPublisherRunResult(org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordPublisher.RecordPublisherRunResult) LimitExceededException(software.amazon.awssdk.services.kinesis.model.LimitExceededException) SubscriptionErrorKinesisV2(org.apache.flink.streaming.connectors.kinesis.testutils.FakeKinesisFanOutBehavioursFactory.SubscriptionErrorKinesisV2) TestConsumer(org.apache.flink.streaming.connectors.kinesis.testutils.TestUtils.TestConsumer) Test(org.junit.Test)

Example 14 with RecordPublisher

use of org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordPublisher in project flink by apache.

the class FanOutRecordPublisherTest method testToSdkV2StartingPositionAfterSequenceNumber.

@Test
public void testToSdkV2StartingPositionAfterSequenceNumber() throws Exception {
    SingleShardFanOutKinesisV2 kinesis = emptyShard();
    RecordPublisher publisher = createRecordPublisher(kinesis, StartingPosition.continueFromSequenceNumber(SEQUENCE_NUMBER));
    publisher.run(new TestConsumer());
    assertEquals(DUMMY_SEQUENCE, kinesis.getStartingPositionForSubscription(0).sequenceNumber());
    assertEquals(AFTER_SEQUENCE_NUMBER, kinesis.getStartingPositionForSubscription(0).type());
}
Also used : RecordPublisher(org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordPublisher) SingleShardFanOutKinesisV2(org.apache.flink.streaming.connectors.kinesis.testutils.FakeKinesisFanOutBehavioursFactory.SingleShardFanOutKinesisV2) TestConsumer(org.apache.flink.streaming.connectors.kinesis.testutils.TestUtils.TestConsumer) Test(org.junit.Test)

Example 15 with RecordPublisher

use of org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordPublisher in project flink by apache.

the class FanOutRecordPublisherTest method testToSdkV2StartingPositionAtTimeStamp.

@Test
public void testToSdkV2StartingPositionAtTimeStamp() throws Exception {
    SingleShardFanOutKinesisV2 kinesis = emptyShard();
    Date now = new Date();
    RecordPublisher publisher = createRecordPublisher(kinesis, StartingPosition.fromTimestamp(now));
    publisher.run(new TestConsumer());
    assertEquals(now.toInstant(), kinesis.getStartingPositionForSubscription(0).timestamp());
    assertEquals(AT_TIMESTAMP, kinesis.getStartingPositionForSubscription(0).type());
}
Also used : RecordPublisher(org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordPublisher) SingleShardFanOutKinesisV2(org.apache.flink.streaming.connectors.kinesis.testutils.FakeKinesisFanOutBehavioursFactory.SingleShardFanOutKinesisV2) Date(java.util.Date) TestConsumer(org.apache.flink.streaming.connectors.kinesis.testutils.TestUtils.TestConsumer) Test(org.junit.Test)

Aggregations

RecordPublisher (org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordPublisher)16 Test (org.junit.Test)15 TestConsumer (org.apache.flink.streaming.connectors.kinesis.testutils.TestUtils.TestConsumer)12 SingleShardFanOutKinesisV2 (org.apache.flink.streaming.connectors.kinesis.testutils.FakeKinesisFanOutBehavioursFactory.SingleShardFanOutKinesisV2)8 KinesisProxyV2Interface (org.apache.flink.streaming.connectors.kinesis.proxy.KinesisProxyV2Interface)4 UserRecord (com.amazonaws.services.kinesis.clientlibrary.types.UserRecord)3 StreamShardHandle (org.apache.flink.streaming.connectors.kinesis.model.StreamShardHandle)3 Date (java.util.Date)2 Properties (java.util.Properties)2 RecordPublisherRunResult (org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordPublisher.RecordPublisherRunResult)2 SubscriptionErrorKinesisV2 (org.apache.flink.streaming.connectors.kinesis.testutils.FakeKinesisFanOutBehavioursFactory.SubscriptionErrorKinesisV2)2 SdkInterruptedException (com.amazonaws.http.timers.client.SdkInterruptedException)1 LinkedList (java.util.LinkedList)1 SimpleStringSchema (org.apache.flink.api.common.serialization.SimpleStringSchema)1 ShardConsumerMetricsReporter (org.apache.flink.streaming.connectors.kinesis.metrics.ShardConsumerMetricsReporter)1 KinesisStreamShardState (org.apache.flink.streaming.connectors.kinesis.model.KinesisStreamShardState)1 SequenceNumber (org.apache.flink.streaming.connectors.kinesis.model.SequenceNumber)1 StartingPosition (org.apache.flink.streaming.connectors.kinesis.model.StartingPosition)1 KinesisProxyInterface (org.apache.flink.streaming.connectors.kinesis.proxy.KinesisProxyInterface)1 KinesisDeserializationSchemaWrapper (org.apache.flink.streaming.connectors.kinesis.serialization.KinesisDeserializationSchemaWrapper)1