in src/integration-test/java/com/awslabs/sqs/helpers/implementations/BasicSqsHelperTests.java [54:98]
public void shouldCreateAndDeleteQueues() {
// Create 100 queues, with consistent names
int expectedCount = 100;
List<QueueName> queueNames = List.ofAll(LongStream.range(0, expectedCount)
// Convert the long to a byte array so it can be hashed into a consistent queue name
.mapToObj(this::longToBytes)
// Create a queue name as the UUID by hashing the bytes
.map(UUID::nameUUIDFromBytes)
// Convert the UUID to a string
.map(UUID::toString)
// Convert the string to a QueueName object
.map(queueName -> ImmutableQueueName.builder().name(queueName).build()));
// Create all of the queues
RetryPolicy<QueueUrl> sqsCreateQueuesRetryPolicy = new RetryPolicy<QueueUrl>()
.withDelay(Duration.ofSeconds(10))
.withMaxRetries(6)
.handle(QueueDeletedRecentlyException.class)
.onRetry(failure -> log.warn("Waiting for SQS to allow recreation of the queue..."))
.onRetriesExceeded(failure -> log.error("SQS never allowed the queue to be recreated, giving up"));
List<QueueUrl> queueUrls = queueNames
.map(queueName -> Failsafe.with(sqsCreateQueuesRetryPolicy).get(() -> sqsHelper.createQueue(queueName)));
RetryPolicy<Integer> sqsGetQueueUrlsRetryPolicy = new RetryPolicy<Integer>()
.handleResult(0)
.withDelay(Duration.ofSeconds(5))
.withMaxRetries(10)
.handle(QueueDeletedRecentlyException.class)
.onRetry(failure -> log.warn("Waiting for non-zero queue URL list result..."))
.onRetriesExceeded(failure -> log.error("SQS never returned results, giving up"));
// Count the number of created queues (this can fail if you have queues with UUIDs as names)
int actualCount = Failsafe.with(sqsGetQueueUrlsRetryPolicy).get(() ->
sqsHelper.getQueueUrls()
.filter(getUuidPredicate())
.size());
// Make sure the count matches
assertThat(actualCount, is(expectedCount));
// Delete the queues we created
queueUrls.forEach(queueUrl -> sqsHelper.deleteQueue(queueUrl));
}