Skip to content

Commit

Permalink
Revert to localstack 0.14.2 for AWS V1 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasKunz committed Dec 4, 2023
1 parent 8be40e0 commit 5762e50
Show file tree
Hide file tree
Showing 12 changed files with 635 additions and 595 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package co.elastic.apm.agent.awssdk.v1;

import co.elastic.apm.agent.awssdk.common.AbstractAwsClientIT;

public abstract class AbstractAws1ClientIT extends AbstractAwsClientIT {

public static final String LOCALSTACK_VERSION = "0.14.2";

public AbstractAws1ClientIT() {
super(LOCALSTACK_VERSION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
import static co.elastic.apm.agent.testutils.assertions.Assertions.assertThat;


public class DynamoDbClientIT extends AbstractAwsClientIT {
public class DynamoDbClientIT extends AbstractAws1ClientIT {

private AmazonDynamoDB dynamoDB;
private AmazonDynamoDBAsync dynamoDBAsync;
Expand All @@ -61,76 +61,76 @@ public class DynamoDbClientIT extends AbstractAwsClientIT {
@BeforeEach
public void setupClient() {
dynamoDB = AmazonDynamoDBClient.builder()
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(localstack.getEndpointOverride(LocalStackContainer.Service.S3).toString(), localstack.getRegion()))
.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(localstack.getAccessKey(), localstack.getSecretKey())))
.build();
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(localstack.getEndpointOverride(LocalStackContainer.Service.S3).toString(), localstack.getRegion()))
.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(localstack.getAccessKey(), localstack.getSecretKey())))
.build();
dynamoDBAsync = AmazonDynamoDBAsyncClient.asyncBuilder()
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(localstack.getEndpointOverride(LocalStackContainer.Service.S3).toString(), localstack.getRegion()))
.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(localstack.getAccessKey(), localstack.getSecretKey())))
.build();
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(localstack.getEndpointOverride(LocalStackContainer.Service.S3).toString(), localstack.getRegion()))
.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(localstack.getAccessKey(), localstack.getSecretKey())))
.build();
}

@Test
public void testDynamoDbClient() {
Transaction transaction = startTestRootTransaction("s3-test");

newTest(() -> dynamoDB.createTable(new CreateTableRequest().withTableName(TABLE_NAME)
.withAttributeDefinitions(List.of(
new AttributeDefinition("attributeOne", ScalarAttributeType.S),
new AttributeDefinition("attributeTwo", ScalarAttributeType.N)
))
.withKeySchema(List.of(
new KeySchemaElement("attributeOne", KeyType.HASH),
new KeySchemaElement("attributeTwo", KeyType.RANGE)
))
.withBillingMode(BillingMode.PAY_PER_REQUEST)))
.operationName("CreateTable")
.entityName(TABLE_NAME)
.action("query")
.withSpanAssertions(dbAssert)
.execute();
.withAttributeDefinitions(List.of(
new AttributeDefinition("attributeOne", ScalarAttributeType.S),
new AttributeDefinition("attributeTwo", ScalarAttributeType.N)
))
.withKeySchema(List.of(
new KeySchemaElement("attributeOne", KeyType.HASH),
new KeySchemaElement("attributeTwo", KeyType.RANGE)
))
.withBillingMode(BillingMode.PAY_PER_REQUEST)))
.operationName("CreateTable")
.entityName(TABLE_NAME)
.action("query")
.withSpanAssertions(dbAssert)
.execute();

newTest(() -> dynamoDB.listTables())
.operationName("ListTables")
.action("query")
.withSpanAssertions(dbAssert)
.execute();
.operationName("ListTables")
.action("query")
.withSpanAssertions(dbAssert)
.execute();

newTest(() -> dynamoDB.putItem(
new PutItemRequest(TABLE_NAME,
Map.of("attributeOne", new AttributeValue("valueOne"), "attributeTwo", new AttributeValue().withN("10")))))
.operationName("PutItem")
.entityName(TABLE_NAME)
.action("query")
.withSpanAssertions(dbAssert)
.execute();
new PutItemRequest(TABLE_NAME,
Map.of("attributeOne", new AttributeValue("valueOne"), "attributeTwo", new AttributeValue().withN("10")))))
.operationName("PutItem")
.entityName(TABLE_NAME)
.action("query")
.withSpanAssertions(dbAssert)
.execute();

newTest(() -> dynamoDB.query(
new QueryRequest(TABLE_NAME)
.withKeyConditionExpression(KEY_CONDITION_EXPRESSION)
.withExpressionAttributeValues(Map.of(":one", new AttributeValue("valueOne")))))
.operationName("Query")
.entityName(TABLE_NAME)
.action("query")
.withSpanAssertions(dbAssert
.andThen(span -> assertThat(span.getContext().getDb()).hasStatement(KEY_CONDITION_EXPRESSION)))
.execute();
new QueryRequest(TABLE_NAME)
.withKeyConditionExpression(KEY_CONDITION_EXPRESSION)
.withExpressionAttributeValues(Map.of(":one", new AttributeValue("valueOne")))))
.operationName("Query")
.entityName(TABLE_NAME)
.action("query")
.withSpanAssertions(dbAssert
.andThen(span -> assertThat(span.getContext().getDb()).hasStatement(KEY_CONDITION_EXPRESSION)))
.execute();

newTest(() -> dynamoDB.deleteTable(TABLE_NAME))
.operationName("DeleteTable")
.entityName(TABLE_NAME)
.action("query")
.withSpanAssertions(dbAssert)
.execute();
.operationName("DeleteTable")
.entityName(TABLE_NAME)
.action("query")
.withSpanAssertions(dbAssert)
.execute();

newTest(() -> dynamoDB.putItem(
new PutItemRequest(TABLE_NAME + "-exception",
Map.of("attributeOne", new AttributeValue("valueOne"), "attributeTwo", new AttributeValue().withN("10")))))
.operationName("PutItem")
.action("query")
.entityName(TABLE_NAME + "-exception")
.withSpanAssertions(dbAssert)
.executeWithException(ResourceNotFoundException.class);
new PutItemRequest(TABLE_NAME + "-exception",
Map.of("attributeOne", new AttributeValue("valueOne"), "attributeTwo", new AttributeValue().withN("10")))))
.operationName("PutItem")
.action("query")
.entityName(TABLE_NAME + "-exception")
.withSpanAssertions(dbAssert)
.executeWithException(ResourceNotFoundException.class);

assertThat(reporter.getSpans().size()).isEqualTo(6);

Expand All @@ -145,59 +145,59 @@ public void testDynamoDbClientAsync() {
Transaction transaction = startTestRootTransaction("s3-test");

newTest(() -> dynamoDBAsync.createTableAsync(new CreateTableRequest().withTableName(TABLE_NAME)
.withAttributeDefinitions(List.of(
new AttributeDefinition("attributeOne", ScalarAttributeType.S),
new AttributeDefinition("attributeTwo", ScalarAttributeType.N)
))
.withKeySchema(List.of(
new KeySchemaElement("attributeOne", KeyType.HASH),
new KeySchemaElement("attributeTwo", KeyType.RANGE)
))
.withBillingMode(BillingMode.PAY_PER_REQUEST)))
.operationName("CreateTable")
.entityName(TABLE_NAME)
.action("query")
.withSpanAssertions(dbAssert)
.async()
.execute();
.withAttributeDefinitions(List.of(
new AttributeDefinition("attributeOne", ScalarAttributeType.S),
new AttributeDefinition("attributeTwo", ScalarAttributeType.N)
))
.withKeySchema(List.of(
new KeySchemaElement("attributeOne", KeyType.HASH),
new KeySchemaElement("attributeTwo", KeyType.RANGE)
))
.withBillingMode(BillingMode.PAY_PER_REQUEST)))
.operationName("CreateTable")
.entityName(TABLE_NAME)
.action("query")
.withSpanAssertions(dbAssert)
.async()
.execute();

newTest(() -> dynamoDBAsync.listTablesAsync())
.operationName("ListTables")
.action("query")
.withSpanAssertions(dbAssert)
.async()
.execute();
.operationName("ListTables")
.action("query")
.withSpanAssertions(dbAssert)
.async()
.execute();

newTest(() -> dynamoDBAsync.putItemAsync(
new PutItemRequest(TABLE_NAME,
Map.of("attributeOne", new AttributeValue("valueOne"), "attributeTwo", new AttributeValue().withN("10")))))
.operationName("PutItem")
.entityName(TABLE_NAME)
.action("query")
.withSpanAssertions(dbAssert)
.async()
.execute();
new PutItemRequest(TABLE_NAME,
Map.of("attributeOne", new AttributeValue("valueOne"), "attributeTwo", new AttributeValue().withN("10")))))
.operationName("PutItem")
.entityName(TABLE_NAME)
.action("query")
.withSpanAssertions(dbAssert)
.async()
.execute();

newTest(() -> dynamoDBAsync.queryAsync(
new QueryRequest(TABLE_NAME)
.withKeyConditionExpression(KEY_CONDITION_EXPRESSION)
.withExpressionAttributeValues(Map.of(":one", new AttributeValue("valueOne")))))
.operationName("Query")
.entityName(TABLE_NAME)
.action("query")
.withSpanAssertions(dbAssert
.andThen(span ->
assertThat(span.getContext().getDb()).hasStatement(KEY_CONDITION_EXPRESSION)))
.async()
.execute();
new QueryRequest(TABLE_NAME)
.withKeyConditionExpression(KEY_CONDITION_EXPRESSION)
.withExpressionAttributeValues(Map.of(":one", new AttributeValue("valueOne")))))
.operationName("Query")
.entityName(TABLE_NAME)
.action("query")
.withSpanAssertions(dbAssert
.andThen(span ->
assertThat(span.getContext().getDb()).hasStatement(KEY_CONDITION_EXPRESSION)))
.async()
.execute();

newTest(() -> dynamoDBAsync.deleteTableAsync(TABLE_NAME))
.operationName("DeleteTable")
.entityName(TABLE_NAME)
.action("query")
.withSpanAssertions(dbAssert)
.async()
.execute();
.operationName("DeleteTable")
.entityName(TABLE_NAME)
.action("query")
.withSpanAssertions(dbAssert)
.async()
.execute();

assertThat(reporter.getSpans().size()).isEqualTo(5);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,92 +36,92 @@
import static org.testcontainers.containers.localstack.LocalStackContainer.Service.S3;


public class S3ClientIT extends AbstractAwsClientIT {
public class S3ClientIT extends AbstractAws1ClientIT {

private AmazonS3 s3;

@BeforeEach
public void setupClient() {
s3 = AmazonS3Client.builder()
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(localstack.getEndpointOverride(LocalStackContainer.Service.S3).toString(), localstack.getRegion()))
.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(localstack.getAccessKey(), localstack.getSecretKey())))
.build();
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(localstack.getEndpointOverride(LocalStackContainer.Service.S3).toString(), localstack.getRegion()))
.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(localstack.getAccessKey(), localstack.getSecretKey())))
.build();
}

@Test
public void testS3Client() {
Transaction transaction = startTestRootTransaction("s3-test");

newTest(() -> s3.createBucket(BUCKET_NAME))
.operationName("CreateBucket")
.entityName(BUCKET_NAME)
.otelAttribute("aws.s3.bucket", BUCKET_NAME)
.execute();
.operationName("CreateBucket")
.entityName(BUCKET_NAME)
.otelAttribute("aws.s3.bucket", BUCKET_NAME)
.execute();

newTest(() -> s3.createBucket(NEW_BUCKET_NAME))
.operationName("CreateBucket")
.entityName(NEW_BUCKET_NAME)
.otelAttribute("aws.s3.bucket", NEW_BUCKET_NAME)
.execute();
.operationName("CreateBucket")
.entityName(NEW_BUCKET_NAME)
.otelAttribute("aws.s3.bucket", NEW_BUCKET_NAME)
.execute();

newTest(() -> s3.listBuckets())
.operationName("ListBuckets")
.execute();
.operationName("ListBuckets")
.execute();

newTest(() -> s3.putObject(BUCKET_NAME, OBJECT_KEY, "This is some Object content"))
.operationName("PutObject")
.entityName(BUCKET_NAME)
.otelAttribute("aws.s3.bucket", BUCKET_NAME)
.otelAttribute("aws.s3.key", OBJECT_KEY)
.execute();
.operationName("PutObject")
.entityName(BUCKET_NAME)
.otelAttribute("aws.s3.bucket", BUCKET_NAME)
.otelAttribute("aws.s3.key", OBJECT_KEY)
.execute();

newTest(() -> s3.listObjects(BUCKET_NAME))
.operationName("ListObjects")
.entityName(BUCKET_NAME)
.otelAttribute("aws.s3.bucket", BUCKET_NAME)
.execute();
.operationName("ListObjects")
.entityName(BUCKET_NAME)
.otelAttribute("aws.s3.bucket", BUCKET_NAME)
.execute();

newTest(() -> s3.getObject(BUCKET_NAME, OBJECT_KEY))
.operationName("GetObject")
.entityName(BUCKET_NAME)
.otelAttribute("aws.s3.bucket", BUCKET_NAME)
.otelAttribute("aws.s3.key", OBJECT_KEY)
.execute();
.operationName("GetObject")
.entityName(BUCKET_NAME)
.otelAttribute("aws.s3.bucket", BUCKET_NAME)
.otelAttribute("aws.s3.key", OBJECT_KEY)
.execute();

newTest(() -> s3.copyObject(BUCKET_NAME, OBJECT_KEY, NEW_BUCKET_NAME, NEW_OBJECT_KEY))
.operationName("CopyObject")
.entityName(NEW_BUCKET_NAME)
.otelAttribute("aws.s3.bucket", NEW_BUCKET_NAME)
.otelAttribute("aws.s3.key", NEW_OBJECT_KEY)
.otelAttribute("aws.s3.copy_source", BUCKET_NAME + "/" + OBJECT_KEY)
.execute();
.operationName("CopyObject")
.entityName(NEW_BUCKET_NAME)
.otelAttribute("aws.s3.bucket", NEW_BUCKET_NAME)
.otelAttribute("aws.s3.key", NEW_OBJECT_KEY)
.otelAttribute("aws.s3.copy_source", BUCKET_NAME + "/" + OBJECT_KEY)
.execute();

newTest(() -> {
s3.deleteObject(BUCKET_NAME, OBJECT_KEY);
return null;
})
.operationName("DeleteObject")
.entityName(BUCKET_NAME)
.otelAttribute("aws.s3.bucket", BUCKET_NAME)
.otelAttribute("aws.s3.key", OBJECT_KEY)
.execute();
.operationName("DeleteObject")
.entityName(BUCKET_NAME)
.otelAttribute("aws.s3.bucket", BUCKET_NAME)
.otelAttribute("aws.s3.key", OBJECT_KEY)
.execute();


newTest(() -> {
s3.deleteBucket(BUCKET_NAME);
return null;
})
.operationName("DeleteBucket")
.entityName(BUCKET_NAME)
.otelAttribute("aws.s3.bucket", BUCKET_NAME)
.execute();
.operationName("DeleteBucket")
.entityName(BUCKET_NAME)
.otelAttribute("aws.s3.bucket", BUCKET_NAME)
.execute();

newTest(() -> s3.putObject(BUCKET_NAME + "-exception", OBJECT_KEY, "This is some Object content"))
.operationName("PutObject")
.entityName(BUCKET_NAME + "-exception")
.otelAttribute("aws.s3.bucket", BUCKET_NAME + "-exception")
.otelAttribute("aws.s3.key", OBJECT_KEY)
.executeWithException(AmazonS3Exception.class);
.operationName("PutObject")
.entityName(BUCKET_NAME + "-exception")
.otelAttribute("aws.s3.bucket", BUCKET_NAME + "-exception")
.otelAttribute("aws.s3.key", OBJECT_KEY)
.executeWithException(AmazonS3Exception.class);

assertThat(reporter.getSpans()).hasSize(10);

Expand Down
Loading

0 comments on commit 5762e50

Please sign in to comment.