Search in sources :

Example 1 with FullJitterBackoff

use of org.apache.flink.streaming.connectors.kinesis.proxy.FullJitterBackoff 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 2 with FullJitterBackoff

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

the class StreamConsumerRegistrarTest method testRegisterStreamConsumerWaitsForConsumerToBecomeActive.

@Test
public void testRegisterStreamConsumerWaitsForConsumerToBecomeActive() throws Exception {
    FullJitterBackoff backoff = mock(FullJitterBackoff.class);
    StreamConsumerFakeKinesis kinesis = FakeKinesisFanOutBehavioursFactory.registerExistingConsumerAndWaitToBecomeActive();
    StreamConsumerRegistrar registrar = createRegistrar(kinesis, backoff);
    String result = registrar.registerStreamConsumer(STREAM, "name");
    // we backoff on each retry
    verify(backoff, times(NUMBER_OF_DESCRIBE_REQUESTS_TO_ACTIVATE - 1)).sleep(anyLong());
    assertEquals(STREAM_CONSUMER_ARN_EXISTING, result);
    // We will invoke describe stream until the stream consumer is activated
    assertEquals(NUMBER_OF_DESCRIBE_REQUESTS_TO_ACTIVATE, kinesis.getNumberOfDescribeStreamConsumerInvocations());
    for (int i = 1; i < NUMBER_OF_DESCRIBE_REQUESTS_TO_ACTIVATE; i++) {
        verify(backoff).calculateFullJitterBackoff(anyLong(), anyLong(), anyDouble(), eq(i));
    }
}
Also used : StreamConsumerFakeKinesis(org.apache.flink.streaming.connectors.kinesis.testutils.FakeKinesisFanOutBehavioursFactory.StreamConsumerFakeKinesis) FullJitterBackoff(org.apache.flink.streaming.connectors.kinesis.proxy.FullJitterBackoff) Test(org.junit.Test)

Example 3 with FullJitterBackoff

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

the class StreamConsumerRegistrarTest method testRegisterStreamConsumerRegistersNewStreamConsumer.

@Test
public void testRegisterStreamConsumerRegistersNewStreamConsumer() throws Exception {
    FullJitterBackoff backoff = mock(FullJitterBackoff.class);
    KinesisProxyV2Interface kinesis = FakeKinesisFanOutBehavioursFactory.streamConsumerNotFound();
    StreamConsumerRegistrar registrar = createRegistrar(kinesis, backoff);
    String result = registrar.registerStreamConsumer(STREAM, "name");
    assertEquals(STREAM_CONSUMER_ARN_NEW, 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 4 with FullJitterBackoff

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

the class StreamConsumerRegistrarTest method testDeregisterStreamConsumerArnNotFound.

@Test
public void testDeregisterStreamConsumerArnNotFound() throws Exception {
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage("Stream consumer ARN not found for stream: not-found");
    FullJitterBackoff backoff = mock(FullJitterBackoff.class);
    StreamConsumerFakeKinesis kinesis = FakeKinesisFanOutBehavioursFactory.streamConsumerNotFound();
    StreamConsumerRegistrar registrar = createRegistrar(kinesis, backoff);
    registrar.deregisterStreamConsumer("not-found");
}
Also used : StreamConsumerFakeKinesis(org.apache.flink.streaming.connectors.kinesis.testutils.FakeKinesisFanOutBehavioursFactory.StreamConsumerFakeKinesis) FullJitterBackoff(org.apache.flink.streaming.connectors.kinesis.proxy.FullJitterBackoff) Test(org.junit.Test)

Example 5 with FullJitterBackoff

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

the class StreamConsumerRegistrarTest method testRegistrationBackoff.

@Test
public void testRegistrationBackoff() throws Exception {
    FanOutRecordPublisherConfiguration configuration = createConfiguration();
    FullJitterBackoff backoff = mock(FullJitterBackoff.class);
    when(backoff.calculateFullJitterBackoff(anyLong(), anyLong(), anyDouble(), anyInt())).thenReturn(5L);
    StreamConsumerRegistrar registrar = new StreamConsumerRegistrar(mock(KinesisProxyV2Interface.class), configuration, backoff);
    registrar.registrationBackoff(configuration, backoff, 10);
    verify(backoff).sleep(5);
    verify(backoff).calculateFullJitterBackoff(EXPECTED_REGISTRATION_BASE, EXPECTED_REGISTRATION_MAX, EXPECTED_REGISTRATION_POW, 10);
}
Also used : KinesisProxyV2Interface(org.apache.flink.streaming.connectors.kinesis.proxy.KinesisProxyV2Interface) FullJitterBackoff(org.apache.flink.streaming.connectors.kinesis.proxy.FullJitterBackoff) Test(org.junit.Test)

Aggregations

FullJitterBackoff (org.apache.flink.streaming.connectors.kinesis.proxy.FullJitterBackoff)16 Test (org.junit.Test)14 KinesisProxyV2Interface (org.apache.flink.streaming.connectors.kinesis.proxy.KinesisProxyV2Interface)6 SubscriptionErrorKinesisV2 (org.apache.flink.streaming.connectors.kinesis.testutils.FakeKinesisFanOutBehavioursFactory.SubscriptionErrorKinesisV2)5 TestConsumer (org.apache.flink.streaming.connectors.kinesis.testutils.TestUtils.TestConsumer)5 StreamConsumerFakeKinesis (org.apache.flink.streaming.connectors.kinesis.testutils.FakeKinesisFanOutBehavioursFactory.StreamConsumerFakeKinesis)4 Properties (java.util.Properties)3 LimitExceededException (software.amazon.awssdk.services.kinesis.model.LimitExceededException)3 ReadTimeoutException (io.netty.handler.timeout.ReadTimeoutException)1 FanOutRecordPublisherConfiguration (org.apache.flink.streaming.connectors.kinesis.internals.publisher.fanout.FanOutRecordPublisherConfiguration)1 StreamConsumerRegistrar (org.apache.flink.streaming.connectors.kinesis.internals.publisher.fanout.StreamConsumerRegistrar)1 FakeKinesisFanOutBehavioursFactory (org.apache.flink.streaming.connectors.kinesis.testutils.FakeKinesisFanOutBehavioursFactory)1