Skip to content

Commit

Permalink
Fix apache#3728 AWS S3 integration test should remove all objects in …
Browse files Browse the repository at this point in the history
…finally block (apache#3729)
  • Loading branch information
zhfeng authored and ppalaga committed Apr 22, 2022
1 parent 275a9f9 commit 90f818b
Showing 1 changed file with 63 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,47 +164,51 @@ public void testKms() throws Exception {
final String oid = UUID.randomUUID().toString();
final String blobContent = "Hello KMS " + oid;

// Create
RestAssured.given()
.contentType(ContentType.TEXT)
.body(blobContent)
.post("/aws2/s3/object/" + oid + "?useKms=true")
.then()
.statusCode(201);

// Read
RestAssured.get("/aws2/s3/object/" + oid + "?useKms=true")
.then()
.statusCode(200)
.body(is(blobContent));
try {
// Create
RestAssured.given()
.contentType(ContentType.TEXT)
.body(blobContent)
.post("/aws2/s3/object/" + oid + "?useKms=true")
.then()
.statusCode(201);

// Delete
deleteObject(oid);
// Read
RestAssured.get("/aws2/s3/object/" + oid + "?useKms=true")
.then()
.statusCode(200)
.body(is(blobContent));
} finally {
// Delete
deleteObject(oid);
}
}

@Test
public void upload() throws Exception {
final String oid = UUID.randomUUID().toString();
final String content = RandomStringUtils.randomAlphabetic(8 * 1024 * 1024);

RestAssured.given()
.contentType(ContentType.TEXT)
.body(content)
.post("/aws2/s3/upload/" + oid)
.then()
.statusCode(200);

String result = RestAssured.get("/aws2/s3/object/" + oid)
.then()
.statusCode(200)
.extract().asString();
try {
RestAssured.given()
.contentType(ContentType.TEXT)
.body(content)
.post("/aws2/s3/upload/" + oid)
.then()
.statusCode(200);

// Delete
deleteObject(oid);
String result = RestAssured.get("/aws2/s3/object/" + oid)
.then()
.statusCode(200)
.extract().asString();

// strip the chuck-signature
result = result.replaceAll("\\s*[0-9]+;chunk-signature=\\w{64}\\s*", "");
assertEquals(content, result);
// strip the chuck-signature
result = result.replaceAll("\\s*[0-9]+;chunk-signature=\\w{64}\\s*", "");
assertEquals(content, result);
} finally {
// Delete
deleteObject(oid);
}
}

@Test
Expand Down Expand Up @@ -284,39 +288,44 @@ public void downloadLink() throws Exception {
final String oid = UUID.randomUUID().toString();
final String blobContent = "Hello " + oid;

// Create
createObject(oid, blobContent);
try {
// Create
createObject(oid, blobContent);

// Download link
RestAssured.given()
.contentType(ContentType.TEXT)
.get("/aws2/s3/downloadlink/" + oid)
.then()
.statusCode(200);
// Download link
RestAssured.given()
.contentType(ContentType.TEXT)
.get("/aws2/s3/downloadlink/" + oid)
.then()
.statusCode(200);

// Delete
deleteObject(oid);
} finally {
// Delete
deleteObject(oid);
}
}

@Test
public void objectRange() {
final String oid = UUID.randomUUID().toString();
final String blobContent = "Hello " + oid;

// Create
createObject(oid, blobContent);

// Object range
RestAssured.given()
.contentType(ContentType.TEXT)
.param("start", "0").param("end", "4")
.get("/aws2/s3/object/range/" + oid)
.then()
.statusCode(200)
.body(is("Hello"));
try {
// Create
createObject(oid, blobContent);

// Delete
deleteObject(oid);
// Object range
RestAssured.given()
.contentType(ContentType.TEXT)
.param("start", "0").param("end", "4")
.get("/aws2/s3/object/range/" + oid)
.then()
.statusCode(200)
.body(is("Hello"));
} finally {
// Delete
deleteObject(oid);
}
}

private void createObject(String oid, String blobContent) {
Expand Down

0 comments on commit 90f818b

Please sign in to comment.