Search in sources :

Example 1 with TestConsumer

use of org.apache.flink.streaming.connectors.kinesis.testutils.TestUtils.TestConsumer in project flink by apache.

the class PollingRecordPublisherTest method testRunOnCompletelyConsumedShardReturnsComplete.

@Test
public void testRunOnCompletelyConsumedShardReturnsComplete() throws Exception {
    KinesisProxyInterface fakeKinesis = totalNumOfRecordsAfterNumOfGetRecordsCalls(5, 1, 100);
    PollingRecordPublisher recordPublisher = createPollingRecordPublisher(fakeKinesis);
    assertEquals(COMPLETE, recordPublisher.run(new TestConsumer()));
    assertEquals(COMPLETE, recordPublisher.run(new TestConsumer()));
}
Also used : KinesisProxyInterface(org.apache.flink.streaming.connectors.kinesis.proxy.KinesisProxyInterface) TestConsumer(org.apache.flink.streaming.connectors.kinesis.testutils.TestUtils.TestConsumer) Test(org.junit.Test)

Example 2 with TestConsumer

use of org.apache.flink.streaming.connectors.kinesis.testutils.TestUtils.TestConsumer in project flink by apache.

the class PollingRecordPublisherTest method testRunReturnsCompleteWhenShardExpires.

@Test
public void testRunReturnsCompleteWhenShardExpires() throws Exception {
    // There are 2 batches available in the stream
    KinesisProxyInterface fakeKinesis = totalNumOfRecordsAfterNumOfGetRecordsCalls(5, 2, 100);
    PollingRecordPublisher recordPublisher = createPollingRecordPublisher(fakeKinesis);
    // First call results in INCOMPLETE, there is one batch left
    assertEquals(INCOMPLETE, recordPublisher.run(new TestConsumer()));
    // After second call the shard is complete
    assertEquals(COMPLETE, recordPublisher.run(new TestConsumer()));
}
Also used : KinesisProxyInterface(org.apache.flink.streaming.connectors.kinesis.proxy.KinesisProxyInterface) TestConsumer(org.apache.flink.streaming.connectors.kinesis.testutils.TestUtils.TestConsumer) Test(org.junit.Test)

Example 3 with TestConsumer

use of org.apache.flink.streaming.connectors.kinesis.testutils.TestUtils.TestConsumer in project flink by apache.

the class FanOutRecordPublisherTest method testSubscribeToShardIgnoresReadTimeoutInRetryPolicy.

@Test
public void testSubscribeToShardIgnoresReadTimeoutInRetryPolicy() throws Exception {
    Properties efoProperties = createEfoProperties();
    efoProperties.setProperty(SUBSCRIBE_TO_SHARD_RETRIES, String.valueOf(EXPECTED_SUBSCRIBE_TO_SHARD_RETRIES));
    FanOutRecordPublisherConfiguration configuration = new FanOutRecordPublisherConfiguration(efoProperties, emptyList());
    ReadTimeoutException retryableError = ReadTimeoutException.INSTANCE;
    FakeKinesisFanOutBehavioursFactory.SubscriptionErrorKinesisV2 kinesis = FakeKinesisFanOutBehavioursFactory.errorDuringSubscription(retryableError);
    FullJitterBackoff backoff = mock(FullJitterBackoff.class);
    FanOutRecordPublisher recordPublisher = new FanOutRecordPublisher(latest(), "arn", createDummyStreamShardHandle(), kinesis, configuration, backoff);
    int count = 0;
    while (recordPublisher.run(new TestConsumer()) == RecordPublisherRunResult.INCOMPLETE) {
        if (++count > EXPECTED_SUBSCRIBE_TO_SHARD_RETRIES) {
            break;
        }
    }
    // No exception is thrown, but we still backoff.
    verify(backoff, times(EXPECTED_SUBSCRIBE_TO_SHARD_RETRIES + 1)).calculateFullJitterBackoff(anyLong(), anyLong(), anyDouble(), anyInt());
}
Also used : ReadTimeoutException(io.netty.handler.timeout.ReadTimeoutException) FakeKinesisFanOutBehavioursFactory(org.apache.flink.streaming.connectors.kinesis.testutils.FakeKinesisFanOutBehavioursFactory) Properties(java.util.Properties) SubscriptionErrorKinesisV2(org.apache.flink.streaming.connectors.kinesis.testutils.FakeKinesisFanOutBehavioursFactory.SubscriptionErrorKinesisV2) FullJitterBackoff(org.apache.flink.streaming.connectors.kinesis.proxy.FullJitterBackoff) TestConsumer(org.apache.flink.streaming.connectors.kinesis.testutils.TestUtils.TestConsumer) Test(org.junit.Test)

Example 4 with TestConsumer

use of org.apache.flink.streaming.connectors.kinesis.testutils.TestUtils.TestConsumer in project flink by apache.

the class FanOutRecordPublisherTest method testToSdkV2StartingPositionTrimHorizon.

@Test
public void testToSdkV2StartingPositionTrimHorizon() throws Exception {
    SingleShardFanOutKinesisV2 kinesis = emptyShard();
    RecordPublisher publisher = createRecordPublisher(kinesis, StartingPosition.continueFromSequenceNumber(SENTINEL_EARLIEST_SEQUENCE_NUM.get()));
    publisher.run(new TestConsumer());
    assertNull(kinesis.getStartingPositionForSubscription(0).sequenceNumber());
    assertEquals(TRIM_HORIZON, 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 5 with TestConsumer

use of org.apache.flink.streaming.connectors.kinesis.testutils.TestUtils.TestConsumer in project flink by apache.

the class FanOutRecordPublisherTest method testInterruptedPublisherReturnsCancelled.

@Test
public void testInterruptedPublisherReturnsCancelled() throws Exception {
    KinesisProxyV2Interface kinesis = FakeKinesisFanOutBehavioursFactory.errorDuringSubscription(new SdkInterruptedException(null));
    RecordPublisher publisher = createRecordPublisher(kinesis, StartingPosition.continueFromSequenceNumber(SEQUENCE_NUMBER));
    RecordPublisherRunResult actual = publisher.run(new TestConsumer());
    assertEquals(CANCELLED, actual);
}
Also used : RecordPublisher(org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordPublisher) RecordPublisherRunResult(org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordPublisher.RecordPublisherRunResult) SdkInterruptedException(com.amazonaws.http.timers.client.SdkInterruptedException) KinesisProxyV2Interface(org.apache.flink.streaming.connectors.kinesis.proxy.KinesisProxyV2Interface) TestConsumer(org.apache.flink.streaming.connectors.kinesis.testutils.TestUtils.TestConsumer) Test(org.junit.Test)

Aggregations

TestConsumer (org.apache.flink.streaming.connectors.kinesis.testutils.TestUtils.TestConsumer)23 Test (org.junit.Test)23 RecordPublisher (org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordPublisher)12 SingleShardFanOutKinesisV2 (org.apache.flink.streaming.connectors.kinesis.testutils.FakeKinesisFanOutBehavioursFactory.SingleShardFanOutKinesisV2)7 SubscriptionErrorKinesisV2 (org.apache.flink.streaming.connectors.kinesis.testutils.FakeKinesisFanOutBehavioursFactory.SubscriptionErrorKinesisV2)7 KinesisProxyInterface (org.apache.flink.streaming.connectors.kinesis.proxy.KinesisProxyInterface)6 FullJitterBackoff (org.apache.flink.streaming.connectors.kinesis.proxy.FullJitterBackoff)5 LimitExceededException (software.amazon.awssdk.services.kinesis.model.LimitExceededException)4 UserRecord (com.amazonaws.services.kinesis.clientlibrary.types.UserRecord)3 KinesisProxyV2Interface (org.apache.flink.streaming.connectors.kinesis.proxy.KinesisProxyV2Interface)3 Date (java.util.Date)2 Properties (java.util.Properties)2 RecordPublisherRunResult (org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordPublisher.RecordPublisherRunResult)2 SdkInterruptedException (com.amazonaws.http.timers.client.SdkInterruptedException)1 ReadTimeoutException (io.netty.handler.timeout.ReadTimeoutException)1 PollingRecordPublisherMetricsReporter (org.apache.flink.streaming.connectors.kinesis.metrics.PollingRecordPublisherMetricsReporter)1 FakeKinesisFanOutBehavioursFactory (org.apache.flink.streaming.connectors.kinesis.testutils.FakeKinesisFanOutBehavioursFactory)1 Record (software.amazon.awssdk.services.kinesis.model.Record)1 ResourceNotFoundException (software.amazon.awssdk.services.kinesis.model.ResourceNotFoundException)1