Search in sources :

Example 6 with SingleShardFanOutKinesisV2

use of org.apache.flink.streaming.connectors.kinesis.testutils.FakeKinesisFanOutBehavioursFactory.SingleShardFanOutKinesisV2 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 7 with SingleShardFanOutKinesisV2

use of org.apache.flink.streaming.connectors.kinesis.testutils.FakeKinesisFanOutBehavioursFactory.SingleShardFanOutKinesisV2 in project flink by apache.

the class FanOutRecordPublisherTest method testExceptionThrownInConsumerPropagatesToRecordPublisher.

@Test
public void testExceptionThrownInConsumerPropagatesToRecordPublisher() throws Exception {
    thrown.expect(RuntimeException.class);
    thrown.expectMessage("An error thrown from the consumer");
    SingleShardFanOutKinesisV2 kinesis = FakeKinesisFanOutBehavioursFactory.boundedShard().build();
    RecordPublisher recordPublisher = createRecordPublisher(kinesis);
    recordPublisher.run(batch -> {
        throw new RuntimeException("An error thrown from the consumer");
    });
}
Also used : RecordPublisher(org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordPublisher) SingleShardFanOutKinesisV2(org.apache.flink.streaming.connectors.kinesis.testutils.FakeKinesisFanOutBehavioursFactory.SingleShardFanOutKinesisV2) Test(org.junit.Test)

Example 8 with SingleShardFanOutKinesisV2

use of org.apache.flink.streaming.connectors.kinesis.testutils.FakeKinesisFanOutBehavioursFactory.SingleShardFanOutKinesisV2 in project flink by apache.

the class ShardConsumerFanOutTest method testSubscribeToShardUsesCorrectStartingSequenceNumbers.

@Test
public void testSubscribeToShardUsesCorrectStartingSequenceNumbers() throws Exception {
    SingleShardFanOutKinesisV2 kinesis = FakeKinesisFanOutBehavioursFactory.boundedShard().withBatchCount(10).withRecordsPerBatch(1).withBatchesPerSubscription(2).build();
    // 10 batches of 1 records = 10
    assertNumberOfMessagesReceivedFromKinesis(10, kinesis, new SequenceNumber("0"));
    // 10 batches / 2 batches per subscription = 5 subscriptions
    assertEquals(5, kinesis.getNumberOfSubscribeToShardInvocations());
    // Starting positions should correlate to the last consumed sequence number
    assertStartingPositionAfterSequenceNumber(kinesis.getStartingPositionForSubscription(0), "0");
    assertStartingPositionAfterSequenceNumber(kinesis.getStartingPositionForSubscription(1), "2");
    assertStartingPositionAfterSequenceNumber(kinesis.getStartingPositionForSubscription(2), "4");
    assertStartingPositionAfterSequenceNumber(kinesis.getStartingPositionForSubscription(3), "6");
    assertStartingPositionAfterSequenceNumber(kinesis.getStartingPositionForSubscription(4), "8");
}
Also used : 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)

Example 9 with SingleShardFanOutKinesisV2

use of org.apache.flink.streaming.connectors.kinesis.testutils.FakeKinesisFanOutBehavioursFactory.SingleShardFanOutKinesisV2 in project flink by apache.

the class ShardConsumerFanOutTest method testMillisBehindReported.

@Test
public void testMillisBehindReported() throws Exception {
    SingleShardFanOutKinesisV2 kinesis = FakeKinesisFanOutBehavioursFactory.boundedShard().withMillisBehindLatest(123L).build();
    // Fake behaviour defaults to 10 messages
    ShardConsumerMetricsReporter metrics = assertNumberOfMessagesReceivedFromKinesis(10, kinesis, fakeSequenceNumber());
    assertEquals(123L, metrics.getMillisBehindLatest());
}
Also used : ShardConsumerMetricsReporter(org.apache.flink.streaming.connectors.kinesis.metrics.ShardConsumerMetricsReporter) AbstractSingleShardFanOutKinesisV2(org.apache.flink.streaming.connectors.kinesis.testutils.FakeKinesisFanOutBehavioursFactory.AbstractSingleShardFanOutKinesisV2) SingleShardFanOutKinesisV2(org.apache.flink.streaming.connectors.kinesis.testutils.FakeKinesisFanOutBehavioursFactory.SingleShardFanOutKinesisV2) Test(org.junit.Test)

Example 10 with SingleShardFanOutKinesisV2

use of org.apache.flink.streaming.connectors.kinesis.testutils.FakeKinesisFanOutBehavioursFactory.SingleShardFanOutKinesisV2 in project flink by apache.

the class ShardConsumerFanOutTest method testBoundedShardResubscribesToShard.

@Test
public void testBoundedShardResubscribesToShard() throws Exception {
    SingleShardFanOutKinesisV2 kinesis = FakeKinesisFanOutBehavioursFactory.boundedShard().withBatchCount(100).withRecordsPerBatch(10).withBatchesPerSubscription(5).build();
    // 100 batches of 10 records = 1000
    assertNumberOfMessagesReceivedFromKinesis(1000, kinesis, fakeSequenceNumber());
    // 100 batches / 5 batches per subscription = 20 subscriptions
    assertEquals(20, kinesis.getNumberOfSubscribeToShardInvocations());
    // Starting from non-aggregated sequence number means we should start AFTER the sequence
    // number
    assertEquals(AFTER_SEQUENCE_NUMBER, kinesis.getStartingPositionForSubscription(0).type());
}
Also used : 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

SingleShardFanOutKinesisV2 (org.apache.flink.streaming.connectors.kinesis.testutils.FakeKinesisFanOutBehavioursFactory.SingleShardFanOutKinesisV2)17 Test (org.junit.Test)17 AbstractSingleShardFanOutKinesisV2 (org.apache.flink.streaming.connectors.kinesis.testutils.FakeKinesisFanOutBehavioursFactory.AbstractSingleShardFanOutKinesisV2)9 RecordPublisher (org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordPublisher)8 TestConsumer (org.apache.flink.streaming.connectors.kinesis.testutils.TestUtils.TestConsumer)7 ShardConsumerTestUtils.fakeSequenceNumber (org.apache.flink.streaming.connectors.kinesis.internals.ShardConsumerTestUtils.fakeSequenceNumber)4 SequenceNumber (org.apache.flink.streaming.connectors.kinesis.model.SequenceNumber)4 UserRecord (com.amazonaws.services.kinesis.clientlibrary.types.UserRecord)2 Instant (java.time.Instant)2 StartingPosition (software.amazon.awssdk.services.kinesis.model.StartingPosition)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Properties (java.util.Properties)1 ShardConsumerMetricsReporter (org.apache.flink.streaming.connectors.kinesis.metrics.ShardConsumerMetricsReporter)1 TestUtils.efoProperties (org.apache.flink.streaming.connectors.kinesis.testutils.TestUtils.efoProperties)1