Search in sources :

Example 11 with KinesisStreamShardState

use of org.apache.flink.streaming.connectors.kinesis.model.KinesisStreamShardState in project flink by apache.

the class ShardConsumerTest method testCorrectNumOfCollectedRecordsAndUpdatedState.

@Test
public void testCorrectNumOfCollectedRecordsAndUpdatedState() {
    KinesisStreamShard fakeToBeConsumedShard = new KinesisStreamShard("fakeStream", new Shard().withShardId(KinesisShardIdGenerator.generateFromShardOrder(0)).withHashKeyRange(new HashKeyRange().withStartingHashKey("0").withEndingHashKey(new BigInteger(StringUtils.repeat("FF", 16), 16).toString())));
    LinkedList<KinesisStreamShardState> subscribedShardsStateUnderTest = new LinkedList<>();
    subscribedShardsStateUnderTest.add(new KinesisStreamShardState(fakeToBeConsumedShard, new SequenceNumber("fakeStartingState")));
    TestableKinesisDataFetcher fetcher = new TestableKinesisDataFetcher(Collections.singletonList("fakeStream"), new Properties(), 10, 2, new AtomicReference<Throwable>(), subscribedShardsStateUnderTest, KinesisDataFetcher.createInitialSubscribedStreamsToLastDiscoveredShardsState(Collections.singletonList("fakeStream")), Mockito.mock(KinesisProxyInterface.class));
    new ShardConsumer<>(fetcher, 0, subscribedShardsStateUnderTest.get(0).getKinesisStreamShard(), subscribedShardsStateUnderTest.get(0).getLastProcessedSequenceNum(), FakeKinesisBehavioursFactory.totalNumOfRecordsAfterNumOfGetRecordsCalls(1000, 9)).run();
    assertTrue(fetcher.getNumOfElementsCollected() == 1000);
    assertTrue(subscribedShardsStateUnderTest.get(0).getLastProcessedSequenceNum().equals(SentinelSequenceNumber.SENTINEL_SHARD_ENDING_SEQUENCE_NUM.get()));
}
Also used : KinesisStreamShard(org.apache.flink.streaming.connectors.kinesis.model.KinesisStreamShard) Properties(java.util.Properties) HashKeyRange(com.amazonaws.services.kinesis.model.HashKeyRange) LinkedList(java.util.LinkedList) SentinelSequenceNumber(org.apache.flink.streaming.connectors.kinesis.model.SentinelSequenceNumber) SequenceNumber(org.apache.flink.streaming.connectors.kinesis.model.SequenceNumber) BigInteger(java.math.BigInteger) KinesisStreamShardState(org.apache.flink.streaming.connectors.kinesis.model.KinesisStreamShardState) KinesisProxyInterface(org.apache.flink.streaming.connectors.kinesis.proxy.KinesisProxyInterface) Shard(com.amazonaws.services.kinesis.model.Shard) KinesisStreamShard(org.apache.flink.streaming.connectors.kinesis.model.KinesisStreamShard) TestableKinesisDataFetcher(org.apache.flink.streaming.connectors.kinesis.testutils.TestableKinesisDataFetcher) Test(org.junit.Test)

Aggregations

KinesisStreamShardState (org.apache.flink.streaming.connectors.kinesis.model.KinesisStreamShardState)11 Properties (java.util.Properties)9 KinesisStreamShard (org.apache.flink.streaming.connectors.kinesis.model.KinesisStreamShard)9 Test (org.junit.Test)9 HashMap (java.util.HashMap)8 LinkedList (java.util.LinkedList)8 Map (java.util.Map)8 SequenceNumber (org.apache.flink.streaming.connectors.kinesis.model.SequenceNumber)8 TestableKinesisDataFetcher (org.apache.flink.streaming.connectors.kinesis.testutils.TestableKinesisDataFetcher)8 Shard (com.amazonaws.services.kinesis.model.Shard)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 SentinelSequenceNumber (org.apache.flink.streaming.connectors.kinesis.model.SentinelSequenceNumber)3 HashKeyRange (com.amazonaws.services.kinesis.model.HashKeyRange)2 BigInteger (java.math.BigInteger)2 KinesisProxyInterface (org.apache.flink.streaming.connectors.kinesis.proxy.KinesisProxyInterface)2 IOException (java.io.IOException)1 Random (java.util.Random)1 Configuration (org.apache.flink.configuration.Configuration)1 Watermark (org.apache.flink.streaming.api.watermark.Watermark)1 InitialPosition (org.apache.flink.streaming.connectors.kinesis.config.ConsumerConfigConstants.InitialPosition)1