Search in sources :

Example 1 with StartingPosition

use of software.amazon.awssdk.services.kinesis.model.StartingPosition in project flink by apache.

the class FanOutShardSubscriberTest method testInterruptedErrorThrownToConsumer.

@Test
public void testInterruptedErrorThrownToConsumer() throws Exception {
    thrown.expect(FanOutShardSubscriber.FanOutSubscriberInterruptedException.class);
    SdkInterruptedException error = new SdkInterruptedException(null);
    SubscriptionErrorKinesisV2 errorKinesisV2 = FakeKinesisFanOutBehavioursFactory.errorDuringSubscription(error);
    FanOutShardSubscriber subscriber = new FanOutShardSubscriber("consumerArn", "shardId", errorKinesisV2, DEFAULT_SUBSCRIBE_TO_SHARD_TIMEOUT);
    software.amazon.awssdk.services.kinesis.model.StartingPosition startingPosition = software.amazon.awssdk.services.kinesis.model.StartingPosition.builder().build();
    subscriber.subscribeToShardAndConsumeRecords(startingPosition, event -> {
    });
}
Also used : SdkInterruptedException(com.amazonaws.http.timers.client.SdkInterruptedException) StartingPosition(software.amazon.awssdk.services.kinesis.model.StartingPosition) SubscriptionErrorKinesisV2(org.apache.flink.streaming.connectors.kinesis.testutils.FakeKinesisFanOutBehavioursFactory.SubscriptionErrorKinesisV2) Test(org.junit.Test)

Example 2 with StartingPosition

use of software.amazon.awssdk.services.kinesis.model.StartingPosition in project flink by apache.

the class FanOutShardSubscriberTest method testRetryableErrorThrownToConsumer.

@Test
public void testRetryableErrorThrownToConsumer() throws Exception {
    thrown.expect(FanOutShardSubscriber.RetryableFanOutSubscriberException.class);
    thrown.expectMessage("Error!");
    RuntimeException error = new RuntimeException("Error!");
    SubscriptionErrorKinesisV2 errorKinesisV2 = FakeKinesisFanOutBehavioursFactory.errorDuringSubscription(error);
    FanOutShardSubscriber subscriber = new FanOutShardSubscriber("consumerArn", "shardId", errorKinesisV2, DEFAULT_SUBSCRIBE_TO_SHARD_TIMEOUT);
    software.amazon.awssdk.services.kinesis.model.StartingPosition startingPosition = software.amazon.awssdk.services.kinesis.model.StartingPosition.builder().build();
    subscriber.subscribeToShardAndConsumeRecords(startingPosition, event -> {
    });
}
Also used : StartingPosition(software.amazon.awssdk.services.kinesis.model.StartingPosition) SubscriptionErrorKinesisV2(org.apache.flink.streaming.connectors.kinesis.testutils.FakeKinesisFanOutBehavioursFactory.SubscriptionErrorKinesisV2) Test(org.junit.Test)

Example 3 with StartingPosition

use of software.amazon.awssdk.services.kinesis.model.StartingPosition in project flink by apache.

the class FanOutShardSubscriberTest method testRecoverableErrorThrownToConsumer.

@Test
public void testRecoverableErrorThrownToConsumer() throws Exception {
    thrown.expect(FanOutShardSubscriber.RecoverableFanOutSubscriberException.class);
    thrown.expectMessage("io.netty.handler.timeout.ReadTimeoutException");
    SubscriptionErrorKinesisV2 errorKinesisV2 = FakeKinesisFanOutBehavioursFactory.errorDuringSubscription(ReadTimeoutException.INSTANCE);
    FanOutShardSubscriber subscriber = new FanOutShardSubscriber("consumerArn", "shardId", errorKinesisV2, DEFAULT_SUBSCRIBE_TO_SHARD_TIMEOUT);
    software.amazon.awssdk.services.kinesis.model.StartingPosition startingPosition = software.amazon.awssdk.services.kinesis.model.StartingPosition.builder().build();
    subscriber.subscribeToShardAndConsumeRecords(startingPosition, event -> {
    });
}
Also used : StartingPosition(software.amazon.awssdk.services.kinesis.model.StartingPosition) SubscriptionErrorKinesisV2(org.apache.flink.streaming.connectors.kinesis.testutils.FakeKinesisFanOutBehavioursFactory.SubscriptionErrorKinesisV2) Test(org.junit.Test)

Example 4 with StartingPosition

use of software.amazon.awssdk.services.kinesis.model.StartingPosition in project flink by apache.

the class ShardConsumerFanOutTest method testBoundedShardConsumesFromTimestamp.

@Test
public void testBoundedShardConsumesFromTimestamp() throws Exception {
    String format = "yyyy-MM-dd'T'HH:mm";
    String timestamp = "2020-07-02T09:14";
    Instant expectedTimestamp = new SimpleDateFormat(format).parse(timestamp).toInstant();
    SingleShardFanOutKinesisV2 kinesis = FakeKinesisFanOutBehavioursFactory.boundedShard().build();
    Properties consumerConfig = efoProperties();
    consumerConfig.setProperty(STREAM_INITIAL_TIMESTAMP, timestamp);
    consumerConfig.setProperty(STREAM_TIMESTAMP_DATE_FORMAT, format);
    SequenceNumber sequenceNumber = SENTINEL_AT_TIMESTAMP_SEQUENCE_NUM.get();
    // Fake behaviour defaults to 10 messages
    assertNumberOfMessagesReceivedFromKinesis(10, kinesis, sequenceNumber, consumerConfig);
    StartingPosition actual = kinesis.getStartingPositionForSubscription(0);
    assertEquals(AT_TIMESTAMP, actual.type());
    assertEquals(expectedTimestamp, actual.timestamp());
}
Also used : StartingPosition(software.amazon.awssdk.services.kinesis.model.StartingPosition) Instant(java.time.Instant) ShardConsumerTestUtils.fakeSequenceNumber(org.apache.flink.streaming.connectors.kinesis.internals.ShardConsumerTestUtils.fakeSequenceNumber) SequenceNumber(org.apache.flink.streaming.connectors.kinesis.model.SequenceNumber) AbstractSingleShardFanOutKinesisV2(org.apache.flink.streaming.connectors.kinesis.testutils.FakeKinesisFanOutBehavioursFactory.AbstractSingleShardFanOutKinesisV2) SingleShardFanOutKinesisV2(org.apache.flink.streaming.connectors.kinesis.testutils.FakeKinesisFanOutBehavioursFactory.SingleShardFanOutKinesisV2) TestUtils.efoProperties(org.apache.flink.streaming.connectors.kinesis.testutils.TestUtils.efoProperties) Properties(java.util.Properties) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 5 with StartingPosition

use of software.amazon.awssdk.services.kinesis.model.StartingPosition in project flink by apache.

the class ShardConsumerFanOutTest method testStartFromLatestIsTranslatedToTimestamp.

@Test
public void testStartFromLatestIsTranslatedToTimestamp() throws Exception {
    Instant now = Instant.now();
    SingleShardFanOutKinesisV2 kinesis = FakeKinesisFanOutBehavioursFactory.boundedShard().build();
    SequenceNumber sequenceNumber = SENTINEL_LATEST_SEQUENCE_NUM.get();
    // Fake behaviour defaults to 10 messages
    assertNumberOfMessagesReceivedFromKinesis(10, kinesis, sequenceNumber, efoProperties());
    StartingPosition actual = kinesis.getStartingPositionForSubscription(0);
    assertEquals(AT_TIMESTAMP, actual.type());
    // Considering milliseconds to make now have the same precision as actual
    assertTrue(now.toEpochMilli() <= actual.timestamp().toEpochMilli());
}
Also used : StartingPosition(software.amazon.awssdk.services.kinesis.model.StartingPosition) Instant(java.time.Instant) ShardConsumerTestUtils.fakeSequenceNumber(org.apache.flink.streaming.connectors.kinesis.internals.ShardConsumerTestUtils.fakeSequenceNumber) SequenceNumber(org.apache.flink.streaming.connectors.kinesis.model.SequenceNumber) AbstractSingleShardFanOutKinesisV2(org.apache.flink.streaming.connectors.kinesis.testutils.FakeKinesisFanOutBehavioursFactory.AbstractSingleShardFanOutKinesisV2) SingleShardFanOutKinesisV2(org.apache.flink.streaming.connectors.kinesis.testutils.FakeKinesisFanOutBehavioursFactory.SingleShardFanOutKinesisV2) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 StartingPosition (software.amazon.awssdk.services.kinesis.model.StartingPosition)8 SubscriptionErrorKinesisV2 (org.apache.flink.streaming.connectors.kinesis.testutils.FakeKinesisFanOutBehavioursFactory.SubscriptionErrorKinesisV2)4 SdkInterruptedException (com.amazonaws.http.timers.client.SdkInterruptedException)2 Instant (java.time.Instant)2 ShardConsumerTestUtils.fakeSequenceNumber (org.apache.flink.streaming.connectors.kinesis.internals.ShardConsumerTestUtils.fakeSequenceNumber)2 SequenceNumber (org.apache.flink.streaming.connectors.kinesis.model.SequenceNumber)2 KinesisProxyV2Interface (org.apache.flink.streaming.connectors.kinesis.proxy.KinesisProxyV2Interface)2 AbstractSingleShardFanOutKinesisV2 (org.apache.flink.streaming.connectors.kinesis.testutils.FakeKinesisFanOutBehavioursFactory.AbstractSingleShardFanOutKinesisV2)2 SingleShardFanOutKinesisV2 (org.apache.flink.streaming.connectors.kinesis.testutils.FakeKinesisFanOutBehavioursFactory.SingleShardFanOutKinesisV2)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Properties (java.util.Properties)1 TestUtils.efoProperties (org.apache.flink.streaming.connectors.kinesis.testutils.TestUtils.efoProperties)1