Skip to content

Commit

Permalink
fix: Properties were not correctly passed down to the S3FileSystem. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-todorov authored Nov 6, 2024
1 parent e359b1f commit 6d1d921
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/main/java/org/carlspring/cloud/storage/s3fs/S3FileSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ public int getCache()
return cache;
}

/**
* Used for internal testing.
* @return the properties with which this file system was initialized.
*/
protected Properties getProperties()
{
Properties copy = new Properties();
copy.putAll(properties);
return copy;
}

/**
* @return The value of the {@link S3Factory#REQUEST_HEADER_CACHE_CONTROL} property. Default is empty.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,8 @@ public S3FileSystem createFileSystem(URI uri,
final String key = getFileSystemKey(uri, props);
final S3Client client = getS3Client(uri, props);
final String host = uri.getHost();
final Properties properties = new Properties(props);
final Properties properties = new Properties();
properties.putAll(props);
return new S3FileSystem(this, key, client, host, properties);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.nio.file.attribute.PosixFilePermissions;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import com.google.common.collect.ImmutableMap;
Expand All @@ -26,7 +27,13 @@
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.S3Utilities;
import software.amazon.awssdk.services.s3.model.GetUrlRequest;

import static org.assertj.core.api.Assertions.assertThat;
import static org.carlspring.cloud.storage.s3fs.S3Factory.ACCESS_KEY;
import static org.carlspring.cloud.storage.s3fs.S3Factory.CONNECTION_TIMEOUT;
import static org.carlspring.cloud.storage.s3fs.S3Factory.MAX_CONNECTIONS;
import static org.carlspring.cloud.storage.s3fs.S3Factory.REGION;
import static org.carlspring.cloud.storage.s3fs.S3Factory.REQUEST_HEADER_CACHE_CONTROL;
import static org.carlspring.cloud.storage.s3fs.S3Factory.SECRET_KEY;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand Down Expand Up @@ -326,6 +333,17 @@ void comparables()
s3fs11.close();
}

@Test
void propertiesMustBePreserved()
{
S3FileSystemProvider provider = new S3FileSystemProvider();

Map<String, ?> inputProps = buildFakeEnv();
S3FileSystem s3fs1 = (S3FileSystem) provider.newFileSystem(URI.create("s3://mirror1.amazon.test/"), inputProps);
Properties outputProps = s3fs1.getProperties();
assertThat(outputProps).containsAllEntriesOf(inputProps);
}

@Test
void key2Parts()
throws IOException
Expand Down Expand Up @@ -458,9 +476,15 @@ void isSameFile()

private Map<String, ?> buildFakeEnv()
{
return ImmutableMap.<String, Object>builder().put(ACCESS_KEY, "access-key")
.put(SECRET_KEY, "secret-key")
.build();
return ImmutableMap.<String, Object>builder()
//.put("s3fs.amazon.s3.factory.class", S3MockFactory.class)
.put(ACCESS_KEY, "access-key")
.put(SECRET_KEY, "secret-key")
.put(MAX_CONNECTIONS, "1000")
.put(CONNECTION_TIMEOUT, "2000")
.put(REQUEST_HEADER_CACHE_CONTROL, "no-cache")
.put(REGION, "eu-west-1")
.build();
}

}

0 comments on commit 6d1d921

Please sign in to comment.