Search in sources :

Example 11 with KinesisProxyV2Interface

use of org.apache.flink.streaming.connectors.kinesis.proxy.KinesisProxyV2Interface in project flink by apache.

the class FanOutShardSubscriberTest method testTimeoutEnqueuingEvent.

@Test
public void testTimeoutEnqueuingEvent() throws Exception {
    thrown.expect(FanOutShardSubscriber.RecoverableFanOutSubscriberException.class);
    thrown.expectMessage("Timed out enqueuing event SubscriptionNextEvent");
    KinesisProxyV2Interface kinesis = FakeKinesisFanOutBehavioursFactory.shardThatCreatesBackpressureOnQueue();
    FanOutShardSubscriber subscriber = new FanOutShardSubscriber("consumerArn", "shardId", kinesis, DEFAULT_SUBSCRIBE_TO_SHARD_TIMEOUT, Duration.ofMillis(100));
    StartingPosition startingPosition = StartingPosition.builder().build();
    subscriber.subscribeToShardAndConsumeRecords(startingPosition, event -> {
        try {
            Thread.sleep(120);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    });
}
Also used : StartingPosition(software.amazon.awssdk.services.kinesis.model.StartingPosition) KinesisProxyV2Interface(org.apache.flink.streaming.connectors.kinesis.proxy.KinesisProxyV2Interface) SdkInterruptedException(com.amazonaws.http.timers.client.SdkInterruptedException) Test(org.junit.Test)

Example 12 with KinesisProxyV2Interface

use of org.apache.flink.streaming.connectors.kinesis.proxy.KinesisProxyV2Interface in project flink by apache.

the class StreamConsumerRegistrarTest method testCloseClosesProxy.

@Test
public void testCloseClosesProxy() {
    KinesisProxyV2Interface kinesis = mock(KinesisProxyV2Interface.class);
    StreamConsumerRegistrar registrar = createRegistrar(kinesis, mock(FullJitterBackoff.class));
    registrar.close();
    verify(kinesis).close();
}
Also used : KinesisProxyV2Interface(org.apache.flink.streaming.connectors.kinesis.proxy.KinesisProxyV2Interface) FullJitterBackoff(org.apache.flink.streaming.connectors.kinesis.proxy.FullJitterBackoff) Test(org.junit.Test)

Example 13 with KinesisProxyV2Interface

use of org.apache.flink.streaming.connectors.kinesis.proxy.KinesisProxyV2Interface 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)

Example 14 with KinesisProxyV2Interface

use of org.apache.flink.streaming.connectors.kinesis.proxy.KinesisProxyV2Interface in project flink by apache.

the class StreamConsumerRegistrarTest method testRegisterStreamConsumerThatAlreadyExistsAndActive.

@Test
public void testRegisterStreamConsumerThatAlreadyExistsAndActive() throws Exception {
    FullJitterBackoff backoff = mock(FullJitterBackoff.class);
    KinesisProxyV2Interface kinesis = FakeKinesisFanOutBehavioursFactory.existingActiveConsumer();
    StreamConsumerRegistrar registrar = createRegistrar(kinesis, backoff);
    String result = registrar.registerStreamConsumer(STREAM, "name");
    verify(backoff, never()).sleep(anyLong());
    assertEquals(STREAM_CONSUMER_ARN_EXISTING, result);
}
Also used : KinesisProxyV2Interface(org.apache.flink.streaming.connectors.kinesis.proxy.KinesisProxyV2Interface) FullJitterBackoff(org.apache.flink.streaming.connectors.kinesis.proxy.FullJitterBackoff) Test(org.junit.Test)

Example 15 with KinesisProxyV2Interface

use of org.apache.flink.streaming.connectors.kinesis.proxy.KinesisProxyV2Interface in project flink by apache.

the class StreamConsumerRegistrarUtil method createStreamConsumerRegistrar.

private static StreamConsumerRegistrar createStreamConsumerRegistrar(final Properties configProps, final List<String> streams) {
    FullJitterBackoff backoff = new FullJitterBackoff();
    FanOutRecordPublisherConfiguration configuration = new FanOutRecordPublisherConfiguration(configProps, streams);
    KinesisProxyV2Interface kinesis = KinesisProxyV2Factory.createKinesisProxyV2(configProps);
    return new StreamConsumerRegistrar(kinesis, configuration, backoff);
}
Also used : FanOutRecordPublisherConfiguration(org.apache.flink.streaming.connectors.kinesis.internals.publisher.fanout.FanOutRecordPublisherConfiguration) StreamConsumerRegistrar(org.apache.flink.streaming.connectors.kinesis.internals.publisher.fanout.StreamConsumerRegistrar) KinesisProxyV2Interface(org.apache.flink.streaming.connectors.kinesis.proxy.KinesisProxyV2Interface) FullJitterBackoff(org.apache.flink.streaming.connectors.kinesis.proxy.FullJitterBackoff)

Aggregations

KinesisProxyV2Interface (org.apache.flink.streaming.connectors.kinesis.proxy.KinesisProxyV2Interface)15 Test (org.junit.Test)14 FullJitterBackoff (org.apache.flink.streaming.connectors.kinesis.proxy.FullJitterBackoff)6 SdkInterruptedException (com.amazonaws.http.timers.client.SdkInterruptedException)3 RecordPublisher (org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordPublisher)3 TestConsumer (org.apache.flink.streaming.connectors.kinesis.testutils.TestUtils.TestConsumer)3 Properties (java.util.Properties)2 SimpleStringSchema (org.apache.flink.api.common.serialization.SimpleStringSchema)2 ShardConsumerTestUtils.fakeSequenceNumber (org.apache.flink.streaming.connectors.kinesis.internals.ShardConsumerTestUtils.fakeSequenceNumber)2 SequenceNumber (org.apache.flink.streaming.connectors.kinesis.model.SequenceNumber)2 KinesisProxyInterface (org.apache.flink.streaming.connectors.kinesis.proxy.KinesisProxyInterface)2 TestableKinesisDataFetcher (org.apache.flink.streaming.connectors.kinesis.testutils.TestableKinesisDataFetcher)2 StartingPosition (software.amazon.awssdk.services.kinesis.model.StartingPosition)2 SdkClientException (com.amazonaws.SdkClientException)1 UserRecord (com.amazonaws.services.kinesis.clientlibrary.types.UserRecord)1 Date (java.util.Date)1 RecordPublisherRunResult (org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordPublisher.RecordPublisherRunResult)1 FanOutRecordPublisherConfiguration (org.apache.flink.streaming.connectors.kinesis.internals.publisher.fanout.FanOutRecordPublisherConfiguration)1 FanOutRecordPublisherFactory (org.apache.flink.streaming.connectors.kinesis.internals.publisher.fanout.FanOutRecordPublisherFactory)1 StreamConsumerRegistrar (org.apache.flink.streaming.connectors.kinesis.internals.publisher.fanout.StreamConsumerRegistrar)1