com.amazonaws.services.kinesis.model.AmazonKinesisException Java Examples

The following examples show how to use com.amazonaws.services.kinesis.model.AmazonKinesisException. 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 5 votes vote down vote up
@Test
public void testGetRecordsRetry() throws Exception {
	Properties kinesisConsumerConfig = new Properties();
	kinesisConsumerConfig.setProperty(ConsumerConfigConstants.AWS_REGION, "us-east-1");

	final GetRecordsResult expectedResult = new GetRecordsResult();
	MutableInt retries = new MutableInt();
	final Throwable[] retriableExceptions = new Throwable[] {
		new AmazonKinesisException("mock"),
	};

	AmazonKinesisClient mockClient = mock(AmazonKinesisClient.class);
	Mockito.when(mockClient.getRecords(any())).thenAnswer(new Answer<GetRecordsResult>() {
		@Override
		public GetRecordsResult answer(InvocationOnMock invocation) throws Throwable{
			if (retries.intValue() < retriableExceptions.length) {
				retries.increment();
				throw retriableExceptions[retries.intValue() - 1];
			}
			return expectedResult;
		}
	});

	KinesisProxy kinesisProxy = new KinesisProxy(kinesisConsumerConfig);
	Whitebox.getField(KinesisProxy.class, "kinesisClient").set(kinesisProxy, mockClient);

	GetRecordsResult result = kinesisProxy.getRecords("fakeShardIterator", 1);
	assertEquals(retriableExceptions.length, retries.intValue());
	assertEquals(expectedResult, result);
}
 
Example #2
Source File: KinesisProxyTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetRecordsRetry() throws Exception {
	Properties kinesisConsumerConfig = new Properties();
	kinesisConsumerConfig.setProperty(ConsumerConfigConstants.AWS_REGION, "us-east-1");

	final GetRecordsResult expectedResult = new GetRecordsResult();
	MutableInt retries = new MutableInt();
	final Throwable[] retriableExceptions = new Throwable[] {
		new AmazonKinesisException("mock"),
	};

	AmazonKinesisClient mockClient = mock(AmazonKinesisClient.class);
	Mockito.when(mockClient.getRecords(any())).thenAnswer(new Answer<GetRecordsResult>() {
		@Override
		public GetRecordsResult answer(InvocationOnMock invocation) throws Throwable{
			if (retries.intValue() < retriableExceptions.length) {
				retries.increment();
				throw retriableExceptions[retries.intValue() - 1];
			}
			return expectedResult;
		}
	});

	KinesisProxy kinesisProxy = new KinesisProxy(kinesisConsumerConfig);
	Whitebox.getField(KinesisProxy.class, "kinesisClient").set(kinesisProxy, mockClient);

	GetRecordsResult result = kinesisProxy.getRecords("fakeShardIterator", 1);
	assertEquals(retriableExceptions.length, retries.intValue());
	assertEquals(expectedResult, result);
}
 
Example #3
Source File: KinesisProxyTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetRecordsRetry() throws Exception {
	Properties kinesisConsumerConfig = new Properties();
	kinesisConsumerConfig.setProperty(ConsumerConfigConstants.AWS_REGION, "us-east-1");

	final GetRecordsResult expectedResult = new GetRecordsResult();
	MutableInt retries = new MutableInt();
	final Throwable[] retriableExceptions = new Throwable[] {
		new AmazonKinesisException("mock"),
	};

	AmazonKinesisClient mockClient = mock(AmazonKinesisClient.class);
	Mockito.when(mockClient.getRecords(any())).thenAnswer(new Answer<GetRecordsResult>() {
		@Override
		public GetRecordsResult answer(InvocationOnMock invocation) throws Throwable{
			if (retries.intValue() < retriableExceptions.length) {
				retries.increment();
				throw retriableExceptions[retries.intValue() - 1];
			}
			return expectedResult;
		}
	});

	KinesisProxy kinesisProxy = new KinesisProxy(kinesisConsumerConfig);
	Whitebox.getField(KinesisProxy.class, "kinesisClient").set(kinesisProxy, mockClient);

	GetRecordsResult result = kinesisProxy.getRecords("fakeShardIterator", 1);
	assertEquals(retriableExceptions.length, retries.intValue());
	assertEquals(expectedResult, result);
}
 
Example #4
Source File: KinesisProxyTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@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 #5
Source File: KinesisProxyTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@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 #6
Source File: KinesisProxyTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@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());
}