Skip to content

Commit

Permalink
Fix Tests and Refactor
Browse files Browse the repository at this point in the history
Fixed the test cases that where failing with the new method for retrieving S3 objects. Also refactored the ImageJ plugin somewhat.
  • Loading branch information
AvocadoMoon committed Oct 31, 2023
1 parent 0ae67b4 commit cbe8146
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 30 deletions.
41 changes: 18 additions & 23 deletions src/main/java/org/vcell/vcellfiji/N5ImageHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,32 @@ public void loadN5Dataset(String selectedDataset) throws IOException {
public void createS3Client(String url, HashMap<String, String> credentials, HashMap<String, String> endpoint){
AmazonS3ClientBuilder s3ClientBuilder = AmazonS3ClientBuilder.standard();
URI uri = URI.create(url);
String defaultRegion = "site2-low";

if(credentials != null){
s3ClientBuilder.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(credentials.get("AccessKey"), credentials.get("SecretKey"))));
}

// believe that it's a s3 URL
try{
AmazonS3URI s3URI = new AmazonS3URI(uri);
this.s3ObjectKey = s3URI.getKey();
this.bucketName = s3URI.getBucket();
defaultRegion = s3URI.getRegion();
if(s3URI.isPathStyle()){
s3ClientBuilder.withPathStyleAccessEnabled(true);
}
if(endpoint != null){
s3ClientBuilder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint.get("Endpoint"), endpoint.get("Region")));
this.s3Client = s3ClientBuilder.build();
return;
}
// if nothing is given, default user and return so that code after if statement does not execute
if(endpoint == null && credentials == null){
this.s3Client = AmazonS3ClientBuilder.standard().withRegion(s3URI.getRegion()).withCredentials(new AWSStaticCredentialsProvider(new AnonymousAWSCredentials())).build();
return;
}
//creds not null, but region is
this.s3Client = s3ClientBuilder.withRegion(s3URI.getRegion()).build();
return;
}
// otherwise assume it is one of our URLs
// http://vcell:8000/bucket/object/object2
Expand All @@ -193,30 +208,10 @@ public void createS3Client(String url, HashMap<String, String> credentials, Hash
this.s3ObjectKey = pathSubStrings[2];
this.bucketName = pathSubStrings[1];
s3ClientBuilder.withPathStyleAccessEnabled(true);
s3ClientBuilder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(uri.getScheme() + "://" + uri.getAuthority(), defaultRegion));
if(credentials != null){
s3ClientBuilder.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(credentials.get("AccessKey"), credentials.get("SecretKey"))));
}
this.s3Client = s3ClientBuilder.build();
return;
}

if(credentials != null){
s3ClientBuilder.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(credentials.get("AccessKey"), credentials.get("SecretKey"))));
}
if(endpoint != null){
s3ClientBuilder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint.get("Endpoint"), endpoint.get("Region")));
s3ClientBuilder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(uri.getScheme() + "://" + uri.getAuthority(), "site2-low"));
this.s3Client = s3ClientBuilder.build();
return;
}
// if nothing is given, default user and return so that code after if statement does not execute
if(endpoint == null && credentials == null){
this.s3Client = AmazonS3ClientBuilder.standard().withRegion(defaultRegion).withCredentials(new AWSStaticCredentialsProvider(new AnonymousAWSCredentials())).build();
return;
}

//creds not null, but region is
this.s3Client = s3ClientBuilder.withRegion(defaultRegion).build();
}


Expand Down
14 changes: 7 additions & 7 deletions src/test/java/org/vcell/vcellfiji/N5ImageHandlerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,22 @@ public void testS3Client() throws IOException {
credentials.put("AccessKey", "jj");
credentials.put("SecretKey", "jj");

final String s3ProxyURL = "/" + this.n5FileName;
final String s3ProxyURI = "http://localhost:4000/" + this.n5FileName;

N5ImageHandler n5ImageHandler = new N5ImageHandler();

// Environment variables are set in github actions VM

// n5ImageHandler.createS3Client(s3ProxyURL, null, null);
// this.remoteN5ImgPlusTests(n5ImageHandler);
n5ImageHandler.createS3Client(s3ProxyURI, null, null);
this.remoteN5ImgPlusTests(n5ImageHandler);

n5ImageHandler.createS3Client(s3ProxyURL, null, s3Endpoint);
n5ImageHandler.createS3Client(s3ProxyURI, null, s3Endpoint);
this.remoteN5ImgPlusTests(n5ImageHandler);

// n5ImageHandler.createS3Client(s3ProxyURL, credentials, null);
// this.remoteN5ImgPlusTests(n5ImageHandler);
n5ImageHandler.createS3Client(s3ProxyURI, credentials, null);
this.remoteN5ImgPlusTests(n5ImageHandler);

n5ImageHandler.createS3Client(s3ProxyURL, credentials, s3Endpoint);
n5ImageHandler.createS3Client(s3ProxyURI, credentials, s3Endpoint);
this.remoteN5ImgPlusTests(n5ImageHandler);
}

Expand Down

0 comments on commit cbe8146

Please sign in to comment.