Java Code Examples for com.amazonaws.services.kinesis.model.ListShardsResult#withShards()
The following examples show how to use
com.amazonaws.services.kinesis.model.ListShardsResult#withShards() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KinesisProxyTest.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Test public void testGetShardListRetry() throws Exception { Properties kinesisConsumerConfig = new Properties(); kinesisConsumerConfig.setProperty(ConsumerConfigConstants.AWS_REGION, "us-east-1"); Shard shard = new Shard(); shard.setShardId("fake-shard-000000000000"); final ListShardsResult expectedResult = new ListShardsResult(); expectedResult.withShards(shard); MutableInt exceptionCount = new MutableInt(); final Throwable[] retriableExceptions = new Throwable[]{ new AmazonKinesisException("attempt1"), new AmazonKinesisException("attempt2"), }; AmazonKinesisClient mockClient = mock(AmazonKinesisClient.class); Mockito.when(mockClient.listShards(any())).thenAnswer(new Answer<ListShardsResult>() { @Override public ListShardsResult answer(InvocationOnMock invocation) throws Throwable { if (exceptionCount.intValue() < retriableExceptions.length) { exceptionCount.increment(); throw retriableExceptions[exceptionCount.intValue() - 1]; } return expectedResult; } }); KinesisProxy kinesisProxy = new KinesisProxy(kinesisConsumerConfig); Whitebox.getField(KinesisProxy.class, "kinesisClient").set(kinesisProxy, mockClient); HashMap<String, String> streamNames = new HashMap(); streamNames.put("fake-stream", null); GetShardListResult result = kinesisProxy.getShardList(streamNames); assertEquals(retriableExceptions.length, exceptionCount.intValue()); assertEquals(true, result.hasRetrievedShards()); assertEquals(shard.getShardId(), result.getLastSeenShardOfStream("fake-stream").getShard().getShardId()); // test max attempt count exceeded int maxRetries = 1; exceptionCount.setValue(0); kinesisConsumerConfig.setProperty(ConsumerConfigConstants.LIST_SHARDS_RETRIES, String.valueOf(maxRetries)); kinesisProxy = new KinesisProxy(kinesisConsumerConfig); Whitebox.getField(KinesisProxy.class, "kinesisClient").set(kinesisProxy, mockClient); try { kinesisProxy.getShardList(streamNames); Assert.fail("exception expected"); } catch (SdkClientException ex) { assertEquals(retriableExceptions[maxRetries], ex); } assertEquals(maxRetries + 1, exceptionCount.intValue()); }
Example 2
Source File: KinesisProxyTest.java From flink with Apache License 2.0 | 4 votes |
@Test public void testGetShardListRetry() throws Exception { Properties kinesisConsumerConfig = new Properties(); kinesisConsumerConfig.setProperty(ConsumerConfigConstants.AWS_REGION, "us-east-1"); Shard shard = new Shard(); shard.setShardId("fake-shard-000000000000"); final ListShardsResult expectedResult = new ListShardsResult(); expectedResult.withShards(shard); MutableInt exceptionCount = new MutableInt(); final Throwable[] retriableExceptions = new Throwable[]{ new AmazonKinesisException("attempt1"), new AmazonKinesisException("attempt2"), }; AmazonKinesisClient mockClient = mock(AmazonKinesisClient.class); Mockito.when(mockClient.listShards(any())).thenAnswer(new Answer<ListShardsResult>() { @Override public ListShardsResult answer(InvocationOnMock invocation) throws Throwable { if (exceptionCount.intValue() < retriableExceptions.length) { exceptionCount.increment(); throw retriableExceptions[exceptionCount.intValue() - 1]; } return expectedResult; } }); KinesisProxy kinesisProxy = new KinesisProxy(kinesisConsumerConfig); Whitebox.getField(KinesisProxy.class, "kinesisClient").set(kinesisProxy, mockClient); HashMap<String, String> streamNames = new HashMap(); streamNames.put("fake-stream", null); GetShardListResult result = kinesisProxy.getShardList(streamNames); assertEquals(retriableExceptions.length, exceptionCount.intValue()); assertEquals(true, result.hasRetrievedShards()); assertEquals(shard.getShardId(), result.getLastSeenShardOfStream("fake-stream").getShard().getShardId()); // test max attempt count exceeded int maxRetries = 1; exceptionCount.setValue(0); kinesisConsumerConfig.setProperty(ConsumerConfigConstants.LIST_SHARDS_RETRIES, String.valueOf(maxRetries)); kinesisProxy = new KinesisProxy(kinesisConsumerConfig); Whitebox.getField(KinesisProxy.class, "kinesisClient").set(kinesisProxy, mockClient); try { kinesisProxy.getShardList(streamNames); Assert.fail("exception expected"); } catch (SdkClientException ex) { assertEquals(retriableExceptions[maxRetries], ex); } assertEquals(maxRetries + 1, exceptionCount.intValue()); }
Example 3
Source File: KinesisProxyTest.java From flink with Apache License 2.0 | 4 votes |
@Test public void testGetShardListRetry() throws Exception { Properties kinesisConsumerConfig = new Properties(); kinesisConsumerConfig.setProperty(ConsumerConfigConstants.AWS_REGION, "us-east-1"); Shard shard = new Shard(); shard.setShardId("fake-shard-000000000000"); final ListShardsResult expectedResult = new ListShardsResult(); expectedResult.withShards(shard); MutableInt exceptionCount = new MutableInt(); final Throwable[] retriableExceptions = new Throwable[]{ new AmazonKinesisException("attempt1"), new AmazonKinesisException("attempt2"), }; AmazonKinesisClient mockClient = mock(AmazonKinesisClient.class); Mockito.when(mockClient.listShards(any())).thenAnswer(new Answer<ListShardsResult>() { @Override public ListShardsResult answer(InvocationOnMock invocation) throws Throwable { if (exceptionCount.intValue() < retriableExceptions.length) { exceptionCount.increment(); throw retriableExceptions[exceptionCount.intValue() - 1]; } return expectedResult; } }); KinesisProxy kinesisProxy = new KinesisProxy(kinesisConsumerConfig); Whitebox.getField(KinesisProxy.class, "kinesisClient").set(kinesisProxy, mockClient); HashMap<String, String> streamNames = new HashMap(); streamNames.put("fake-stream", null); GetShardListResult result = kinesisProxy.getShardList(streamNames); assertEquals(retriableExceptions.length, exceptionCount.intValue()); assertEquals(true, result.hasRetrievedShards()); assertEquals(shard.getShardId(), result.getLastSeenShardOfStream("fake-stream").getShard().getShardId()); // test max attempt count exceeded int maxRetries = 1; exceptionCount.setValue(0); kinesisConsumerConfig.setProperty(ConsumerConfigConstants.LIST_SHARDS_RETRIES, String.valueOf(maxRetries)); kinesisProxy = new KinesisProxy(kinesisConsumerConfig); Whitebox.getField(KinesisProxy.class, "kinesisClient").set(kinesisProxy, mockClient); try { kinesisProxy.getShardList(streamNames); Assert.fail("exception expected"); } catch (SdkClientException ex) { assertEquals(retriableExceptions[maxRetries], ex); } assertEquals(maxRetries + 1, exceptionCount.intValue()); }