本文整理汇总了Java中com.amazonaws.services.kinesis.model.GetRecordsResult类的典型用法代码示例。如果您正苦于以下问题:Java GetRecordsResult类的具体用法?Java GetRecordsResult怎么用?Java GetRecordsResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GetRecordsResult类属于com.amazonaws.services.kinesis.model包,在下文中一共展示了GetRecordsResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: noSourceOffsets
import com.amazonaws.services.kinesis.model.GetRecordsResult; //导入依赖的package包/类
@Test
public void noSourceOffsets() throws InterruptedException {
when(this.kinesisClient.getShardIterator(any())).thenReturn(
new GetShardIteratorResult().withShardIterator("dfasdfsadfasdf")
);
this.task.start(settings);
GetRecordsResult recordsResult = new GetRecordsResult()
.withNextShardIterator("dsfargadsfasdfasda")
.withRecords(TestData.record())
.withMillisBehindLatest(0L);
when(this.kinesisClient.getRecords(any())).thenReturn(recordsResult);
List<SourceRecord> records = this.task.poll();
assertNotNull(records, "records should not be null.");
assertFalse(records.isEmpty(), "records should not be empty.");
verify(this.kinesisClient, atLeastOnce()).getShardIterator(any());
verify(this.kinesisClient, atLeastOnce()).getRecords(any());
}
示例2: noRecords
import com.amazonaws.services.kinesis.model.GetRecordsResult; //导入依赖的package包/类
@Test
public void noRecords() throws InterruptedException {
final String SEQUENCE_NUMBER = "asdfasdfddsa";
Map<String, Object> sourceOffset = ImmutableMap.of(RecordConverter.FIELD_SEQUENCE_NUMBER, SEQUENCE_NUMBER);
when(this.offsetStorageReader.offset(anyMap())).thenReturn(sourceOffset);
when(this.kinesisClient.getShardIterator(any())).thenReturn(
new GetShardIteratorResult().withShardIterator("dfasdfsadfasdf")
);
this.task.start(settings);
GetRecordsResult recordsResult = new GetRecordsResult()
.withNextShardIterator("dsfargadsfasdfasda")
.withRecords(Arrays.asList())
.withMillisBehindLatest(0L);
when(this.kinesisClient.getRecords(any())).thenReturn(recordsResult);
List<SourceRecord> records = this.task.poll();
assertNotNull(records, "records should not be null");
assertTrue(records.isEmpty(), "records should be empty.");
verify(this.task.time, atLeastOnce()).sleep(this.config.kinesisEmptyRecordsBackoffMs);
}
示例3: getRecords
import com.amazonaws.services.kinesis.model.GetRecordsResult; //导入依赖的package包/类
/**
* Gets records from Kinesis and deaggregates them if needed.
*
* @return list of deaggregated records
* @throws TransientKinesisException - in case of recoverable situation
*/
public GetKinesisRecordsResult getRecords(final String shardIterator, final String streamName,
final String shardId, final Integer limit)
throws
TransientKinesisException {
return wrapExceptions(new Callable<GetKinesisRecordsResult>() {
@Override
public GetKinesisRecordsResult call() throws Exception {
GetRecordsResult response = kinesis.getRecords(new GetRecordsRequest()
.withShardIterator(shardIterator)
.withLimit(limit));
return new GetKinesisRecordsResult(
UserRecord.deaggregate(response.getRecords()),
response.getNextShardIterator(),
response.getMillisBehindLatest(),
streamName, shardId);
}
});
}
示例4: getRecords
import com.amazonaws.services.kinesis.model.GetRecordsResult; //导入依赖的package包/类
/**
* Calls {@link KinesisProxyInterface#getRecords(String, int)}, while also handling unexpected
* AWS {@link ExpiredIteratorException}s to assure that we get results and don't just fail on
* such occasions. The returned shard iterator within the successful {@link GetRecordsResult} should
* be used for the next call to this method.
*
* <p>Note: it is important that this method is not called again before all the records from the last result have been
* fully collected with {@link ShardConsumer#deserializeRecordForCollectionAndUpdateState(UserRecord)}, otherwise
* {@link ShardConsumer#lastSequenceNum} may refer to a sub-record in the middle of an aggregated record, leading to
* incorrect shard iteration if the iterator had to be refreshed.
*
* @param shardItr shard iterator to use
* @param maxNumberOfRecords the maximum number of records to fetch for this getRecords attempt
* @return get records result
* @throws InterruptedException
*/
private GetRecordsResult getRecords(String shardItr, int maxNumberOfRecords) throws InterruptedException {
GetRecordsResult getRecordsResult = null;
while (getRecordsResult == null) {
try {
getRecordsResult = kinesis.getRecords(shardItr, maxNumberOfRecords);
// Update millis behind latest so it gets reported by the millisBehindLatest gauge
shardMetricsReporter.setMillisBehindLatest(getRecordsResult.getMillisBehindLatest());
} catch (ExpiredIteratorException eiEx) {
LOG.warn("Encountered an unexpected expired iterator {} for shard {};" +
" refreshing the iterator ...", shardItr, subscribedShard);
shardItr = kinesis.getShardIterator(subscribedShard, ShardIteratorType.AFTER_SEQUENCE_NUMBER.toString(), lastSequenceNum.getSequenceNumber());
// sleep for the fetch interval before the next getRecords attempt with the refreshed iterator
if (fetchIntervalMillis != 0) {
Thread.sleep(fetchIntervalMillis);
}
}
}
return getRecordsResult;
}
示例5: noShardsFoundForRequestedStreamsBehaviour
import com.amazonaws.services.kinesis.model.GetRecordsResult; //导入依赖的package包/类
public static KinesisProxyInterface noShardsFoundForRequestedStreamsBehaviour() {
return new KinesisProxyInterface() {
@Override
public GetShardListResult getShardList(Map<String, String> streamNamesWithLastSeenShardIds) {
return new GetShardListResult(); // not setting any retrieved shards for result
}
@Override
public String getShardIterator(StreamShardHandle shard, String shardIteratorType, Object startingMarker) {
return null;
}
@Override
public GetRecordsResult getRecords(String shardIterator, int maxRecordsToGet) {
return null;
}
};
}
示例6: getRecords
import com.amazonaws.services.kinesis.model.GetRecordsResult; //导入依赖的package包/类
@Override
public GetRecordsResult getRecords(String shardIterator, int maxRecordsToGet) {
if ((Integer.valueOf(shardIterator) == orderOfCallToExpire - 1) && !expiredOnceAlready) {
// we fake only once the expired iterator exception at the specified get records attempt order
expiredOnceAlready = true;
throw new ExpiredIteratorException("Artificial expired shard iterator");
} else if (expiredOnceAlready && !expiredIteratorRefreshed) {
// if we've thrown the expired iterator exception already, but the iterator was not refreshed,
// throw a hard exception to the test that is testing this Kinesis behaviour
throw new RuntimeException("expired shard iterator was not refreshed on the next getRecords() call");
} else {
// assuming that the maxRecordsToGet is always large enough
return new GetRecordsResult()
.withRecords(shardItrToRecordBatch.get(shardIterator))
.withMillisBehindLatest(millisBehindLatest)
.withNextShardIterator(
(Integer.valueOf(shardIterator) == totalNumOfGetRecordsCalls - 1)
? null : String.valueOf(Integer.valueOf(shardIterator) + 1)); // last next shard iterator is null
}
}
示例7: getRecords
import com.amazonaws.services.kinesis.model.GetRecordsResult; //导入依赖的package包/类
/**
* Calls {@link KinesisProxyInterface#getRecords(String, int)}, while also handling unexpected
* AWS {@link ExpiredIteratorException}s to assure that we get results and don't just fail on
* such occasions. The returned shard iterator within the successful {@link GetRecordsResult} should
* be used for the next call to this method.
*
* Note: it is important that this method is not called again before all the records from the last result have been
* fully collected with {@link ShardConsumer#deserializeRecordForCollectionAndUpdateState(UserRecord)}, otherwise
* {@link ShardConsumer#lastSequenceNum} may refer to a sub-record in the middle of an aggregated record, leading to
* incorrect shard iteration if the iterator had to be refreshed.
*
* @param shardItr shard iterator to use
* @param maxNumberOfRecords the maximum number of records to fetch for this getRecords attempt
* @return get records result
* @throws InterruptedException
*/
private GetRecordsResult getRecords(String shardItr, int maxNumberOfRecords) throws InterruptedException {
GetRecordsResult getRecordsResult = null;
while (getRecordsResult == null) {
try {
getRecordsResult = kinesis.getRecords(shardItr, maxNumberOfRecords);
} catch (ExpiredIteratorException eiEx) {
LOG.warn("Encountered an unexpected expired iterator {} for shard {};" +
" refreshing the iterator ...", shardItr, subscribedShard);
shardItr = kinesis.getShardIterator(subscribedShard, ShardIteratorType.AFTER_SEQUENCE_NUMBER.toString(), lastSequenceNum.getSequenceNumber());
// sleep for the fetch interval before the next getRecords attempt with the refreshed iterator
if (fetchIntervalMillis != 0) {
Thread.sleep(fetchIntervalMillis);
}
}
}
return getRecordsResult;
}
示例8: noShardsFoundForRequestedStreamsBehaviour
import com.amazonaws.services.kinesis.model.GetRecordsResult; //导入依赖的package包/类
public static KinesisProxyInterface noShardsFoundForRequestedStreamsBehaviour() {
return new KinesisProxyInterface() {
@Override
public GetShardListResult getShardList(Map<String, String> streamNamesWithLastSeenShardIds) {
return new GetShardListResult(); // not setting any retrieved shards for result
}
@Override
public String getShardIterator(KinesisStreamShard shard, String shardIteratorType, String startingSeqNum) {
return null;
}
@Override
public GetRecordsResult getRecords(String shardIterator, int maxRecordsToGet) {
return null;
}
};
}
示例9: getRecords
import com.amazonaws.services.kinesis.model.GetRecordsResult; //导入依赖的package包/类
@Override
public GetRecordsResult getRecords(String shardIterator, int maxRecordsToGet) {
if ((Integer.valueOf(shardIterator) == orderOfCallToExpire-1) && !expiredOnceAlready) {
// we fake only once the expired iterator exception at the specified get records attempt order
expiredOnceAlready = true;
throw new ExpiredIteratorException("Artificial expired shard iterator");
} else if (expiredOnceAlready && !expiredIteratorRefreshed) {
// if we've thrown the expired iterator exception already, but the iterator was not refreshed,
// throw a hard exception to the test that is testing this Kinesis behaviour
throw new RuntimeException("expired shard iterator was not refreshed on the next getRecords() call");
} else {
// assuming that the maxRecordsToGet is always large enough
return new GetRecordsResult()
.withRecords(shardItrToRecordBatch.get(shardIterator))
.withNextShardIterator(
(Integer.valueOf(shardIterator) == totalNumOfGetRecordsCalls - 1)
? null : String.valueOf(Integer.valueOf(shardIterator) + 1)); // last next shard iterator is null
}
}
示例10: poll
import com.amazonaws.services.kinesis.model.GetRecordsResult; //导入依赖的package包/类
@Override
protected int poll() throws Exception {
GetRecordsRequest req = new GetRecordsRequest()
.withShardIterator(getShardItertor())
.withLimit(getEndpoint().getMaxResultsPerRequest());
GetRecordsResult result = getClient().getRecords(req);
Queue<Exchange> exchanges = createExchanges(result.getRecords());
int processedExchangeCount = processBatch(CastUtils.cast(exchanges));
// May cache the last successful sequence number, and pass it to the
// getRecords request. That way, on the next poll, we start from where
// we left off, however, I don't know what happens to subsequent
// exchanges when an earlier echangee fails.
currentShardIterator = result.getNextShardIterator();
return processedExchangeCount;
}
示例11: setup
import com.amazonaws.services.kinesis.model.GetRecordsResult; //导入依赖的package包/类
@Before
public void setup() throws Exception {
KinesisEndpoint endpoint = new KinesisEndpoint(null, "streamName", component);
endpoint.setAmazonKinesisClient(kinesisClient);
endpoint.setIteratorType(ShardIteratorType.LATEST);
undertest = new KinesisConsumer(endpoint, processor);
when(kinesisClient.getRecords(any(GetRecordsRequest.class)))
.thenReturn(new GetRecordsResult()
.withNextShardIterator("nextShardIterator")
);
when(kinesisClient.describeStream(any(DescribeStreamRequest.class)))
.thenReturn(new DescribeStreamResult()
.withStreamDescription(new StreamDescription()
.withShards(new Shard().withShardId("shardId"))
)
);
when(kinesisClient.getShardIterator(any(GetShardIteratorRequest.class)))
.thenReturn(new GetShardIteratorResult()
.withShardIterator("shardIterator")
);
}
示例12: recordsAreSentToTheProcessor
import com.amazonaws.services.kinesis.model.GetRecordsResult; //导入依赖的package包/类
@Test
public void recordsAreSentToTheProcessor() throws Exception {
when(kinesisClient.getRecords(any(GetRecordsRequest.class)))
.thenReturn(new GetRecordsResult()
.withNextShardIterator("nextShardIterator")
.withRecords(new Record().withSequenceNumber("1"), new Record().withSequenceNumber("2"))
);
int messageCount = undertest.poll();
assertThat(messageCount, is(2));
final ArgumentCaptor<Exchange> exchangeCaptor = ArgumentCaptor.forClass(Exchange.class);
verify(processor, times(2)).process(exchangeCaptor.capture(), any(AsyncCallback.class));
assertThat(exchangeCaptor.getAllValues().get(0).getIn().getBody(Record.class).getSequenceNumber(), is("1"));
assertThat(exchangeCaptor.getAllValues().get(1).getIn().getBody(Record.class).getSequenceNumber(), is("2"));
}
示例13: exchangePropertiesAreSet
import com.amazonaws.services.kinesis.model.GetRecordsResult; //导入依赖的package包/类
@Test
public void exchangePropertiesAreSet() throws Exception {
String partitionKey = "partitionKey";
String sequenceNumber = "1";
when(kinesisClient.getRecords(any(GetRecordsRequest.class)))
.thenReturn(new GetRecordsResult()
.withNextShardIterator("nextShardIterator")
.withRecords(new Record()
.withSequenceNumber(sequenceNumber)
.withApproximateArrivalTimestamp(new Date(42))
.withPartitionKey(partitionKey)
)
);
undertest.poll();
final ArgumentCaptor<Exchange> exchangeCaptor = ArgumentCaptor.forClass(Exchange.class);
verify(processor).process(exchangeCaptor.capture(), any(AsyncCallback.class));
assertThat(exchangeCaptor.getValue().getIn().getHeader(KinesisConstants.APPROX_ARRIVAL_TIME, long.class), is(42L));
assertThat(exchangeCaptor.getValue().getIn().getHeader(KinesisConstants.PARTITION_KEY, String.class), is(partitionKey));
assertThat(exchangeCaptor.getValue().getIn().getHeader(KinesisConstants.SEQUENCE_NUMBER, String.class), is(sequenceNumber));
}
示例14: processNextIterator
import com.amazonaws.services.kinesis.model.GetRecordsResult; //导入依赖的package包/类
public String processNextIterator(String iterator)
{
GetRecordsRequest getRequest = new GetRecordsRequest();
getRequest.setLimit(1000);
getRequest.setShardIterator(iterator);
// call "get" operation and get everything in this shard range
GetRecordsResult getResponse = client.getRecords(getRequest);
iterator = getResponse.getNextShardIterator();
List<Record> records = getResponse.getRecords();
processResponseRecords(records);
return iterator;
}
示例15: getPreviewRecords
import com.amazonaws.services.kinesis.model.GetRecordsResult; //导入依赖的package包/类
public static List<com.amazonaws.services.kinesis.model.Record> getPreviewRecords(
ClientConfiguration awsClientConfig,
KinesisConfigBean conf,
int maxBatchSize,
GetShardIteratorRequest getShardIteratorRequest
) throws StageException {
AmazonKinesis kinesisClient = getKinesisClient(awsClientConfig, conf);
GetShardIteratorResult getShardIteratorResult = kinesisClient.getShardIterator(getShardIteratorRequest);
String shardIterator = getShardIteratorResult.getShardIterator();
GetRecordsRequest getRecordsRequest = new GetRecordsRequest();
getRecordsRequest.setShardIterator(shardIterator);
getRecordsRequest.setLimit(maxBatchSize);
GetRecordsResult getRecordsResult = kinesisClient.getRecords(getRecordsRequest);
return getRecordsResult.getRecords();
}