diff --git a/pom.xml b/pom.xml
index 590e787..0a0de7e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -187,6 +187,12 @@
${aws.sdkv2.version}
provided
+
+ software.amazon.awssdk
+ apache-client
+ ${aws.sdkv2.version}
+ provided
+
software.amazon.kinesis
amazon-kinesis-client
diff --git a/src/main/java/cloud/localstack/awssdkv2/TestUtils.java b/src/main/java/cloud/localstack/awssdkv2/TestUtils.java
index ab07fa9..dbeb412 100644
--- a/src/main/java/cloud/localstack/awssdkv2/TestUtils.java
+++ b/src/main/java/cloud/localstack/awssdkv2/TestUtils.java
@@ -1,27 +1,41 @@
package cloud.localstack.awssdkv2;
+import cloud.localstack.Localstack;
+import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
+import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
+import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
+import software.amazon.awssdk.awscore.client.builder.AwsClientBuilder;
+import software.amazon.awssdk.core.client.builder.SdkAsyncClientBuilder;
+import software.amazon.awssdk.core.client.builder.SdkSyncClientBuilder;
+import software.amazon.awssdk.http.SdkHttpConfigurationOption;
+import software.amazon.awssdk.http.apache.ApacheHttpClient;
+import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient;
import software.amazon.awssdk.regions.Region;
+import software.amazon.awssdk.services.cloudwatch.CloudWatchAsyncClient;
+import software.amazon.awssdk.services.cloudwatch.CloudWatchClient;
import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient;
+import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
+import software.amazon.awssdk.services.iam.IamAsyncClient;
+import software.amazon.awssdk.services.iam.IamClient;
+import software.amazon.awssdk.services.kinesis.KinesisAsyncClient;
+import software.amazon.awssdk.services.kinesis.KinesisClient;
import software.amazon.awssdk.services.lambda.LambdaAsyncClient;
-import software.amazon.awssdk.utils.*;
-import software.amazon.awssdk.http.*;
-import software.amazon.awssdk.services.cloudwatch.*;
-import software.amazon.awssdk.services.kinesis.*;
-import software.amazon.awssdk.services.sns.*;
-import software.amazon.awssdk.services.sqs.*;
-import software.amazon.awssdk.services.s3.*;
+import software.amazon.awssdk.services.lambda.LambdaClient;
+import software.amazon.awssdk.services.qldb.QldbAsyncClient;
+import software.amazon.awssdk.services.qldb.QldbClient;
+import software.amazon.awssdk.services.s3.S3AsyncClient;
+import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.secretsmanager.SecretsManagerAsyncClient;
-import software.amazon.awssdk.services.ssm.*;
-import software.amazon.awssdk.services.iam.*;
-import software.amazon.awssdk.services.qldb.*;
-import software.amazon.awssdk.auth.credentials.*;
-import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient;
-import software.amazon.awssdk.core.client.builder.SdkAsyncClientBuilder;
-import software.amazon.awssdk.awscore.client.builder.AwsClientBuilder;
-
-import cloud.localstack.Localstack;
+import software.amazon.awssdk.services.secretsmanager.SecretsManagerClient;
+import software.amazon.awssdk.services.sns.SnsAsyncClient;
+import software.amazon.awssdk.services.sns.SnsClient;
+import software.amazon.awssdk.services.sqs.SqsAsyncClient;
+import software.amazon.awssdk.services.sqs.SqsClient;
+import software.amazon.awssdk.services.ssm.SsmAsyncClient;
+import software.amazon.awssdk.services.ssm.SsmClient;
+import software.amazon.awssdk.utils.AttributeMap;
-import java.net.*;
+import java.net.URI;
/**
* Utility methods for AWS SDK v2
@@ -30,50 +44,94 @@
public class TestUtils {
public static KinesisAsyncClient getClientKinesisAsyncV2() {
- return wrapApiClientV2(KinesisAsyncClient.builder(), Localstack.INSTANCE.getEndpointKinesis()).build();
+ return wrapApiAsyncClientV2(KinesisAsyncClient.builder(), Localstack.INSTANCE.getEndpointKinesis()).build();
+ }
+
+ public static KinesisClient getClientKinesisV2() {
+ return wrapApiSyncClientV2(KinesisClient.builder(), Localstack.INSTANCE.getEndpointKinesis()).build();
}
public static DynamoDbAsyncClient getClientDyanamoAsyncV2() {
- return wrapApiClientV2(DynamoDbAsyncClient.builder(), Localstack.INSTANCE.getEndpointDynamoDB()).build();
+ return wrapApiAsyncClientV2(DynamoDbAsyncClient.builder(), Localstack.INSTANCE.getEndpointDynamoDB()).build();
+ }
+
+ public static DynamoDbClient getClientDyanamoV2() {
+ return wrapApiSyncClientV2(DynamoDbClient.builder(), Localstack.INSTANCE.getEndpointDynamoDB()).build();
}
public static SqsAsyncClient getClientSQSAsyncV2() {
- return wrapApiClientV2(SqsAsyncClient.builder(), Localstack.INSTANCE.getEndpointSQS()).build();
+ return wrapApiAsyncClientV2(SqsAsyncClient.builder(), Localstack.INSTANCE.getEndpointSQS()).build();
+ }
+
+ public static SqsClient getClientSQSV2() {
+ return wrapApiSyncClientV2(SqsClient.builder(), Localstack.INSTANCE.getEndpointSQS()).build();
}
public static QldbAsyncClient getClientQLDBAsyncV2() {
- return wrapApiClientV2(QldbAsyncClient.builder(), Localstack.INSTANCE.getEndpointQLDB()).build();
+ return wrapApiAsyncClientV2(QldbAsyncClient.builder(), Localstack.INSTANCE.getEndpointQLDB()).build();
+ }
+
+ public static QldbClient getClientQLDBV2() {
+ return wrapApiSyncClientV2(QldbClient.builder(), Localstack.INSTANCE.getEndpointQLDB()).build();
}
public static SnsAsyncClient getClientSNSAsyncV2() {
- return wrapApiClientV2(SnsAsyncClient.builder(), Localstack.INSTANCE.getEndpointSNS()).build();
+ return wrapApiAsyncClientV2(SnsAsyncClient.builder(), Localstack.INSTANCE.getEndpointSNS()).build();
+ }
+
+ public static SnsClient getClientSNSV2() {
+ return wrapApiSyncClientV2(SnsClient.builder(), Localstack.INSTANCE.getEndpointSNS()).build();
}
public static SsmAsyncClient getClientSSMAsyncV2() {
- return wrapApiClientV2(SsmAsyncClient.builder(), Localstack.INSTANCE.getEndpointSSM()).build();
+ return wrapApiAsyncClientV2(SsmAsyncClient.builder(), Localstack.INSTANCE.getEndpointSSM()).build();
+ }
+
+ public static SsmClient getClientSSMV2() {
+ return wrapApiSyncClientV2(SsmClient.builder(), Localstack.INSTANCE.getEndpointSSM()).build();
}
public static SecretsManagerAsyncClient getClientSecretsManagerAsyncV2() {
- return wrapApiClientV2(SecretsManagerAsyncClient.builder(), Localstack.INSTANCE.getEndpointSSM()).build();
+ return wrapApiAsyncClientV2(SecretsManagerAsyncClient.builder(), Localstack.INSTANCE.getEndpointSSM()).build();
+ }
+
+ public static SecretsManagerClient getClientSecretsManagerV2() {
+ return wrapApiSyncClientV2(SecretsManagerClient.builder(), Localstack.INSTANCE.getEndpointSSM()).build();
}
public static S3AsyncClient getClientS3AsyncV2() {
- return wrapApiClientV2(S3AsyncClient.builder(), Localstack.INSTANCE.getEndpointS3()).build();
+ return wrapApiAsyncClientV2(S3AsyncClient.builder(), Localstack.INSTANCE.getEndpointS3()).build();
}
-
+
+ public static S3Client getClientS3V2() {
+ return wrapApiSyncClientV2(S3Client.builder(), Localstack.INSTANCE.getEndpointS3()).build();
+ }
+
public static CloudWatchAsyncClient getClientCloudWatchAsyncV2() {
- return wrapApiClientV2(CloudWatchAsyncClient.builder(), Localstack.INSTANCE.getEndpointCloudWatch()).build();
+ return wrapApiAsyncClientV2(CloudWatchAsyncClient.builder(), Localstack.INSTANCE.getEndpointCloudWatch()).build();
+ }
+
+ public static CloudWatchClient getClientCloudWatchV2() {
+ return wrapApiSyncClientV2(CloudWatchClient.builder(), Localstack.INSTANCE.getEndpointCloudWatch()).build();
}
public static LambdaAsyncClient getClientLambdaAsyncV2() {
- return wrapApiClientV2(LambdaAsyncClient.builder(), Localstack.INSTANCE.getEndpointLambda()).build();
+ return wrapApiAsyncClientV2(LambdaAsyncClient.builder(), Localstack.INSTANCE.getEndpointLambda()).build();
+ }
+
+ public static LambdaClient getClientLambdaV2() {
+ return wrapApiSyncClientV2(LambdaClient.builder(), Localstack.INSTANCE.getEndpointLambda()).build();
}
-
+
public static IamAsyncClient getClientIamAsyncV2() {
- return wrapApiClientV2(IamAsyncClient.builder(), Localstack.INSTANCE.getEndpointIAM()).build();
+ return wrapApiAsyncClientV2(IamAsyncClient.builder(), Localstack.INSTANCE.getEndpointIAM()).build();
+ }
+
+ public static IamClient getClientIamV2() {
+ return wrapApiSyncClientV2(IamClient.builder(), Localstack.INSTANCE.getEndpointIAM()).build();
}
-
- public static T wrapApiClientV2(T builder, String endpointURL) {
+
+ public static T wrapApiAsyncClientV2(T builder, String endpointURL) {
try {
return (T) ((AwsClientBuilder)builder
.httpClient(NettyNioAsyncHttpClient.builder().buildWithDefaults(
@@ -87,6 +145,20 @@ public static T wrapApiClientV2(T builder, Str
}
}
+ public static T wrapApiSyncClientV2(T builder, String endpointURL) {
+ try {
+ return (T) ((AwsClientBuilder)builder
+ .httpClient(ApacheHttpClient.builder().buildWithDefaults(
+ AttributeMap.builder().put(
+ SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES, java.lang.Boolean.TRUE).build())))
+ .credentialsProvider(getCredentialsV2())
+ .region(Region.of(Localstack.INSTANCE.getDefaultRegion()))
+ .endpointOverride(new URI(endpointURL));
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
private static AwsCredentialsProvider getCredentialsV2() throws Exception {
return StaticCredentialsProvider.create(AwsBasicCredentials.create("access", "secret"));
}
diff --git a/src/test/java/cloud/localstack/awssdkv2/BasicFeaturesSDKV2Test.java b/src/test/java/cloud/localstack/awssdkv2/BasicFeaturesSDKV2Test.java
index 1f85a84..8321776 100644
--- a/src/test/java/cloud/localstack/awssdkv2/BasicFeaturesSDKV2Test.java
+++ b/src/test/java/cloud/localstack/awssdkv2/BasicFeaturesSDKV2Test.java
@@ -11,55 +11,74 @@
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.testcontainers.utility.ThrowingFunction;
import software.amazon.awssdk.core.SdkBytes;
import software.amazon.awssdk.core.SdkSystemSetting;
import software.amazon.awssdk.services.cloudwatch.CloudWatchAsyncClient;
+import software.amazon.awssdk.services.cloudwatch.CloudWatchClient;
import software.amazon.awssdk.services.cloudwatch.model.Dimension;
import software.amazon.awssdk.services.cloudwatch.model.MetricDatum;
import software.amazon.awssdk.services.cloudwatch.model.PutMetricDataRequest;
import software.amazon.awssdk.services.cloudwatch.model.PutMetricDataResponse;
import software.amazon.awssdk.services.cloudwatch.model.StandardUnit;
import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient;
+import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
import software.amazon.awssdk.services.dynamodb.model.AttributeDefinition;
import software.amazon.awssdk.services.dynamodb.model.CreateTableRequest;
import software.amazon.awssdk.services.dynamodb.model.CreateTableResponse;
import software.amazon.awssdk.services.dynamodb.model.DeleteTableRequest;
+import software.amazon.awssdk.services.dynamodb.model.DeleteTableResponse;
import software.amazon.awssdk.services.dynamodb.model.KeySchemaElement;
import software.amazon.awssdk.services.dynamodb.model.KeyType;
import software.amazon.awssdk.services.dynamodb.model.ProvisionedThroughput;
import software.amazon.awssdk.services.dynamodb.model.ScalarAttributeType;
import software.amazon.awssdk.services.iam.IamAsyncClient;
+import software.amazon.awssdk.services.iam.IamClient;
import software.amazon.awssdk.services.iam.model.CreateUserRequest;
+import software.amazon.awssdk.services.iam.model.CreateUserResponse;
+import software.amazon.awssdk.services.iam.model.ListUsersResponse;
import software.amazon.awssdk.services.iam.model.User;
import software.amazon.awssdk.services.kinesis.KinesisAsyncClient;
+import software.amazon.awssdk.services.kinesis.KinesisClient;
import software.amazon.awssdk.services.kinesis.model.CreateStreamRequest;
import software.amazon.awssdk.services.kinesis.model.CreateStreamResponse;
import software.amazon.awssdk.services.kinesis.model.PutRecordRequest;
+import software.amazon.awssdk.services.kinesis.model.PutRecordResponse;
import software.amazon.awssdk.services.lambda.model.CreateFunctionRequest;
+import software.amazon.awssdk.services.lambda.model.CreateFunctionResponse;
+import software.amazon.awssdk.services.lambda.model.ListFunctionsResponse;
import software.amazon.awssdk.services.lambda.model.Runtime;
import software.amazon.awssdk.services.s3.S3AsyncClient;
+import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.Bucket;
import software.amazon.awssdk.services.s3.model.CreateBucketRequest;
import software.amazon.awssdk.services.s3.model.CreateBucketResponse;
import software.amazon.awssdk.services.s3.model.ListBucketsRequest;
import software.amazon.awssdk.services.s3.model.ListBucketsResponse;
import software.amazon.awssdk.services.secretsmanager.SecretsManagerAsyncClient;
+import software.amazon.awssdk.services.secretsmanager.SecretsManagerClient;
import software.amazon.awssdk.services.secretsmanager.model.CreateSecretRequest;
+import software.amazon.awssdk.services.secretsmanager.model.CreateSecretResponse;
import software.amazon.awssdk.services.secretsmanager.model.DeleteSecretRequest;
+import software.amazon.awssdk.services.secretsmanager.model.DeleteSecretResponse;
import software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest;
import software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse;
import software.amazon.awssdk.services.sns.SnsAsyncClient;
+import software.amazon.awssdk.services.sns.SnsClient;
import software.amazon.awssdk.services.sns.model.CreateTopicRequest;
import software.amazon.awssdk.services.sns.model.CreateTopicResponse;
import software.amazon.awssdk.services.sns.model.PublishRequest;
import software.amazon.awssdk.services.sns.model.PublishResponse;
import software.amazon.awssdk.services.sqs.SqsAsyncClient;
+import software.amazon.awssdk.services.sqs.SqsClient;
import software.amazon.awssdk.services.sqs.model.CreateQueueRequest;
import software.amazon.awssdk.services.sqs.model.CreateQueueResponse;
import software.amazon.awssdk.services.ssm.SsmAsyncClient;
+import software.amazon.awssdk.services.ssm.SsmClient;
import software.amazon.awssdk.services.ssm.model.GetParameterRequest;
import software.amazon.awssdk.services.ssm.model.GetParameterResponse;
import software.amazon.awssdk.services.ssm.model.PutParameterRequest;
+import software.amazon.awssdk.services.ssm.model.PutParameterResponse;
import java.nio.ByteBuffer;
import java.time.Instant;
@@ -69,7 +88,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
-import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -86,32 +104,75 @@ public static void beforeAll() {
System.setProperty(SdkSystemSetting.CBOR_ENABLED.property(), "false");
}
+ @Test
+ public void testCreateSqsQueueAsyncV2() throws Exception {
+ SqsAsyncClient sqsAsyncClient = TestUtils.getClientSQSAsyncV2();
+ validateCreateSqsQueueV2(createReq -> sqsAsyncClient.createQueue(createReq).get());
+ }
+
@Test
public void testCreateSqsQueueV2() throws Exception {
+ SqsClient sqsClient = TestUtils.getClientSQSV2();
+ validateCreateSqsQueueV2(createReq -> sqsClient.createQueue(createReq));
+ }
+
+ protected static void validateCreateSqsQueueV2(
+ ThrowingFunction createAction
+ ) throws Exception {
String queueName = "test-q-"+ UUID.randomUUID().toString();
CreateQueueRequest request = CreateQueueRequest.builder().queueName(queueName).build();
- SqsAsyncClient sqsClient = TestUtils.getClientSQSAsyncV2();
- CreateQueueResponse queue = sqsClient.createQueue(request).get();
+ CreateQueueResponse queue = createAction.apply(request);
Assert.assertTrue(queue.queueUrl().contains(Constants.DEFAULT_AWS_ACCOUNT_ID + "/" + queueName));
}
+ @Test
+ public void testCreateKinesisStreamAsyncV2() throws Exception {
+ KinesisAsyncClient kinesisAsyncClient = TestUtils.getClientKinesisAsyncV2();
+ validateCreateKinesisStreamV2(createReq -> kinesisAsyncClient.createStream(createReq).get());
+ }
+
@Test
public void testCreateKinesisStreamV2() throws Exception {
+ KinesisClient kinesisClient = TestUtils.getClientKinesisV2();
+ validateCreateKinesisStreamV2(createReq -> kinesisClient.createStream(createReq));
+ }
+
+ protected static void validateCreateKinesisStreamV2(
+ ThrowingFunction createAction
+ ) throws Exception {
String streamName = "test-s-"+ UUID.randomUUID().toString();
- KinesisAsyncClient kinesisClient = TestUtils.getClientKinesisAsyncV2();
CreateStreamRequest request = CreateStreamRequest.builder()
.streamName(streamName).shardCount(1).build();
- CreateStreamResponse response = kinesisClient.createStream(request).get();
+ CreateStreamResponse response = createAction.apply(request);
Assert.assertNotNull(response);
}
+ @Test
+ public void testCreateKinesisRecordAsyncV2() throws Exception {
+ KinesisAsyncClient kinesisAsyncClient = TestUtils.getClientKinesisAsyncV2();
+ validateCreateKinesisRecordV2(
+ createReq -> kinesisAsyncClient.createStream(createReq).get(),
+ putReq -> kinesisAsyncClient.putRecord(putReq).get()
+ );
+ }
+
@Test
public void testCreateKinesisRecordV2() throws Exception {
+ KinesisClient kinesisClient = TestUtils.getClientKinesisV2();
+ validateCreateKinesisRecordV2(
+ createReq -> kinesisClient.createStream(createReq),
+ putReq -> kinesisClient.putRecord(putReq)
+ );
+ }
+
+ protected static void validateCreateKinesisRecordV2(
+ ThrowingFunction createAction,
+ ThrowingFunction putAction
+ ) throws Exception {
String streamName = "test-s-"+UUID.randomUUID().toString();
- KinesisAsyncClient kinesisClient = TestUtils.getClientKinesisAsyncV2();
CreateStreamRequest request = CreateStreamRequest.builder()
.streamName(streamName).shardCount(1).build();
- CreateStreamResponse response = kinesisClient.createStream(request).get();
+ CreateStreamResponse response = createAction.apply(request);
Assert.assertNotNull(response);
SdkBytes payload = SdkBytes.fromByteBuffer(ByteBuffer.wrap(String.format("testData-%d", 1).getBytes()));
@@ -119,12 +180,31 @@ public void testCreateKinesisRecordV2() throws Exception {
putRecordRequest.streamName(streamName);
putRecordRequest.data(payload);
putRecordRequest.partitionKey(String.format("partitionKey-%d", 1));
- Assert.assertNotNull(kinesisClient.putRecord(putRecordRequest.build()));
+ Assert.assertNotNull(putAction.apply(putRecordRequest.build()));
}
@Test
- public void testCreateDynamoDBTable() throws Exception {
+ public void testCreateDynamoDBTableAsync() throws Exception {
DynamoDbAsyncClient dynamoDbAsyncClient = TestUtils.getClientDyanamoAsyncV2();
+ validateCreateDynamoDBTable(
+ createReq -> dynamoDbAsyncClient.createTable(createReq).get(),
+ deleteReq -> dynamoDbAsyncClient.deleteTable(deleteReq).get()
+ );
+ }
+
+ @Test
+ public void testCreateDynamoDBTable() throws Exception {
+ DynamoDbClient dynamoDbClient = TestUtils.getClientDyanamoV2();
+ validateCreateDynamoDBTable(
+ createReq -> dynamoDbClient.createTable(createReq),
+ deleteReq -> dynamoDbClient.deleteTable(deleteReq)
+ );
+ }
+
+ protected static void validateCreateDynamoDBTable(
+ ThrowingFunction createAction,
+ ThrowingFunction deleteAction
+ ) throws Exception {
String tableName = "test-s-"+ UUID.randomUUID().toString();
CreateTableRequest createTableRequest = CreateTableRequest.builder()
.keySchema(
@@ -144,95 +224,215 @@ public void testCreateDynamoDBTable() throws Exception {
.build())
.tableName(tableName)
.build();
- CreateTableResponse response = dynamoDbAsyncClient.createTable(createTableRequest).get();
+ CreateTableResponse response = createAction.apply(createTableRequest);
Assert.assertNotNull(response);
// clean up
- dynamoDbAsyncClient.deleteTable(DeleteTableRequest.builder().tableName(tableName).build());
+ deleteAction.apply(DeleteTableRequest.builder().tableName(tableName).build());
+ }
+
+ @Test
+ public void testS3CreateListBucketsAsync() throws Exception {
+ S3AsyncClient s3AsyncClient = TestUtils.getClientS3AsyncV2();
+ validateS3CreateListBuckets(
+ createReq -> s3AsyncClient.createBucket(createReq).get(),
+ listReq -> s3AsyncClient.listBuckets(listReq).get()
+ );
}
@Test
public void testS3CreateListBuckets() throws Exception {
+ S3Client s3Client = TestUtils.getClientS3V2();
+ validateS3CreateListBuckets(
+ createReq -> s3Client.createBucket(createReq),
+ listReq -> s3Client.listBuckets(listReq)
+ );
+ }
+
+ protected static void validateS3CreateListBuckets(
+ ThrowingFunction createAction,
+ ThrowingFunction listAction
+ ) throws Exception {
String bucketName = "test-b-"+UUID.randomUUID().toString();
- S3AsyncClient s3Client = TestUtils.getClientS3AsyncV2();
CreateBucketRequest request = CreateBucketRequest.builder().bucket(bucketName).build();
- CreateBucketResponse response = s3Client.createBucket(request).get();
+ CreateBucketResponse response = createAction.apply(request);
Assert.assertNotNull(response);
ListBucketsRequest listRequest = ListBucketsRequest.builder().build();
- ListBucketsResponse buckets = s3Client.listBuckets(listRequest).get();
+ ListBucketsResponse buckets = listAction.apply(listRequest);
Bucket bucket = buckets.buckets().stream().filter(b -> b.name().equals(bucketName)).findFirst().get();
Assert.assertNotNull(bucket);
}
+ @Test
+ public void testSendSNSMessageAsync() throws Exception {
+ final SnsAsyncClient snsAsyncClient = TestUtils.getClientSNSAsyncV2();
+ validateSendSNSMessage(
+ createReq -> snsAsyncClient.createTopic(createReq).get(),
+ publishReq -> snsAsyncClient.publish(publishReq).get()
+ );
+ }
+
@Test
public void testSendSNSMessage() throws Exception {
+ final SnsClient snsClient = TestUtils.getClientSNSV2();
+ validateSendSNSMessage(
+ createReq -> snsClient.createTopic(createReq),
+ publishReq -> snsClient.publish(publishReq)
+ );
+ }
+
+ protected void validateSendSNSMessage(
+ ThrowingFunction createAction,
+ ThrowingFunction publishAction
+ ) throws Exception {
// Test integration of SNS messaging with LocalStack using SDK v2
final String topicName = "test-t-"+UUID.randomUUID().toString();
- final SnsAsyncClient clientSNS = TestUtils.getClientSNSAsyncV2();
- CreateTopicResponse createTopicResponse = clientSNS.createTopic(
- CreateTopicRequest.builder().name(topicName).build()).get();
+ CreateTopicResponse createTopicResponse = createAction.apply(
+ CreateTopicRequest.builder().name(topicName).build());
String topicArn = createTopicResponse.topicArn();
Assert.assertNotNull(topicArn);
PublishRequest publishRequest = PublishRequest.builder().topicArn(topicArn).subject("test subject").message("message test.").build();
- PublishResponse publishResponse = clientSNS.publish(publishRequest).get();
+ PublishResponse publishResponse = publishAction.apply(publishRequest);
Assert.assertNotNull(publishResponse.messageId());
}
+ @Test
+ public void testGetSsmParameterAsync() throws Exception {
+ final SsmAsyncClient ssmAsyncClient = TestUtils.getClientSSMAsyncV2();
+ validateGetSsmParameter(
+ putReq -> ssmAsyncClient.putParameter(putReq).get(),
+ getReq -> ssmAsyncClient.getParameter(getReq).get()
+ );
+ }
+
@Test
public void testGetSsmParameter() throws Exception {
+ final SsmClient ssmClient = TestUtils.getClientSSMV2();
+ validateGetSsmParameter(
+ putReq -> ssmClient.putParameter(putReq),
+ getReq -> ssmClient.getParameter(getReq)
+ );
+ }
+
+ protected static void validateGetSsmParameter(
+ ThrowingFunction putAction,
+ ThrowingFunction getAction
+ ) throws Exception {
// Test integration of ssm parameter with LocalStack using SDK v2
- final SsmAsyncClient clientSsm = TestUtils.getClientSSMAsyncV2();
final String paramName = "param-"+UUID.randomUUID().toString();
- clientSsm.putParameter(PutParameterRequest.builder().name(paramName).value("testvalue").build()).join();
- CompletableFuture getParameterResponse = clientSsm.getParameter(
+ putAction.apply(PutParameterRequest.builder().name(paramName).value("testvalue").build());
+ GetParameterResponse getParameterResponse = getAction.apply(
GetParameterRequest.builder().name(paramName).build());
- String parameterValue = getParameterResponse.get().parameter().value();
+ String parameterValue = getParameterResponse.parameter().value();
Assert.assertNotNull(parameterValue);
Assert.assertEquals("testvalue", parameterValue);
}
+ @Test
+ public void testGetSecretsManagerSecretAsync() throws Exception {
+ final SecretsManagerAsyncClient secretsManagerAsync = TestUtils.getClientSecretsManagerAsyncV2();
+ validateGetSecretsManagerSecret(
+ createReq -> secretsManagerAsync.createSecret(createReq).get(),
+ getReq -> secretsManagerAsync.getSecretValue(getReq).get(),
+ delReq -> secretsManagerAsync.deleteSecret(delReq).get()
+ );
+ }
+
@Test
public void testGetSecretsManagerSecret() throws Exception {
- final SecretsManagerAsyncClient clientSecretsManager = TestUtils.getClientSecretsManagerAsyncV2();
+ final SecretsManagerClient secretsManager = TestUtils.getClientSecretsManagerV2();
+ validateGetSecretsManagerSecret(
+ createReq -> secretsManager.createSecret(createReq),
+ getReq -> secretsManager.getSecretValue(getReq),
+ delReq -> secretsManager.deleteSecret(delReq)
+ );
+ }
+
+ protected static void validateGetSecretsManagerSecret(
+ ThrowingFunction createAction,
+ ThrowingFunction getAction,
+ ThrowingFunction deleteAction
+ ) throws Exception {
final String secretName = "test-s-" + UUID.randomUUID().toString();
- clientSecretsManager.createSecret(
- CreateSecretRequest.builder().name(secretName).secretString("secretcontent").build()).join();
- CompletableFuture getSecretResponse = clientSecretsManager.getSecretValue(
+ createAction.apply(
+ CreateSecretRequest.builder().name(secretName).secretString("secretcontent").build());
+ GetSecretValueResponse getSecretResponse = getAction.apply(
GetSecretValueRequest.builder().secretId(secretName).build());
- String secretValue = getSecretResponse.get().secretString();
+ String secretValue = getSecretResponse.secretString();
Assert.assertNotNull(secretValue);
Assert.assertEquals("secretcontent", secretValue);
// clean up
- clientSecretsManager.deleteSecret(DeleteSecretRequest.builder().secretId(secretName).build());
+ deleteAction.apply(DeleteSecretRequest.builder().secretId(secretName).build());
+ }
+
+ @Test
+ public void testGetSecretAsParamAsync() throws Exception {
+ final SsmAsyncClient ssmAsyncClient = TestUtils.getClientSSMAsyncV2();
+ final SecretsManagerAsyncClient secretsManagerAsyncClient = TestUtils.getClientSecretsManagerAsyncV2();
+
+ validateGetSecretAsParam(
+ createReq -> secretsManagerAsyncClient.createSecret(createReq).get(),
+ getReq -> ssmAsyncClient.getParameter(getReq).get(),
+ delReq -> secretsManagerAsyncClient.deleteSecret(delReq).get()
+ );
}
@Test
public void testGetSecretAsParam() throws Exception {
- final SsmAsyncClient clientSsm = TestUtils.getClientSSMAsyncV2();
- final SecretsManagerAsyncClient clientSecretsManager = TestUtils.getClientSecretsManagerAsyncV2();
+ final SsmClient ssmClient = TestUtils.getClientSSMV2();
+ final SecretsManagerClient secretsManagerClient = TestUtils.getClientSecretsManagerV2();
+
+ validateGetSecretAsParam(
+ createReq -> secretsManagerClient.createSecret(createReq),
+ getReq -> ssmClient.getParameter(getReq),
+ delReq -> secretsManagerClient.deleteSecret(delReq)
+ );
+ }
+ protected static void validateGetSecretAsParam(
+ ThrowingFunction createAction,
+ ThrowingFunction getAction,
+ ThrowingFunction delAction
+ ) throws Exception {
final String secretName = "test-s-" + UUID.randomUUID().toString();
- clientSecretsManager.createSecret(CreateSecretRequest.builder()
- .name(secretName).secretString("secretcontent").build()).join();
+ createAction.apply(CreateSecretRequest.builder()
+ .name(secretName).secretString("secretcontent").build());
- CompletableFuture getParameterResponse = clientSsm.getParameter(
+ GetParameterResponse getParameterResponse = getAction.apply(
GetParameterRequest.builder().name("/aws/reference/secretsmanager/" + secretName).build());
- final String parameterValue = getParameterResponse.get().parameter().value();
+ final String parameterValue = getParameterResponse.parameter().value();
Assert.assertNotNull(parameterValue);
Assert.assertEquals("secretcontent", parameterValue);
// clean up
- clientSecretsManager.deleteSecret(DeleteSecretRequest.builder().secretId(secretName).build());
+ delAction.apply(DeleteSecretRequest.builder().secretId(secretName).build());
}
+
+ @Test
+ public void testCWPutMetricsAsync() throws Exception {
+ final CloudWatchAsyncClient cwClientAsync = TestUtils.getClientCloudWatchAsyncV2();
+ validateCWPutMetrics(
+ putReq -> cwClientAsync.putMetricData(putReq).get()
+ );
+ }
+
@Test
public void testCWPutMetrics() throws Exception {
- final CloudWatchAsyncClient clientCW = TestUtils.getClientCloudWatchAsyncV2();
+ final CloudWatchClient cwClient = TestUtils.getClientCloudWatchV2();
+ validateCWPutMetrics(
+ putReq -> cwClient.putMetricData(putReq)
+ );
+ }
+
+ protected static void validateCWPutMetrics(
+ ThrowingFunction putAction
+ ) throws Exception {
Dimension dimension = Dimension.builder()
.name("UNIQUE_PAGES")
.value("URLS")
@@ -255,14 +455,29 @@ public void testCWPutMetrics() throws Exception {
.namespace("SITE/TRAFFIC")
.metricData(datum).build();
- PutMetricDataResponse response = clientCW.putMetricData(request).get();
+ PutMetricDataResponse response = putAction.apply(request);
Assert.assertNotNull(response);
}
-
+
+ @Test
+ public void testCWMultipleDimentionsAndMetricsAsync() throws Exception {
+ final CloudWatchAsyncClient clientCWAsync = TestUtils.getClientCloudWatchAsyncV2();
+ validateCWMultipleDimentionsAndMetrics(
+ putReq -> clientCWAsync.putMetricData(putReq).get()
+ );
+ }
+
@Test
public void testCWMultipleDimentionsAndMetrics() throws Exception {
- final CloudWatchAsyncClient clientCW = TestUtils.getClientCloudWatchAsyncV2();
-
+ final CloudWatchClient clientCW = TestUtils.getClientCloudWatchV2();
+ validateCWMultipleDimentionsAndMetrics(
+ putReq -> clientCW.putMetricData(putReq)
+ );
+ }
+
+ protected static void validateCWMultipleDimentionsAndMetrics(
+ ThrowingFunction putAction
+ ) throws Exception {
List awsDimensionList = new ArrayList<>();
for (int i = 0; i < 10; i++) {
awsDimensionList.add(Dimension.builder()
@@ -275,8 +490,8 @@ public void testCWMultipleDimentionsAndMetrics() throws Exception {
String time = ZonedDateTime.now( ZoneOffset.UTC ).format( DateTimeFormatter.ISO_INSTANT );
Instant instant = Instant.parse(time);
double dataPoint = 1.23423;
-
- List metrics = new ArrayList();
+
+ List metrics = new ArrayList<>();
for (int i = 0; i < 20; i++) {
metrics.add(MetricDatum.builder()
.metricName("PAGES_VISITED")
@@ -290,36 +505,74 @@ public void testCWMultipleDimentionsAndMetrics() throws Exception {
.namespace("SITE/TRAFFIC")
.metricData(metrics).build();
- PutMetricDataResponse response = clientCW.putMetricData(request).get();
+ PutMetricDataResponse response = putAction.apply(request);
Assert.assertNotNull(response);
}
+ @Test
+ public void testLambdaCreateListFunctionsAsync() throws Exception {
+ val lambdaClientAsync = TestUtils.getClientLambdaAsyncV2();
+ validateLambdaCreateListFunctions(
+ createReq -> lambdaClientAsync.createFunction(createReq).get(),
+ x -> lambdaClientAsync.listFunctions().get()
+ );
+ }
+
@Test
public void testLambdaCreateListFunctions() throws Exception {
+ val lambdaClient = TestUtils.getClientLambdaV2();
+ validateLambdaCreateListFunctions(
+ createReq -> lambdaClient.createFunction(createReq),
+ x -> lambdaClient.listFunctions()
+ );
+ }
+
+ protected static void validateLambdaCreateListFunctions(
+ ThrowingFunction createAction,
+ ThrowingFunction listAction
+ ) throws Exception {
val functionName = "test-f-"+UUID.randomUUID().toString();
- val lambdaClient = TestUtils.getClientLambdaAsyncV2();
val createFunctionRequest = CreateFunctionRequest.builder().functionName(functionName)
.runtime(Runtime.JAVA8)
.role("r1")
.code(LocalTestUtilSDKV2.createFunctionCode(LambdaHandler.class))
.handler(LambdaHandler.class.getName()).build();
- val response = lambdaClient.createFunction(createFunctionRequest).get();
+ val response = createAction.apply(createFunctionRequest);
Assert.assertNotNull(response);
- val functions = lambdaClient.listFunctions().get();
+ val functions = listAction.apply(null);
val function = functions.functions().stream().filter(f -> f.functionName().equals(functionName)).findFirst().get();
Assert.assertNotNull(function);
}
-
+
@Test
- public void testIAMUserCreation() throws Exception {
- IamAsyncClient iamClient = TestUtils.getClientIamAsyncV2();
+ public void testIAMUserCreationAsync() throws Exception {
+ IamAsyncClient iamClientAsync = TestUtils.getClientIamAsyncV2();
+ validateIAMUserCreation(
+ createReq -> iamClientAsync.createUser(createReq).get(),
+ x -> iamClientAsync.listUsers().get()
+ );
+ }
+
+ @Test
+ public void testIAMUserCreation() throws Exception {
+ IamClient iamClient = TestUtils.getClientIamV2();
+ validateIAMUserCreation(
+ createReq -> iamClient.createUser(createReq),
+ x -> iamClient.listUsers()
+ );
+ }
+
+ protected static void validateIAMUserCreation(
+ ThrowingFunction createAction,
+ ThrowingFunction listAction
+ ) throws Exception {
+
+ String username = UUID.randomUUID().toString();
+ CreateUserRequest createUserRequest = CreateUserRequest.builder().userName(username).build();
+ createAction.apply(createUserRequest);
- String username = UUID.randomUUID().toString();
- CreateUserRequest createUserRequest = CreateUserRequest.builder().userName(username).build();
- iamClient.createUser(createUserRequest).join();
-
boolean userFound = false;
- List users = iamClient.listUsers().get().users();
+ List users = listAction.apply(null).users();
for (int i = 0; i < users.size(); i++) {
if(users.get(i).userName().equals(username)){
@@ -328,11 +581,11 @@ public void testIAMUserCreation() throws Exception {
}
}
- Assert.assertTrue(userFound);
- }
-
+ Assert.assertTrue(userFound);
+ }
+
@Test
- public void testIAMListUserPagination() throws Exception {
+ public void testIAMListUserPaginationAsync() throws Exception {
IamAsyncClient iamClient = TestUtils.getClientIamAsyncV2();
String username = UUID.randomUUID().toString();