You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by zh...@apache.org on 2021/11/10 13:03:02 UTC
[camel-quarkus] branch main updated: Fix #3276 to make sure all
objects have been deleted after each test in AWS2 S3 (#3279)
This is an automated email from the ASF dual-hosted git repository.
zhfeng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/main by this push:
new 7ede271 Fix #3276 to make sure all objects have been deleted after each test in AWS2 S3 (#3279)
7ede271 is described below
commit 7ede271611b98a676af724ce4d2543e94ffb6a0d
Author: Amos Feng <zh...@gmail.com>
AuthorDate: Wed Nov 10 21:01:46 2021 +0800
Fix #3276 to make sure all objects have been deleted after each test in AWS2 S3 (#3279)
---
.../camel/quarkus/component/aws2/Aws2S3Test.java | 52 ++++++++++++++++++++--
1 file changed, 49 insertions(+), 3 deletions(-)
diff --git a/integration-test-groups/aws2/aws2-s3/src/test/java/org/apache/camel/quarkus/component/aws2/Aws2S3Test.java b/integration-test-groups/aws2/aws2-s3/src/test/java/org/apache/camel/quarkus/component/aws2/Aws2S3Test.java
index 5c690e5..31d7446 100644
--- a/integration-test-groups/aws2/aws2-s3/src/test/java/org/apache/camel/quarkus/component/aws2/Aws2S3Test.java
+++ b/integration-test-groups/aws2/aws2-s3/src/test/java/org/apache/camel/quarkus/component/aws2/Aws2S3Test.java
@@ -26,8 +26,11 @@ import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import org.apache.camel.quarkus.test.support.aws2.Aws2TestResource;
import org.apache.commons.lang3.RandomStringUtils;
+import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertEquals;
@@ -35,6 +38,34 @@ import static org.junit.Assert.assertEquals;
@QuarkusTest
@QuarkusTestResource(Aws2TestResource.class)
class Aws2S3Test {
+ private int objects_num_before;
+ private int objects_num_after;
+
+ @BeforeEach
+ public void before() {
+ objects_num_before = getObjects().length;
+ }
+
+ @AfterEach
+ public void after(TestInfo testInfo) {
+
+ // Make sure all create objects have been deleted after test
+ objects_num_after = getObjects().length;
+ if (objects_num_after != objects_num_before) {
+ Assertions.fail("There is object leak after " + testInfo.getTestMethod().get().getName());
+ }
+ }
+
+ private String[] getObjects() {
+ final String[] objects = RestAssured.given()
+ .get("/aws2/s3/object-keys")
+ .then()
+ .statusCode(200)
+ .extract()
+ .body().as(String[].class);
+
+ return objects;
+ }
@Test
public void crud() {
@@ -148,9 +179,7 @@ class Aws2S3Test {
.body(is(blobContent));
// Delete
- RestAssured.delete("/aws2/s3/object/" + oid)
- .then()
- .statusCode(204);
+ deleteObject(oid);
}
@Test
@@ -170,6 +199,9 @@ class Aws2S3Test {
.statusCode(200)
.extract().asString();
+ // Delete
+ deleteObject(oid);
+
// strip the chuck-signature
result = result.replaceAll("\\s*[0-9]+;chunk-signature=\\w{64}\\s*", "");
assertEquals(content, result);
@@ -216,6 +248,9 @@ class Aws2S3Test {
.body(is(blobContent));
} finally {
+ // Delete oid1
+ deleteObject(oid1);
+
// Delete the object before deleting the bucket
try {
RestAssured.delete("/aws2/s3/bucket/" + destinationBucket + "/object/" + oid2)
@@ -259,6 +294,8 @@ class Aws2S3Test {
.then()
.statusCode(200);
+ // Delete
+ deleteObject(oid);
}
@Test
@@ -277,6 +314,9 @@ class Aws2S3Test {
.then()
.statusCode(200)
.body(is("Hello"));
+
+ // Delete
+ deleteObject(oid);
}
private void createObject(String oid, String blobContent) {
@@ -288,6 +328,12 @@ class Aws2S3Test {
.statusCode(201);
}
+ private void deleteObject(String oid) {
+ RestAssured.delete("/aws2/s3/object/" + oid)
+ .then()
+ .statusCode(204);
+ }
+
/**
* Do not forget to delete every bucket you create!
*