Search in sources :

Example 11 with TestConsumer

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

the class PollingRecordPublisherTest method testRunEmitsRunLoopTimeNanos.

@Test
public void testRunEmitsRunLoopTimeNanos() throws Exception {
    PollingRecordPublisherMetricsReporter metricsReporter = spy(new PollingRecordPublisherMetricsReporter(createFakeShardConsumerMetricGroup()));
    KinesisProxyInterface fakeKinesis = totalNumOfRecordsAfterNumOfGetRecordsCalls(5, 5, 100);
    PollingRecordPublisher recordPublisher = createPollingRecordPublisher(fakeKinesis, metricsReporter);
    recordPublisher.run(new TestConsumer());
    // Expect that the run loop took at least FETCH_INTERVAL_MILLIS in nanos
    verify(metricsReporter).setRunLoopTimeNanos(geq(FETCH_INTERVAL_MILLIS * 1_000_000));
}
Also used : KinesisProxyInterface(org.apache.flink.streaming.connectors.kinesis.proxy.KinesisProxyInterface) PollingRecordPublisherMetricsReporter(org.apache.flink.streaming.connectors.kinesis.metrics.PollingRecordPublisherMetricsReporter) TestConsumer(org.apache.flink.streaming.connectors.kinesis.testutils.TestUtils.TestConsumer) Test(org.junit.Test)

Example 12 with TestConsumer

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

the class FanOutRecordPublisherTest method testSubscribeToShardFailsWhenMaxRetriesExceeded.

@Test
public void testSubscribeToShardFailsWhenMaxRetriesExceeded() throws Exception {
    thrown.expect(RuntimeException.class);
    thrown.expectMessage("Maximum retries exceeded for SubscribeToShard. Failed 3 times.");
    Properties efoProperties = createEfoProperties();
    efoProperties.setProperty(SUBSCRIBE_TO_SHARD_RETRIES, String.valueOf(EXPECTED_SUBSCRIBE_TO_SHARD_RETRIES));
    FanOutRecordPublisherConfiguration configuration = new FanOutRecordPublisherConfiguration(efoProperties, emptyList());
    LimitExceededException retryableError = LimitExceededException.builder().build();
    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()) == INCOMPLETE) {
        if (++count > EXPECTED_SUBSCRIBE_TO_SHARD_RETRIES) {
            break;
        }
    }
}
Also used : LimitExceededException(software.amazon.awssdk.services.kinesis.model.LimitExceededException) 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 13 with TestConsumer

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

the class FanOutRecordPublisherTest method testAggregatedRecordDurability.

@Test
public void testAggregatedRecordDurability() throws Exception {
    SingleShardFanOutKinesisV2 kinesis = FakeKinesisFanOutBehavioursFactory.boundedShard().withBatchCount(10).withAggregationFactor(5).withRecordsPerBatch(12).build();
    RecordPublisher recordPublisher = createRecordPublisher(kinesis);
    TestConsumer consumer = new TestConsumer();
    int count = 0;
    while (recordPublisher.run(consumer) == INCOMPLETE) {
        if (++count > 5) {
            break;
        }
    }
    List<UserRecord> userRecords = flattenToUserRecords(consumer.getRecordBatches());
    // Should have received 10 * 12 * 5 = 600 records
    assertEquals(600, userRecords.size());
    int sequence = 1;
    long subsequence = 0;
    for (UserRecord userRecord : userRecords) {
        assertEquals(String.valueOf(sequence), userRecord.getSequenceNumber());
        assertEquals(subsequence++, userRecord.getSubSequenceNumber());
        if (subsequence == 5) {
            sequence++;
            subsequence = 0;
        }
    }
}
Also used : RecordPublisher(org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordPublisher) UserRecord(com.amazonaws.services.kinesis.clientlibrary.types.UserRecord) 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 14 with TestConsumer

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

the class FanOutRecordPublisherTest method testRecordDurability.

@Test
public void testRecordDurability() throws Exception {
    SingleShardFanOutKinesisV2 kinesis = FakeKinesisFanOutBehavioursFactory.boundedShard().withBatchCount(10).withBatchesPerSubscription(3).withRecordsPerBatch(12).build();
    RecordPublisher recordPublisher = createRecordPublisher(kinesis);
    TestConsumer consumer = new TestConsumer();
    int count = 0;
    while (recordPublisher.run(consumer) == INCOMPLETE) {
        if (++count > 4) {
            break;
        }
    }
    List<UserRecord> userRecords = flattenToUserRecords(consumer.getRecordBatches());
    // Should have received 10 * 12 = 120 records
    assertEquals(120, userRecords.size());
    int expectedSequenceNumber = 1;
    for (UserRecord record : userRecords) {
        assertEquals(String.valueOf(expectedSequenceNumber++), record.getSequenceNumber());
    }
}
Also used : RecordPublisher(org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordPublisher) UserRecord(com.amazonaws.services.kinesis.clientlibrary.types.UserRecord) 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 TestConsumer

use of org.apache.flink.streaming.connectors.kinesis.testutils.TestUtils.TestConsumer 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)

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