Adding guardrails test

This commit is contained in:
Joshua Kim 2021-04-29 17:12:47 -07:00
parent dfed0e3b50
commit fab2d416af

View file

@ -435,26 +435,32 @@ public class KinesisProxyTest {
verify(mockClient).listShards(any()); verify(mockClient).listShards(any());
} }
@Test @Test
public void testNoDuplicateShardsInPartialFailure() { public void testNoDuplicateShardsInPartialFailure() {
proxy.setCachedShardMap(null); proxy.setCachedShardMap(null);
ListShardsResult firstPage = new ListShardsResult().withShards(shards.subList(0, 2)).withNextToken(NEXT_TOKEN); ListShardsResult firstPage = new ListShardsResult().withShards(shards.subList(0, 2)).withNextToken(NEXT_TOKEN);
ListShardsResult lastPage = new ListShardsResult().withShards(shards.subList(2, shards.size())).withNextToken(null); ListShardsResult lastPage = new ListShardsResult().withShards(shards.subList(2, shards.size())).withNextToken(null);
when(mockClient.listShards(any())).thenReturn(firstPage).thenThrow(new RuntimeException("Failed!")) // First call
when(mockClient.listShards(any())) .thenReturn(firstPage).thenReturn(lastPage); // second call
.thenReturn(firstPage)
.thenThrow(new RuntimeException("Failed!"))
.thenReturn(firstPage)
.thenReturn(lastPage);
try { try {
proxy.getShardList(); proxy.getShardList();
} catch (Exception e) { } catch (Exception e) {
// Do nothing
} }
assertEquals(shards, proxy.getShardList()); 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) { private void mockListShardsForSingleResponse(List<Shard> shards) {
when(mockClient.listShards(any())).thenReturn(listShardsResult); when(mockClient.listShards(any())).thenReturn(listShardsResult);
when(listShardsResult.getShards()).thenReturn(shards); when(listShardsResult.getShards()).thenReturn(shards);