Skip to content

Commit

Permalink
AWS: Remove AssertHelpers usage (#8937)
Browse files Browse the repository at this point in the history
  • Loading branch information
coded9 authored Oct 30, 2023
1 parent 7e9e02c commit 8bb52bc
Show file tree
Hide file tree
Showing 8 changed files with 257 additions and 310 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
package org.apache.iceberg.aws;

import java.util.Map;
import org.apache.iceberg.AssertHelpers;
import org.apache.iceberg.aws.s3.S3FileIOProperties;
import org.apache.iceberg.relocated.com.google.common.collect.Maps;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import software.amazon.awssdk.core.exception.SdkClientException;
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
Expand All @@ -39,11 +39,11 @@ public void testGlueEndpointOverride() {
properties.put(AwsProperties.GLUE_CATALOG_ENDPOINT, "https://unknown:1234");
AwsClientFactory factory = AwsClientFactories.from(properties);
GlueClient glueClient = factory.glue();
AssertHelpers.assertThrowsCause(
"Should refuse connection to unknown endpoint",
SdkClientException.class,
"Unable to execute HTTP request: unknown",
() -> glueClient.getDatabase(GetDatabaseRequest.builder().name("TEST").build()));
Assertions.assertThatThrownBy(
() -> glueClient.getDatabase(GetDatabaseRequest.builder().name("TEST").build()))
.cause()
.isInstanceOf(SdkClientException.class)
.hasMessageContaining("Unable to execute HTTP request: unknown");
}

@Test
Expand All @@ -52,11 +52,12 @@ public void testS3FileIoEndpointOverride() {
properties.put(S3FileIOProperties.ENDPOINT, "https://unknown:1234");
AwsClientFactory factory = AwsClientFactories.from(properties);
S3Client s3Client = factory.s3();
AssertHelpers.assertThrowsCause(
"Should refuse connection to unknown endpoint",
SdkClientException.class,
"Unable to execute HTTP request: bucket.unknown",
() -> s3Client.getObject(GetObjectRequest.builder().bucket("bucket").key("key").build()));
Assertions.assertThatThrownBy(
() ->
s3Client.getObject(GetObjectRequest.builder().bucket("bucket").key("key").build()))
.cause()
.isInstanceOf(SdkClientException.class)
.hasMessageContaining("Unable to execute HTTP request: bucket.unknown");
}

@Test
Expand All @@ -66,16 +67,15 @@ public void testS3FileIoCredentialsOverride() {
properties.put(S3FileIOProperties.SECRET_ACCESS_KEY, "unknown");
AwsClientFactory factory = AwsClientFactories.from(properties);
S3Client s3Client = factory.s3();
AssertHelpers.assertThrows(
"Should fail request because of bad access key",
S3Exception.class,
"The AWS Access Key Id you provided does not exist in our records",
() ->
s3Client.getObject(
GetObjectRequest.builder()
.bucket(AwsIntegTestUtil.testBucketName())
.key("key")
.build()));
Assertions.assertThatThrownBy(
() ->
s3Client.getObject(
GetObjectRequest.builder()
.bucket(AwsIntegTestUtil.testBucketName())
.key("key")
.build()))
.isInstanceOf(S3Exception.class)
.hasMessageContaining("The AWS Access Key Id you provided does not exist in our records");
}

@Test
Expand All @@ -84,10 +84,9 @@ public void testDynamoDbEndpointOverride() {
properties.put(AwsProperties.DYNAMODB_ENDPOINT, "https://unknown:1234");
AwsClientFactory factory = AwsClientFactories.from(properties);
DynamoDbClient dynamoDbClient = factory.dynamo();
AssertHelpers.assertThrowsCause(
"Should refuse connection to unknown endpoint",
SdkClientException.class,
"Unable to execute HTTP request: unknown",
dynamoDbClient::listTables);
Assertions.assertThatThrownBy(dynamoDbClient::listTables)
.cause()
.isInstanceOf(SdkClientException.class)
.hasMessageContaining("Unable to execute HTTP request: unknown");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.concurrent.ForkJoinPool;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.apache.iceberg.AssertHelpers;
import org.apache.iceberg.CatalogProperties;
import org.apache.iceberg.HasTableOperations;
import org.apache.iceberg.Schema;
Expand Down Expand Up @@ -105,27 +104,19 @@ public void testCreateNamespace() {
"namespace must be stored in DynamoDB",
namespace.toString(),
response.item().get("namespace").s());

AssertHelpers.assertThrows(
"should not create duplicated namespace",
AlreadyExistsException.class,
"already exists",
() -> catalog.createNamespace(namespace));
Assertions.assertThatThrownBy(() -> catalog.createNamespace(namespace))
.isInstanceOf(AlreadyExistsException.class)
.hasMessageContaining("already exists");
}

@Test
public void testCreateNamespaceBadName() {
AssertHelpers.assertThrows(
"should not create namespace with empty level",
ValidationException.class,
"must not be empty",
() -> catalog.createNamespace(Namespace.of("a", "", "b")));

AssertHelpers.assertThrows(
"should not create namespace with dot in level",
ValidationException.class,
"must not contain dot",
() -> catalog.createNamespace(Namespace.of("a", "b.c")));
Assertions.assertThatThrownBy(() -> catalog.createNamespace(Namespace.of("a", "", "b")))
.isInstanceOf(ValidationException.class)
.hasMessageContaining("must not be empty");
Assertions.assertThatThrownBy(() -> catalog.createNamespace(Namespace.of("a", "b.c")))
.isInstanceOf(ValidationException.class)
.hasMessageContaining("must not contain dot");
}

@Test
Expand Down Expand Up @@ -180,29 +171,23 @@ public void testCreateTable() {
"table must be stored in DynamoDB with namespace as sort key",
namespace.toString(),
response.item().get("namespace").s());

AssertHelpers.assertThrows(
"should not create duplicated table",
AlreadyExistsException.class,
"already exists",
() -> catalog.createTable(tableIdentifier, SCHEMA));
Assertions.assertThatThrownBy(() -> catalog.createTable(tableIdentifier, SCHEMA))
.isInstanceOf(AlreadyExistsException.class)
.hasMessageContaining("already exists");
}

@Test
public void testCreateTableBadName() {
Namespace namespace = Namespace.of(genRandomName());
catalog.createNamespace(namespace);
AssertHelpers.assertThrows(
"should not create table name with empty namespace",
ValidationException.class,
"Table namespace must not be empty",
() -> catalog.createTable(TableIdentifier.of(Namespace.empty(), "a"), SCHEMA));

AssertHelpers.assertThrows(
"should not create table name with dot",
ValidationException.class,
"must not contain dot",
() -> catalog.createTable(TableIdentifier.of(namespace, "a.b"), SCHEMA));
Assertions.assertThatThrownBy(
() -> catalog.createTable(TableIdentifier.of(Namespace.empty(), "a"), SCHEMA))
.isInstanceOf(ValidationException.class)
.hasMessageContaining("Table namespace must not be empty");
Assertions.assertThatThrownBy(
() -> catalog.createTable(TableIdentifier.of(namespace, "a.b"), SCHEMA))
.isInstanceOf(ValidationException.class)
.hasMessageContaining("must not contain dot");
}

@Test
Expand Down Expand Up @@ -243,15 +228,18 @@ public void testDropTable() {
.key(DynamoDbCatalog.tablePrimaryKey(tableIdentifier))
.build())
.hasItem());
AssertHelpers.assertThrows(
"metadata location should be deleted",
NoSuchKeyException.class,
() ->
s3.headObject(
HeadObjectRequest.builder()
.bucket(testBucket)
.key(metadataLocation.substring(testBucket.length() + 6)) // s3:// + end slash
.build()));
Assertions.assertThatThrownBy(
() ->
s3.headObject(
HeadObjectRequest.builder()
.bucket(testBucket)
.key(
metadataLocation.substring(
testBucket.length() + 6)) // s3:// + end slash
.build()))
.as("metadata location should be deleted")
.isInstanceOf(NoSuchKeyException.class)
.hasMessageContaining("not found");
}

@Test
Expand All @@ -263,18 +251,14 @@ public void testRenameTable() {
TableIdentifier tableIdentifier = TableIdentifier.of(namespace, genRandomName());
catalog.createTable(tableIdentifier, SCHEMA);
TableIdentifier tableIdentifier2 = TableIdentifier.of(namespace2, genRandomName());
Assertions.assertThatThrownBy(
() -> catalog.renameTable(TableIdentifier.of(namespace, "a"), tableIdentifier2))
.isInstanceOf(NoSuchTableException.class)
.hasMessageContaining("does not exist");

AssertHelpers.assertThrows(
"should not be able to rename a table not exist",
NoSuchTableException.class,
"does not exist",
() -> catalog.renameTable(TableIdentifier.of(namespace, "a"), tableIdentifier2));

AssertHelpers.assertThrows(
"should not be able to rename an existing table",
AlreadyExistsException.class,
"already exists",
() -> catalog.renameTable(tableIdentifier, tableIdentifier));
Assertions.assertThatThrownBy(() -> catalog.renameTable(tableIdentifier, tableIdentifier))
.isInstanceOf(AlreadyExistsException.class)
.hasMessageContaining("already exists");

String metadataLocation =
dynamo
Expand Down Expand Up @@ -404,7 +388,8 @@ public void testRegisterExistingTable() {
TableOperations ops = ((HasTableOperations) registeringTable).operations();
String metadataLocation = ((DynamoDbTableOperations) ops).currentMetadataLocation();
Assertions.assertThatThrownBy(() -> catalog.registerTable(identifier, metadataLocation))
.isInstanceOf(AlreadyExistsException.class);
.isInstanceOf(AlreadyExistsException.class)
.hasMessageContaining("already exists");
Assertions.assertThat(catalog.dropTable(identifier, true)).isTrue();
Assertions.assertThat(catalog.dropNamespace(namespace)).isTrue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
import java.util.concurrent.ForkJoinPool;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.apache.iceberg.AssertHelpers;
import org.apache.iceberg.CatalogProperties;
import org.apache.iceberg.aws.AwsClientFactories;
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
import org.apache.iceberg.relocated.com.google.common.collect.Maps;
import org.assertj.core.api.Assertions;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
Expand Down Expand Up @@ -227,11 +227,10 @@ public void testTableCreationFailure() {
Mockito.doThrow(ResourceNotFoundException.class)
.when(dynamo2)
.describeTable(Mockito.any(DescribeTableRequest.class));
AssertHelpers.assertThrows(
"should fail to initialize the lock manager",
IllegalStateException.class,
"Cannot find Dynamo table",
() -> new DynamoDbLockManager(dynamo2, lockTableName));
Assertions.assertThatThrownBy(() -> new DynamoDbLockManager(dynamo2, lockTableName))
.as("should fail to initialize the lock manager")
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining("Cannot find Dynamo table");
}

private static String genTableName() {
Expand Down
Loading

0 comments on commit 8bb52bc

Please sign in to comment.