public GetRecordsResult unmarshall(JsonUnmarshallerContext context) throws Exception { GetRecordsResult getRecordsResult = new GetRecordsResult();
public GetRecordsResult unmarshall(JsonUnmarshallerContext context) throws Exception { GetRecordsResult getRecordsResult = new GetRecordsResult(); AwsJsonReader reader = context.getReader(); reader.beginObject(); while (reader.hasNext()) { String name = reader.nextName(); if (name.equals("Records")) { getRecordsResult.setRecords(new ListUnmarshaller<Record>(RecordJsonUnmarshaller .getInstance() ) .unmarshall(context)); } else if (name.equals("NextShardIterator")) { getRecordsResult.setNextShardIterator(StringJsonUnmarshaller.getInstance() .unmarshall(context)); } else if (name.equals("MillisBehindLatest")) { getRecordsResult.setMillisBehindLatest(LongJsonUnmarshaller.getInstance() .unmarshall(context)); } else { reader.skipValue(); } } reader.endObject(); return getRecordsResult; }
@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); }
public GetRecordsResult unmarshall(JsonUnmarshallerContext context) throws Exception { GetRecordsResult getRecordsResult = new GetRecordsResult();
.withShardIterator(shard1Iterator1) .withLimit(25))) .willReturn(new GetRecordsResult() .withNextShardIterator(null) .withRecords(new Record()
.withShardIterator(shard1Iterator2) .withLimit(25))) .willReturn(new GetRecordsResult() .withNextShardIterator(shard1Iterator3) .withRecords(new Record() .withShardIterator(shard2Iterator1) .withLimit(25))) .willReturn(new GetRecordsResult() .withNextShardIterator(shard2Iterator1)); .withShardIterator(shard1Iterator3) .withLimit(25))) .willReturn(new GetRecordsResult() .withNextShardIterator(shard1Iterator3)); .withShardIterator(shard1Iterator4) .withLimit(25))) .willReturn(new GetRecordsResult() .withNextShardIterator(shard1Iterator3) .withRecords(new Record()