com.amazonaws.services.kinesis.model.ListShardsRequest Java Examples

The following examples show how to use com.amazonaws.services.kinesis.model.ListShardsRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KinesisProxyTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetShardWithNoNewShards() throws Exception {
	// given
	String fakeStreamName = "fake-stream";

	AmazonKinesis mockClient = mock(AmazonKinesis.class);
	KinesisProxy kinesisProxy = getProxy(mockClient);

	Mockito.when(mockClient.listShards(
		new ListShardsRequest()
		.withStreamName(fakeStreamName)
		.withExclusiveStartShardId(KinesisShardIdGenerator.generateFromShardOrder(1))
	)).thenReturn(new ListShardsResult().withShards(Collections.emptyList()));

	HashMap<String, String> streamHashMap = new HashMap<>();
	streamHashMap.put(fakeStreamName, KinesisShardIdGenerator.generateFromShardOrder(1));

	// when
	GetShardListResult shardListResult = kinesisProxy.getShardList(streamHashMap);

	// then
	Assert.assertFalse(shardListResult.hasRetrievedShards());
}
 
Example #2
Source File: KinesisProxyTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean matchesSafely(final ListShardsRequest listShardsRequest, final Description description) {
	if (shardId == null) {
		if (listShardsRequest.getExclusiveStartShardId() != null) {
			return false;
		}
	} else {
		if (!shardId.equals(listShardsRequest.getExclusiveStartShardId())) {
			return false;
		}
	}

	if (listShardsRequest.getNextToken() != null) {
		if (!(listShardsRequest.getStreamName() == null
						&& listShardsRequest.getExclusiveStartShardId() == null)) {
			return false;
		}

		if (!listShardsRequest.getNextToken().equals(nextToken)) {
			return false;
		}
	} else {
		return nextToken == null;
	}
	return true;
}
 
Example #3
Source File: KinesisProxyTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetShardWithNoNewShards() throws Exception {
	// given
	String fakeStreamName = "fake-stream";

	AmazonKinesis mockClient = mock(AmazonKinesis.class);
	KinesisProxy kinesisProxy = getProxy(mockClient);

	Mockito.when(mockClient.listShards(
		new ListShardsRequest()
		.withStreamName(fakeStreamName)
		.withExclusiveStartShardId(KinesisShardIdGenerator.generateFromShardOrder(1))
	)).thenReturn(new ListShardsResult().withShards(Collections.emptyList()));

	HashMap<String, String> streamHashMap = new HashMap<>();
	streamHashMap.put(fakeStreamName, KinesisShardIdGenerator.generateFromShardOrder(1));

	// when
	GetShardListResult shardListResult = kinesisProxy.getShardList(streamHashMap);

	// then
	Assert.assertFalse(shardListResult.hasRetrievedShards());
}
 
Example #4
Source File: KinesisProxyTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean matchesSafely(final ListShardsRequest listShardsRequest, final Description description) {
	if (shardId == null) {
		if (listShardsRequest.getExclusiveStartShardId() != null) {
			return false;
		}
	} else {
		if (!shardId.equals(listShardsRequest.getExclusiveStartShardId())) {
			return false;
		}
	}

	if (listShardsRequest.getNextToken() != null) {
		if (!(listShardsRequest.getStreamName() == null
						&& listShardsRequest.getExclusiveStartShardId() == null)) {
			return false;
		}

		if (!listShardsRequest.getNextToken().equals(nextToken)) {
			return false;
		}
	} else {
		return nextToken == null;
	}
	return true;
}
 
Example #5
Source File: KinesisProxyTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetShardWithNoNewShards() throws Exception {
	// given
	String fakeStreamName = "fake-stream";

	AmazonKinesis mockClient = mock(AmazonKinesis.class);
	KinesisProxy kinesisProxy = getProxy(mockClient);

	Mockito.when(mockClient.listShards(
		new ListShardsRequest()
		.withStreamName(fakeStreamName)
		.withExclusiveStartShardId(KinesisShardIdGenerator.generateFromShardOrder(1))
	)).thenReturn(new ListShardsResult().withShards(Collections.emptyList()));

	HashMap<String, String> streamHashMap = new HashMap<>();
	streamHashMap.put(fakeStreamName, KinesisShardIdGenerator.generateFromShardOrder(1));

	// when
	GetShardListResult shardListResult = kinesisProxy.getShardList(streamHashMap);

	// then
	Assert.assertFalse(shardListResult.hasRetrievedShards());
}
 
Example #6
Source File: KinesisProxyTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean matchesSafely(final ListShardsRequest listShardsRequest, final Description description) {
	if (shardId == null) {
		if (listShardsRequest.getExclusiveStartShardId() != null) {
			return false;
		}
	} else {
		if (!shardId.equals(listShardsRequest.getExclusiveStartShardId())) {
			return false;
		}
	}

	if (listShardsRequest.getNextToken() != null) {
		if (!(listShardsRequest.getStreamName() == null
						&& listShardsRequest.getExclusiveStartShardId() == null)) {
			return false;
		}

		if (!listShardsRequest.getNextToken().equals(nextToken)) {
			return false;
		}
	} else {
		return nextToken == null;
	}
	return true;
}
 
Example #7
Source File: KinesisStreamProvisioner.java    From spring-cloud-stream-binder-aws-kinesis with Apache License 2.0 5 votes vote down vote up
private List<Shard> getShardList(String stream, int retryCount) {
	List<Shard> shardList = new ArrayList<>();

	if (retryCount > configurationProperties.getDescribeStreamRetries()) {
		ResourceNotFoundException resourceNotFoundException = new ResourceNotFoundException(
				"The stream [" + stream + "] isn't ACTIVE or doesn't exist.");
		resourceNotFoundException.setServiceName("Kinesis");

		throw new ProvisioningException(
				"Kinesis org.springframework.cloud.stream.binder.kinesis.provisioning error",
				resourceNotFoundException);
	}

	ListShardsRequest listShardsRequest = new ListShardsRequest().withStreamName(stream);

	try {
		ListShardsResult listShardsResult = amazonKinesis.listShards(listShardsRequest);

		shardList.addAll(listShardsResult.getShards());

	}
	catch (LimitExceededException limitExceededException) {
		logger.info("Got LimitExceededException when describing stream [" + stream + "]. " + "Backing off for ["
				+ this.configurationProperties.getDescribeStreamBackoff() + "] millis.");

		try {
			Thread.sleep(this.configurationProperties.getDescribeStreamBackoff());
			getShardList(stream, retryCount++);
		}
		catch (InterruptedException ex) {
			Thread.currentThread().interrupt();
			throw new ProvisioningException(
					"The [describeStream] thread for the stream [" + stream + "] has been interrupted.", ex);
		}
	}

	return shardList;
}
 
Example #8
Source File: AmazonKinesisMock.java    From beam with Apache License 2.0 4 votes vote down vote up
@Override
public ListShardsResult listShards(ListShardsRequest listShardsRequest) {
  throw new RuntimeException("Not implemented");
}