Skip to content

Commit

Permalink
Merge branch 'master' of github.com:apache/iceberg into fd-bump-pydantic
Browse files Browse the repository at this point in the history
  • Loading branch information
Fokko committed Jul 5, 2023
2 parents 8d89a9b + efd257a commit 5701bf2
Show file tree
Hide file tree
Showing 58 changed files with 1,944 additions and 1,141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
import org.apache.iceberg.util.SerializationUtil;
import org.assertj.core.api.Assertions;
import org.assertj.core.api.ThrowableAssert;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.AwsCredentials;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
Expand All @@ -45,23 +44,22 @@ public class TestAwsClientFactories {

@Test
public void testLoadDefault() {
Assert.assertEquals(
"default client should be singleton",
AwsClientFactories.defaultFactory(),
AwsClientFactories.defaultFactory());

Assert.assertTrue(
"should load default when not configured",
AwsClientFactories.from(Maps.newHashMap())
instanceof AwsClientFactories.DefaultAwsClientFactory);
Assertions.assertThat(AwsClientFactories.defaultFactory())
.as("default client should be singleton")
.isSameAs(AwsClientFactories.defaultFactory());

Assertions.assertThat(AwsClientFactories.from(Maps.newHashMap()))
.as("should load default when not configured")
.isInstanceOf(AwsClientFactories.DefaultAwsClientFactory.class);
}

@Test
public void testLoadCustom() {
Map<String, String> properties = Maps.newHashMap();
properties.put(AwsProperties.CLIENT_FACTORY, CustomFactory.class.getName());
Assert.assertTrue(
"should load custom class", AwsClientFactories.from(properties) instanceof CustomFactory);
Assertions.assertThat(AwsClientFactories.from(properties))
.as("should load custom class")
.isInstanceOf(CustomFactory.class);
}

@Test
Expand Down
92 changes: 43 additions & 49 deletions aws/src/test/java/org/apache/iceberg/aws/TestAwsProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
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.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
Expand Down Expand Up @@ -72,7 +71,7 @@ public void testS3FileIoAcl() {
Map<String, String> map = Maps.newHashMap();
map.put(AwsProperties.S3FILEIO_ACL, ObjectCannedACL.AUTHENTICATED_READ.toString());
AwsProperties properties = new AwsProperties(map);
Assert.assertEquals(ObjectCannedACL.AUTHENTICATED_READ, properties.s3FileIoAcl());
Assertions.assertThat(properties.s3FileIoAcl()).isEqualTo(ObjectCannedACL.AUTHENTICATED_READ);
}

@Test
Expand Down Expand Up @@ -148,9 +147,9 @@ public void testS3FileIoDefaultCredentialsConfiguration() {
Mockito.verify(mockS3ClientBuilder).credentialsProvider(awsCredentialsProviderCaptor.capture());
AwsCredentialsProvider capturedAwsCredentialsProvider = awsCredentialsProviderCaptor.getValue();

Assert.assertTrue(
"Should use default credentials if nothing is set",
capturedAwsCredentialsProvider instanceof DefaultCredentialsProvider);
Assertions.assertThat(capturedAwsCredentialsProvider)
.as("Should use default credentials if nothing is set")
.isInstanceOf(DefaultCredentialsProvider.class);
}

@Test
Expand All @@ -168,17 +167,16 @@ public void testS3FileIoBasicCredentialsConfiguration() {
Mockito.verify(mockS3ClientBuilder).credentialsProvider(awsCredentialsProviderCaptor.capture());
AwsCredentialsProvider capturedAwsCredentialsProvider = awsCredentialsProviderCaptor.getValue();

Assert.assertTrue(
"Should use basic credentials if access key ID and secret access key are set",
capturedAwsCredentialsProvider.resolveCredentials() instanceof AwsBasicCredentials);
Assert.assertEquals(
"The access key id should be the same as the one set by tag S3FILEIO_ACCESS_KEY_ID",
"key",
capturedAwsCredentialsProvider.resolveCredentials().accessKeyId());
Assert.assertEquals(
"The secret access key should be the same as the one set by tag S3FILEIO_SECRET_ACCESS_KEY",
"secret",
capturedAwsCredentialsProvider.resolveCredentials().secretAccessKey());
Assertions.assertThat(capturedAwsCredentialsProvider.resolveCredentials())
.as("Should use basic credentials if access key ID and secret access key are set")
.isInstanceOf(AwsBasicCredentials.class);
Assertions.assertThat(capturedAwsCredentialsProvider.resolveCredentials().accessKeyId())
.as("The access key id should be the same as the one set by tag S3FILEIO_ACCESS_KEY_ID")
.isEqualTo("key");
Assertions.assertThat(capturedAwsCredentialsProvider.resolveCredentials().secretAccessKey())
.as(
"The secret access key should be the same as the one set by tag S3FILEIO_SECRET_ACCESS_KEY")
.isEqualTo("secret");
}

@Test
Expand All @@ -197,17 +195,16 @@ public void testS3FileIoSessionCredentialsConfiguration() {
Mockito.verify(mockS3ClientBuilder).credentialsProvider(awsCredentialsProviderCaptor.capture());
AwsCredentialsProvider capturedAwsCredentialsProvider = awsCredentialsProviderCaptor.getValue();

Assert.assertTrue(
"Should use session credentials if session token is set",
capturedAwsCredentialsProvider.resolveCredentials() instanceof AwsSessionCredentials);
Assert.assertEquals(
"The access key id should be the same as the one set by tag S3FILEIO_ACCESS_KEY_ID",
"key",
capturedAwsCredentialsProvider.resolveCredentials().accessKeyId());
Assert.assertEquals(
"The secret access key should be the same as the one set by tag S3FILEIO_SECRET_ACCESS_KEY",
"secret",
capturedAwsCredentialsProvider.resolveCredentials().secretAccessKey());
Assertions.assertThat(capturedAwsCredentialsProvider.resolveCredentials())
.as("Should use session credentials if session token is set")
.isInstanceOf(AwsSessionCredentials.class);
Assertions.assertThat(capturedAwsCredentialsProvider.resolveCredentials().accessKeyId())
.as("The access key id should be the same as the one set by tag S3FILEIO_ACCESS_KEY_ID")
.isEqualTo("key");
Assertions.assertThat(capturedAwsCredentialsProvider.resolveCredentials().secretAccessKey())
.as(
"The secret access key should be the same as the one set by tag S3FILEIO_SECRET_ACCESS_KEY")
.isEqualTo("secret");
}

@Test
Expand All @@ -223,9 +220,9 @@ public void testUrlHttpClientConfiguration() {
Mockito.verify(mockS3ClientBuilder).httpClientBuilder(httpClientBuilderCaptor.capture());
SdkHttpClient.Builder capturedHttpClientBuilder = httpClientBuilderCaptor.getValue();

Assert.assertTrue(
"Should use url connection http client",
capturedHttpClientBuilder instanceof UrlConnectionHttpClient.Builder);
Assertions.assertThat(capturedHttpClientBuilder)
.as("Should use url connection http client")
.isInstanceOf(UrlConnectionHttpClient.Builder.class);
}

@Test
Expand All @@ -240,9 +237,9 @@ public void testApacheHttpClientConfiguration() {
awsProperties.applyHttpClientConfigurations(mockS3ClientBuilder);
Mockito.verify(mockS3ClientBuilder).httpClientBuilder(httpClientBuilderCaptor.capture());
SdkHttpClient.Builder capturedHttpClientBuilder = httpClientBuilderCaptor.getValue();
Assert.assertTrue(
"Should use apache http client",
capturedHttpClientBuilder instanceof ApacheHttpClient.Builder);
Assertions.assertThat(capturedHttpClientBuilder)
.as("Should use apache http client")
.isInstanceOf(ApacheHttpClient.Builder.class);
}

@Test
Expand All @@ -263,29 +260,26 @@ public void testKryoSerialization() throws IOException {
AwsProperties awsProperties = new AwsProperties();
AwsProperties deSerializedAwsProperties =
TestHelpers.KryoHelpers.roundTripSerialize(awsProperties);
Assert.assertEquals(
awsProperties.s3BucketToAccessPointMapping(),
deSerializedAwsProperties.s3BucketToAccessPointMapping());
Assert.assertEquals(
awsProperties.httpClientProperties(), deSerializedAwsProperties.httpClientProperties());
Assertions.assertThat(deSerializedAwsProperties.s3BucketToAccessPointMapping())
.isEqualTo(awsProperties.s3BucketToAccessPointMapping());
Assertions.assertThat(deSerializedAwsProperties.httpClientProperties())
.isEqualTo(awsProperties.httpClientProperties());

AwsProperties awsPropertiesWithProps = new AwsProperties(ImmutableMap.of("a", "b"));
AwsProperties deSerializedAwsPropertiesWithProps =
TestHelpers.KryoHelpers.roundTripSerialize(awsPropertiesWithProps);
Assert.assertEquals(
awsPropertiesWithProps.s3BucketToAccessPointMapping(),
deSerializedAwsPropertiesWithProps.s3BucketToAccessPointMapping());
Assert.assertEquals(
awsProperties.httpClientProperties(), deSerializedAwsProperties.httpClientProperties());
Assertions.assertThat(deSerializedAwsPropertiesWithProps.s3BucketToAccessPointMapping())
.isEqualTo(awsPropertiesWithProps.s3BucketToAccessPointMapping());
Assertions.assertThat(deSerializedAwsPropertiesWithProps.httpClientProperties())
.isEqualTo(awsProperties.httpClientProperties());

AwsProperties awsPropertiesWithEmptyProps = new AwsProperties(Collections.emptyMap());
AwsProperties deSerializedAwsPropertiesWithEmptyProps =
TestHelpers.KryoHelpers.roundTripSerialize(awsPropertiesWithProps);
Assert.assertEquals(
awsPropertiesWithEmptyProps.s3BucketToAccessPointMapping(),
deSerializedAwsPropertiesWithEmptyProps.s3BucketToAccessPointMapping());
Assert.assertEquals(
awsProperties.httpClientProperties(), deSerializedAwsProperties.httpClientProperties());
Assertions.assertThat(deSerializedAwsPropertiesWithEmptyProps.s3BucketToAccessPointMapping())
.isEqualTo(awsPropertiesWithEmptyProps.s3BucketToAccessPointMapping());
Assertions.assertThat(deSerializedAwsPropertiesWithEmptyProps.httpClientProperties())
.isEqualTo(awsProperties.httpClientProperties());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.time.Duration;
import java.util.Map;
import org.apache.iceberg.relocated.com.google.common.collect.Maps;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import software.amazon.awssdk.http.apache.ApacheHttpClient;
import software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
import org.apache.iceberg.rest.responses.ConfigResponse;
import org.apache.iceberg.rest.responses.OAuthTokenResponse;
import org.assertj.core.api.Assertions;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockserver.integration.ClientAndServer;
import org.mockserver.model.Header;
import org.mockserver.model.HttpRequest;
Expand All @@ -44,7 +44,7 @@ public class TestRESTSigV4Signer {
private static ClientAndServer mockServer;
private static HTTPClient client;

@BeforeClass
@BeforeAll
public static void beforeClass() {
mockServer = ClientAndServer.startClientAndServer();

Expand All @@ -66,13 +66,13 @@ public static void beforeClass() {
.build();
}

@AfterClass
@AfterAll
public static void afterClass() throws IOException {
mockServer.stop();
client.close();
}

@Before
@BeforeEach
public void before() {
mockServer.reset();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
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.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
Expand All @@ -44,7 +44,7 @@ public class TestDynamoDbCatalog {
private DynamoDbClient dynamo;
private DynamoDbCatalog dynamoCatalog;

@Before
@BeforeEach
public void before() {
dynamo = Mockito.mock(DynamoDbClient.class);
dynamoCatalog = new DynamoDbCatalog();
Expand Down
Loading

0 comments on commit 5701bf2

Please sign in to comment.