This is an automated email from the ASF dual-hosted git repository. asf-gitbox-commits pushed a commit to branch geoapi-4.0 in repository https://gitbox.apache.org/repos/asf/sis.git
commit cc7642ab5749e60953b18219f355a7c37ec2ce93 Author: Martin Desruisseaux <[email protected]> AuthorDate: Tue Jun 23 17:26:09 2026 +0200 Use an arbitrary region during S3 tests for avoiding the following exception thrown by AWS SDK on machines having no `~/.aws/credentials` file: "Unable to load region from system settings. Region must be specified either via environment variable (AWS_REGION) or system property (aws.region)." --- .../org/apache/sis/cloud/aws/s3/ClientFileSystem.java | 13 ------------- .../apache/sis/cloud/aws/s3/ClientFileSystemTest.java | 17 +++++++++++++++-- .../org/apache/sis/cloud/aws/s3/FileServiceTest.java | 10 +++++++--- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/endorsed/src/org.apache.sis.cloud.aws/main/org/apache/sis/cloud/aws/s3/ClientFileSystem.java b/endorsed/src/org.apache.sis.cloud.aws/main/org/apache/sis/cloud/aws/s3/ClientFileSystem.java index ea90b1d19b..0eef551cf4 100644 --- a/endorsed/src/org.apache.sis.cloud.aws/main/org/apache/sis/cloud/aws/s3/ClientFileSystem.java +++ b/endorsed/src/org.apache.sis.cloud.aws/main/org/apache/sis/cloud/aws/s3/ClientFileSystem.java @@ -83,19 +83,6 @@ final class ClientFileSystem extends FileSystem { */ final String duplicatedSeparator; - /** - * Creates a file system with default credential and default separator. - * This constructor assumes that the given {@code server} argument has no host and no port. - * That argument should have been created with {@link Server#Server(String)} constructor. - */ - ClientFileSystem(final FileService provider, final Server server) { - this.provider = provider; - this.server = server; - this.client = S3Client.create(); - this.separator = DEFAULT_SEPARATOR; - duplicatedSeparator = DEFAULT_SEPARATOR + DEFAULT_SEPARATOR; - } - /** * Creates a new file system with the specified credential. * diff --git a/endorsed/src/org.apache.sis.cloud.aws/test/org/apache/sis/cloud/aws/s3/ClientFileSystemTest.java b/endorsed/src/org.apache.sis.cloud.aws/test/org/apache/sis/cloud/aws/s3/ClientFileSystemTest.java index c306599dda..49eaf11363 100644 --- a/endorsed/src/org.apache.sis.cloud.aws/test/org/apache/sis/cloud/aws/s3/ClientFileSystemTest.java +++ b/endorsed/src/org.apache.sis.cloud.aws/test/org/apache/sis/cloud/aws/s3/ClientFileSystemTest.java @@ -17,6 +17,7 @@ package org.apache.sis.cloud.aws.s3; import java.net.URISyntaxException; +import software.amazon.awssdk.regions.Region; // Test dependencies import org.junit.jupiter.api.Test; @@ -38,6 +39,16 @@ public final class ClientFileSystemTest extends TestCase { public ClientFileSystemTest() { } + /** + * Returns an arbitrary region for testing purpose. + * This is for avoiding the <abbr>AWS</abbr> <abbr>SDK</abbr> exception saying + * "Unable to load region from system settings. Region must be specified either via + * environment variable ({@code AWS_REGION}) or system property ({@code aws.region})." + */ + static Region region() { + return Region.of("eu-central-1"); + } + /** * Returns the file system to use for testing purpose. * @@ -46,11 +57,13 @@ public final class ClientFileSystemTest extends TestCase { */ static ClientFileSystem create(final boolean selfHosted) throws URISyntaxException { final var fs = new FileService(); + final Server server; if (selfHosted) { - return new ClientFileSystem(fs, null, new Server(null, "testhost", 8581, true, null), null, null); + server = new Server(null, "testhost", 8581, true, null); } else { - return new ClientFileSystem(fs, new Server(null)); + server = new Server(null); } + return new ClientFileSystem(fs, region(), server, null, null); } /** diff --git a/endorsed/src/org.apache.sis.cloud.aws/test/org/apache/sis/cloud/aws/s3/FileServiceTest.java b/endorsed/src/org.apache.sis.cloud.aws/test/org/apache/sis/cloud/aws/s3/FileServiceTest.java index ea6ea97e20..4777f2769f 100644 --- a/endorsed/src/org.apache.sis.cloud.aws/test/org/apache/sis/cloud/aws/s3/FileServiceTest.java +++ b/endorsed/src/org.apache.sis.cloud.aws/test/org/apache/sis/cloud/aws/s3/FileServiceTest.java @@ -80,7 +80,8 @@ public final class FileServiceTest extends TestCase { @Test public void testNewFileSystemAws() throws URISyntaxException, IOException { newFileSystem(new URI("S3://accessKey@bucket/file"), true, - Map.of(FileService.AWS_SECRET_ACCESS_KEY, "secret")); + Map.of(FileService.AWS_REGION, ClientFileSystemTest.region(), + FileService.AWS_SECRET_ACCESS_KEY, "secret")); } /** @@ -92,7 +93,8 @@ public final class FileServiceTest extends TestCase { @Test public void testNewFileSystemSelfHosted() throws URISyntaxException, IOException { newFileSystem(new URI("S3://accessKey@localhost:8080/bucket/file"), true, - Map.of(FileService.AWS_SECRET_ACCESS_KEY, "secret")); + Map.of(FileService.AWS_REGION, ClientFileSystemTest.region(), + FileService.AWS_SECRET_ACCESS_KEY, "secret")); } /** @@ -105,6 +107,7 @@ public final class FileServiceTest extends TestCase { public void testNewFileSystemSelfHostedWithPropertiesNoPort() throws URISyntaxException, IOException { final var uri = new URI("S3://accessKey@bucket/file"); final ClientFileSystem fs = newFileSystem(uri, false, Map.of( + FileService.AWS_REGION, ClientFileSystemTest.region(), FileService.AWS_SECRET_ACCESS_KEY, "secret", FileService.HOST_URL, "localhost", FileService.IS_HTTPS, Boolean.FALSE)); @@ -128,6 +131,7 @@ public final class FileServiceTest extends TestCase { public void testNewFileSystemSelfHostedWithProperties() throws URISyntaxException, IOException { final URI uri = new URI("S3://accessKey@bucket/file"); final ClientFileSystem fs = newFileSystem(uri, false, Map.of( + FileService.AWS_REGION, ClientFileSystemTest.region(), FileService.AWS_SECRET_ACCESS_KEY, "secret", FileService.HOST_URL, "localhost", FileService.PORT, 8454, @@ -149,7 +153,7 @@ public final class FileServiceTest extends TestCase { */ @Test public void testMissingSecretKey() throws URISyntaxException { - final Map<String, Object> properties = Map.of(); + final Map<String, Object> properties = Map.of(FileService.AWS_REGION, ClientFileSystemTest.region()); final var uri = new URI("S3://accessKey@bucket/file"); var exception = assertThrows(IllegalArgumentException.class, () -> { service.newFileSystem(uri, properties);
