Skip to content

Commit

Permalink
Simplify PhysicalAddressCreator selection
Browse files Browse the repository at this point in the history
  • Loading branch information
arielshaqed committed Nov 24, 2024
1 parent f56b541 commit 71cb74b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,15 @@ public static Iterable<Object[]> data() {
{new PresignedPhysicalAddressCreator(), "presigned"}});
}

@Parameter(0)
public PhysicalAddressCreator pac;

@Parameter(1)
public String unusedAddressCreatorType;

@Parameter(0)
public PhysicalAddressCreator pacParam;

@Override
// pac is defined in a superclass but parametrized here.
protected void setPac() {
pac = pacParam;
LOG.info("Set pac!");
protected PhysicalAddressCreator getPac() {
return pac;
}

@Test
Expand Down Expand Up @@ -115,7 +113,7 @@ public void testMkdirs() throws IOException {
mockGetPhysicalAddress("repo", "main", "dir1/dir2/dir3/", "repo-base/emptyDir");

ObjectStats newStats = makeObjectStats("dir1/dir2/dir3/")
.physicalAddress(pac.createGetPhysicalAddress(this, "repo-base/dir12"));
.physicalAddress(getPac().createGetPhysicalAddress(this, "repo-base/dir12"));
mockStatObject("repo", "main", "dir1/dir2/dir3/", newStats);

mockServerClient.when(request()
Expand Down Expand Up @@ -144,7 +142,7 @@ public void testCreateExistingDirectory() throws IOException {

mockStatObjectNotFound("repo", "main", "sub1/sub2/create.me");
ObjectStats stats = makeObjectStats("sub1/sub2/create.me/")
.physicalAddress(pac.createGetPhysicalAddress(this, "repo-base/sub1/sub2/create.me"));
.physicalAddress(getPac().createGetPhysicalAddress(this, "repo-base/sub1/sub2/create.me"));
mockStatObject("repo", "main", "sub1/sub2/create.me/", stats);

Exception e =
Expand All @@ -169,7 +167,7 @@ public void testOpen() throws IOException, ApiException {
String contents = "The quick brown fox jumps over the lazy dog.";
byte[] contentsBytes = contents.getBytes();
String physicalPath = sessionId() + "/repo-base/open";
String physicalKey = pac.createGetPhysicalAddress(this, physicalPath);
String physicalKey = getPac().createGetPhysicalAddress(this, physicalPath);
int readBufferSize = 5;
Path path = new Path("lakefs://repo/main/read.me");

Expand Down Expand Up @@ -220,7 +218,7 @@ public void testOpenWithInvalidUriChars() throws IOException, ApiException {

String path = String.format("lakefs://repo/main/%s-x", suffix);
ObjectStats stats = makeObjectStats(suffix + "-x")
.physicalAddress(pac.createGetPhysicalAddress(this, key))
.physicalAddress(getPac().createGetPhysicalAddress(this, key))
.sizeBytes((long) contentsBytes.length);
mockStatObject("repo", "main", suffix + "-x", stats);

Expand Down
9 changes: 3 additions & 6 deletions clients/hadoopfs/src/test/java/io/lakefs/S3FSTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@
public abstract class S3FSTestBase extends FSTestBase {
static private final Logger LOG = LoggerFactory.getLogger(S3FSTestBase.class);

protected PhysicalAddressCreator pac = new SimplePhysicalAddressCreator();

protected String s3Endpoint;
protected AmazonS3 s3Client;

Expand Down Expand Up @@ -127,18 +125,17 @@ protected void assertS3Object(StagingLocation stagingLocation, String contents)
}
}

protected void setPac() {}
protected abstract PhysicalAddressCreator getPac();

protected void moreHadoopSetup() {
setPac();
s3ClientSetup();

conf.set("fs.s3a.impl", "org.apache.hadoop.fs.s3a.S3AFileSystem");
conf.set(org.apache.hadoop.fs.s3a.Constants.ACCESS_KEY, S3_ACCESS_KEY_ID);
conf.set(org.apache.hadoop.fs.s3a.Constants.SECRET_KEY, S3_SECRET_ACCESS_KEY);
conf.set(org.apache.hadoop.fs.s3a.Constants.ENDPOINT, s3Endpoint);
conf.set(org.apache.hadoop.fs.s3a.Constants.BUFFER_DIR, "/tmp/s3a");
pac.initConfiguration(conf);
getPac().initConfiguration(conf);

LOG.info("Setup done!");
}
Expand Down Expand Up @@ -196,7 +193,7 @@ public StagingLocation createPutStagingLocation(S3FSTestBase o, String namespace
// Return a location under namespace for this getPhysicalAddress call.
protected StagingLocation mockGetPhysicalAddress(String repo, String branch, String path, String namespace) {
StagingLocation stagingLocation =
pac.createPutStagingLocation(this, namespace, repo, branch, path);
getPac().createPutStagingLocation(this, namespace, repo, branch, path);
mockServerClient.when(request()
.withMethod("GET")
.withPath(String.format("/repositories/%s/branches/%s/staging/backing", repo, branch))
Expand Down

0 comments on commit 71cb74b

Please sign in to comment.