Adding guardrails test
This commit is contained in:
parent
dfed0e3b50
commit
fab2d416af
1 changed files with 13 additions and 7 deletions
|
|
@ -435,26 +435,32 @@ public class KinesisProxyTest {
|
|||
verify(mockClient).listShards(any());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testNoDuplicateShardsInPartialFailure() {
|
||||
proxy.setCachedShardMap(null);
|
||||
ListShardsResult firstPage = new ListShardsResult().withShards(shards.subList(0, 2)).withNextToken(NEXT_TOKEN);
|
||||
ListShardsResult lastPage = new ListShardsResult().withShards(shards.subList(2, shards.size())).withNextToken(null);
|
||||
|
||||
when(mockClient.listShards(any()))
|
||||
.thenReturn(firstPage)
|
||||
.thenThrow(new RuntimeException("Failed!"))
|
||||
.thenReturn(firstPage)
|
||||
.thenReturn(lastPage);
|
||||
when(mockClient.listShards(any())).thenReturn(firstPage).thenThrow(new RuntimeException("Failed!")) // First call
|
||||
.thenReturn(firstPage).thenReturn(lastPage); // second call
|
||||
|
||||
try {
|
||||
proxy.getShardList();
|
||||
} catch (Exception e) {
|
||||
// Do nothing
|
||||
}
|
||||
assertEquals(shards, proxy.getShardList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDuplicateShardResponseDedupedGracefully() {
|
||||
proxy.setCachedShardMap(null);
|
||||
ListShardsResult pageOfShards = new ListShardsResult().withShards(shards).withNextToken(null);
|
||||
when(mockClient.listShards(any())).thenReturn(pageOfShards);
|
||||
|
||||
proxy.getShardList();
|
||||
assertEquals(shards, proxy.getShardList());
|
||||
}
|
||||
|
||||
private void mockListShardsForSingleResponse(List<Shard> shards) {
|
||||
when(mockClient.listShards(any())).thenReturn(listShardsResult);
|
||||
when(listShardsResult.getShards()).thenReturn(shards);
|
||||
|
|
|
|||
Loading…
Reference in a new issue