Search in sources :

Example 11 with GetShardIteratorResult

use of com.amazonaws.services.kinesis.model.GetShardIteratorResult in project kafka-connect-kinesis by jcustenborder.

the class KinesisSourceTaskTest method noSourceOffsets.

@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());
}
Also used : GetRecordsResult(com.amazonaws.services.kinesis.model.GetRecordsResult) GetShardIteratorResult(com.amazonaws.services.kinesis.model.GetShardIteratorResult) SourceRecord(org.apache.kafka.connect.source.SourceRecord) Test(org.junit.jupiter.api.Test)

Example 12 with GetShardIteratorResult

use of com.amazonaws.services.kinesis.model.GetShardIteratorResult in project kafka-connect-kinesis by jcustenborder.

the class KinesisSourceTaskTest method throughputExceeded.

@Test
public void throughputExceeded() 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);
    when(this.kinesisClient.getRecords(any())).thenThrow(new ProvisionedThroughputExceededException(""));
    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.kinesisThroughputExceededBackoffMs);
}
Also used : GetShardIteratorResult(com.amazonaws.services.kinesis.model.GetShardIteratorResult) ProvisionedThroughputExceededException(com.amazonaws.services.kinesis.model.ProvisionedThroughputExceededException) SourceRecord(org.apache.kafka.connect.source.SourceRecord) Test(org.junit.jupiter.api.Test)

Example 13 with GetShardIteratorResult

use of com.amazonaws.services.kinesis.model.GetShardIteratorResult in project kafka-connect-kinesis by jcustenborder.

the class KinesisSourceTaskTest method noRecords.

@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);
}
Also used : GetRecordsResult(com.amazonaws.services.kinesis.model.GetRecordsResult) GetShardIteratorResult(com.amazonaws.services.kinesis.model.GetShardIteratorResult) SourceRecord(org.apache.kafka.connect.source.SourceRecord) Test(org.junit.jupiter.api.Test)

Example 14 with GetShardIteratorResult

use of com.amazonaws.services.kinesis.model.GetShardIteratorResult in project beam by apache.

the class SimplifiedKinesisClientTest method shouldReturnIteratorStartingWithSequenceNumber.

@Test
public void shouldReturnIteratorStartingWithSequenceNumber() throws Exception {
    when(kinesis.getShardIterator(new GetShardIteratorRequest().withStreamName(STREAM).withShardId(SHARD_1).withShardIteratorType(ShardIteratorType.AT_SEQUENCE_NUMBER).withStartingSequenceNumber(SEQUENCE_NUMBER))).thenReturn(new GetShardIteratorResult().withShardIterator(SHARD_ITERATOR));
    String stream = underTest.getShardIterator(STREAM, SHARD_1, ShardIteratorType.AT_SEQUENCE_NUMBER, SEQUENCE_NUMBER, null);
    assertThat(stream).isEqualTo(SHARD_ITERATOR);
}
Also used : GetShardIteratorRequest(com.amazonaws.services.kinesis.model.GetShardIteratorRequest) GetShardIteratorResult(com.amazonaws.services.kinesis.model.GetShardIteratorResult) Test(org.junit.Test)

Example 15 with GetShardIteratorResult

use of com.amazonaws.services.kinesis.model.GetShardIteratorResult in project druid by druid-io.

the class KinesisRecordSupplierTest method setupMockKinesisForShardId.

private void setupMockKinesisForShardId(AmazonKinesis kinesis, String shardId, List<Record> expectedRecords, String expectedNextIterator) {
    String shardIteratorType = ShardIteratorType.TRIM_HORIZON.toString();
    String shardIterator = "shardIterator" + shardId;
    GetShardIteratorResult shardIteratorResult = new GetShardIteratorResult().withShardIterator(shardIterator);
    EasyMock.expect(kinesis.getShardIterator(STREAM, shardId, shardIteratorType)).andReturn(shardIteratorResult).once();
    GetRecordsRequest request = new GetRecordsRequest().withShardIterator(shardIterator).withLimit(1);
    GetRecordsResult result = new GetRecordsResult().withRecords(expectedRecords).withNextShardIterator(expectedNextIterator);
    EasyMock.expect(kinesis.getRecords(request)).andReturn(result);
}
Also used : GetRecordsResult(com.amazonaws.services.kinesis.model.GetRecordsResult) GetShardIteratorResult(com.amazonaws.services.kinesis.model.GetShardIteratorResult) GetRecordsRequest(com.amazonaws.services.kinesis.model.GetRecordsRequest)

Aggregations

GetShardIteratorResult (com.amazonaws.services.kinesis.model.GetShardIteratorResult)15 GetShardIteratorRequest (com.amazonaws.services.kinesis.model.GetShardIteratorRequest)9 GetRecordsResult (com.amazonaws.services.kinesis.model.GetRecordsResult)6 GetRecordsRequest (com.amazonaws.services.kinesis.model.GetRecordsRequest)4 SourceRecord (org.apache.kafka.connect.source.SourceRecord)4 Test (org.junit.jupiter.api.Test)4 DescribeStreamRequest (com.amazonaws.services.kinesis.model.DescribeStreamRequest)3 DescribeStreamResult (com.amazonaws.services.kinesis.model.DescribeStreamResult)3 Shard (com.amazonaws.services.kinesis.model.Shard)2 Test (org.junit.Test)2 AmazonClientException (com.amazonaws.AmazonClientException)1 AmazonServiceException (com.amazonaws.AmazonServiceException)1 ProvisionedThroughputExceededException (com.amazonaws.services.kinesis.model.ProvisionedThroughputExceededException)1 ShardIteratorType (com.amazonaws.services.kinesis.model.ShardIteratorType)1 StreamDescription (com.amazonaws.services.kinesis.model.StreamDescription)1 Instant (org.joda.time.Instant)1 Before (org.junit.Before)1