@Override public GetRecordsResult getResult() { return new GetRecordsResult().withMillisBehindLatest(null).withRecords(Collections.emptyList()) .withNextShardIterator(null); }
@Override public GetRecordsResult getRecords(GetRecordsRequest getRecordsRequest) { List<String> shardIteratorParts = Splitter.on(':').splitToList(getRecordsRequest.getShardIterator()); int shardId = parseInt(shardIteratorParts.get(0)); int startingRecord = parseInt(shardIteratorParts.get(1)); List<Record> shardData = shardedData.get(shardId); int toIndex = min(startingRecord + numberOfRecordsPerGet, shardData.size()); int fromIndex = min(startingRecord, toIndex); return new GetRecordsResult() .withRecords(shardData.subList(fromIndex, toIndex)) .withNextShardIterator(String.format("%s:%s", shardId, toIndex)) .withMillisBehindLatest(0L); }
@Test public void shouldReturnLimitedNumberOfRecords() throws Exception { final Integer limit = 100; doAnswer( (Answer<GetRecordsResult>) invocation -> { GetRecordsRequest request = (GetRecordsRequest) invocation.getArguments()[0]; List<Record> records = generateRecords(request.getLimit()); return new GetRecordsResult().withRecords(records).withMillisBehindLatest(1000L); }) .when(kinesis) .getRecords(any(GetRecordsRequest.class)); GetKinesisRecordsResult result = underTest.getRecords(SHARD_ITERATOR, STREAM, SHARD_1, limit); assertThat(result.getRecords().size()).isEqualTo(limit); }
.willReturn(new GetRecordsResult() .withNextShardIterator(null) .withRecords(new Record() .withPartitionKey("partition1") .withSequenceNumber("1")
.willReturn(new GetRecordsResult() .withNextShardIterator(shard1Iterator3) .withRecords(new Record() .withPartitionKey("partition1") .withSequenceNumber("1") .willReturn(new GetRecordsResult() .withNextShardIterator(shard1Iterator3) .withRecords(new Record() .withPartitionKey("partition1") .withSequenceNumber("2")