This is an automated email from the ASF dual-hosted git repository.

quantranhong1999 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 0428a28c1326fc10f5699d77973369dd19a15812
Author: Benoit TELLIER <[email protected]>
AuthorDate: Thu Sep 17 09:42:29 2026 +0200

    [BUILD] S3: Reuse driver accross tests
---
 .../aws/S3DeDuplicationBlobStoreTest.java          | 37 +++++++++++---------
 .../aws/S3PrefixAndNamespaceTest.java              | 38 +++++++++++---------
 .../aws/S3WithMinIOGenerationAwareBlobIdTest.java  | 40 ++++++++++++++--------
 3 files changed, 67 insertions(+), 48 deletions(-)

diff --git 
a/server/blob/blob-s3/src/test/java/org/apache/james/blob/objectstorage/aws/S3DeDuplicationBlobStoreTest.java
 
b/server/blob/blob-s3/src/test/java/org/apache/james/blob/objectstorage/aws/S3DeDuplicationBlobStoreTest.java
index 24beccdcba..24c7ca2843 100644
--- 
a/server/blob/blob-s3/src/test/java/org/apache/james/blob/objectstorage/aws/S3DeDuplicationBlobStoreTest.java
+++ 
b/server/blob/blob-s3/src/test/java/org/apache/james/blob/objectstorage/aws/S3DeDuplicationBlobStoreTest.java
@@ -32,8 +32,9 @@ import org.apache.james.blob.api.PlainBlobId;
 import org.apache.james.metrics.api.NoopGaugeRegistry;
 import org.apache.james.metrics.tests.RecordingMetricFactory;
 import org.apache.james.server.blob.deduplication.BlobStoreFactory;
+import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 
@@ -42,19 +43,12 @@ import reactor.core.publisher.Flux;
 @ExtendWith(DockerAwsS3Extension.class)
 class S3DeDuplicationBlobStoreTest implements BlobStoreContract, 
DeduplicationBlobStoreContract {
 
-    private BlobStore testee;
-    private DockerAwsS3Container dockerAwsS3;
-    private S3BlobStoreDAO s3BlobStoreDAO;
-    private S3ClientFactory s3ClientFactory;
+    private static BlobStore testee;
+    private static S3BlobStoreDAO s3BlobStoreDAO;
+    private static S3ClientFactory s3ClientFactory;
 
-    @BeforeEach
-    void setUpClass(DockerAwsS3Container dockerAwsS3) {
-        this.dockerAwsS3 = dockerAwsS3;
-        testee = createBlobStore();
-    }
-
-    @Override
-    public BlobStore createBlobStore() {
+    @BeforeAll
+    static void setUpClass(DockerAwsS3Container dockerAwsS3) {
         AwsS3AuthConfiguration authConfiguration = 
AwsS3AuthConfiguration.builder()
                 .endpoint(dockerAwsS3.getEndpoint())
                 .accessKeyId(DockerAwsS3Container.ACCESS_KEY_ID)
@@ -66,13 +60,20 @@ class S3DeDuplicationBlobStoreTest implements 
BlobStoreContract, DeduplicationBl
                 .region(dockerAwsS3.dockerAwsS3().region())
                 .build();
 
-        PlainBlobId.Factory blobIdFactory = new PlainBlobId.Factory();
         s3ClientFactory = new S3ClientFactory(s3Configuration, new 
RecordingMetricFactory(), new NoopGaugeRegistry());
-        s3BlobStoreDAO = new S3BlobStoreDAO(s3ClientFactory, s3Configuration, 
blobIdFactory, S3RequestOption.DEFAULT);
+        s3BlobStoreDAO = new S3BlobStoreDAO(s3ClientFactory, s3Configuration, 
new PlainBlobId.Factory(), S3RequestOption.DEFAULT);
+        testee = createBlobStore(s3BlobStoreDAO);
+    }
 
+    @Override
+    public BlobStore createBlobStore() {
+        return createBlobStore(s3BlobStoreDAO);
+    }
+
+    private static BlobStore createBlobStore(S3BlobStoreDAO s3BlobStoreDAO) {
         return BlobStoreFactory.builder()
                 .blobStoreDAO(s3BlobStoreDAO)
-                .blobIdFactory(blobIdFactory)
+                .blobIdFactory(new PlainBlobId.Factory())
                 .defaultBucketName()
                 .deduplication();
     }
@@ -91,6 +92,10 @@ class S3DeDuplicationBlobStoreTest implements 
BlobStoreContract, DeduplicationBl
     @AfterEach
     void tearDown() {
         s3BlobStoreDAO.deleteAllBuckets().block();
+    }
+
+    @AfterAll
+    static void tearDownClass() {
         s3ClientFactory.close();
     }
 
diff --git 
a/server/blob/blob-s3/src/test/java/org/apache/james/blob/objectstorage/aws/S3PrefixAndNamespaceTest.java
 
b/server/blob/blob-s3/src/test/java/org/apache/james/blob/objectstorage/aws/S3PrefixAndNamespaceTest.java
index 99183da991..053e5d95b7 100644
--- 
a/server/blob/blob-s3/src/test/java/org/apache/james/blob/objectstorage/aws/S3PrefixAndNamespaceTest.java
+++ 
b/server/blob/blob-s3/src/test/java/org/apache/james/blob/objectstorage/aws/S3PrefixAndNamespaceTest.java
@@ -28,26 +28,19 @@ import org.apache.james.blob.api.PlainBlobId;
 import org.apache.james.metrics.api.NoopGaugeRegistry;
 import org.apache.james.metrics.tests.RecordingMetricFactory;
 import org.apache.james.server.blob.deduplication.BlobStoreFactory;
+import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.extension.ExtendWith;
 
 @ExtendWith(DockerAwsS3Extension.class)
 class S3PrefixAndNamespaceTest implements BlobStoreContract, 
DeduplicationBlobStoreContract {
-    private BlobStore testee;
-    private S3BlobStoreDAO s3BlobStoreDAO;
+    private static BlobStore testee;
+    private static S3BlobStoreDAO s3BlobStoreDAO;
+    private static S3ClientFactory s3ClientFactory;
 
-    private S3ClientFactory s3ClientFactory;
-    private DockerAwsS3Container dockerAwsS3;
-
-    @BeforeEach
-    void setUpClass(DockerAwsS3Container dockerAwsS3) {
-        this.dockerAwsS3 = dockerAwsS3;
-        this.testee = createBlobStore();
-    }
-
-    @Override
-    public BlobStore createBlobStore() {
+    @BeforeAll
+    static void setUpClass(DockerAwsS3Container dockerAwsS3) {
         AwsS3AuthConfiguration authConfiguration = 
AwsS3AuthConfiguration.builder()
                 .endpoint(dockerAwsS3.getEndpoint())
                 .accessKeyId(DockerAwsS3Container.ACCESS_KEY_ID)
@@ -61,13 +54,20 @@ class S3PrefixAndNamespaceTest implements 
BlobStoreContract, DeduplicationBlobSt
                 .bucketPrefix("prefix")
                 .build();
 
-        PlainBlobId.Factory blobIdFactory = new PlainBlobId.Factory();
         s3ClientFactory = new S3ClientFactory(s3Configuration, new 
RecordingMetricFactory(), new NoopGaugeRegistry());
-        s3BlobStoreDAO = new S3BlobStoreDAO(s3ClientFactory, s3Configuration, 
blobIdFactory, S3RequestOption.DEFAULT);
+        s3BlobStoreDAO = new S3BlobStoreDAO(s3ClientFactory, s3Configuration, 
new PlainBlobId.Factory(), S3RequestOption.DEFAULT);
+        testee = createBlobStore(s3BlobStoreDAO);
+    }
 
+    @Override
+    public BlobStore createBlobStore() {
+        return createBlobStore(s3BlobStoreDAO);
+    }
+
+    private static BlobStore createBlobStore(S3BlobStoreDAO s3BlobStoreDAO) {
         return BlobStoreFactory.builder()
                 .blobStoreDAO(s3BlobStoreDAO)
-                .blobIdFactory(blobIdFactory)
+                .blobIdFactory(new PlainBlobId.Factory())
                 .bucket(BucketName.of("namespace"))
                 .deduplication();
     }
@@ -75,6 +75,10 @@ class S3PrefixAndNamespaceTest implements BlobStoreContract, 
DeduplicationBlobSt
     @AfterEach
     void tearDown() {
         s3BlobStoreDAO.deleteAllBuckets().block();
+    }
+
+    @AfterAll
+    static void tearDownClass() {
         s3ClientFactory.close();
     }
 
diff --git 
a/server/blob/blob-s3/src/test/java/org/apache/james/blob/objectstorage/aws/S3WithMinIOGenerationAwareBlobIdTest.java
 
b/server/blob/blob-s3/src/test/java/org/apache/james/blob/objectstorage/aws/S3WithMinIOGenerationAwareBlobIdTest.java
index ef1e6b7dbf..7e6fb7046d 100644
--- 
a/server/blob/blob-s3/src/test/java/org/apache/james/blob/objectstorage/aws/S3WithMinIOGenerationAwareBlobIdTest.java
+++ 
b/server/blob/blob-s3/src/test/java/org/apache/james/blob/objectstorage/aws/S3WithMinIOGenerationAwareBlobIdTest.java
@@ -40,7 +40,9 @@ import 
org.apache.james.server.blob.deduplication.BlobStoreFactory;
 import org.apache.james.server.blob.deduplication.GenerationAwareBlobId;
 import org.apache.james.server.blob.deduplication.MinIOGenerationAwareBlobId;
 import org.apache.james.utils.UpdatableTickingClock;
+import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Nested;
@@ -60,10 +62,31 @@ public class S3WithMinIOGenerationAwareBlobIdTest 
implements BlobStoreContract {
     static S3MinioExtension minoExtension = new S3MinioExtension();
 
     private static BlobStore testee;
+    private static S3BlobStoreConfiguration s3Configuration;
     private static S3ClientFactory s3ClientFactory;
-    private S3BlobStoreDAO s3BlobStoreDAO;
+    private static S3BlobStoreDAO s3BlobStoreDAO;
     private BlobId.Factory blobIdFactory;
 
+    @BeforeAll
+    static void setUpClass() {
+        AwsS3AuthConfiguration awsS3AuthConfiguration = 
minoExtension.minioDocker().getAwsS3AuthConfiguration();
+
+        s3Configuration = S3BlobStoreConfiguration.builder()
+            .authConfiguration(awsS3AuthConfiguration)
+            .region(DockerAwsS3Container.REGION)
+            .uploadRetrySpec(Optional.of(Retry.backoff(3, 
java.time.Duration.ofSeconds(1))
+                .filter(UPLOAD_RETRY_EXCEPTION_PREDICATE)))
+            .build();
+
+        s3ClientFactory = new S3ClientFactory(s3Configuration, new 
RecordingMetricFactory(), new NoopGaugeRegistry());
+        s3BlobStoreDAO = new S3BlobStoreDAO(s3ClientFactory, s3Configuration, 
new PlainBlobId.Factory(), S3RequestOption.DEFAULT);
+    }
+
+    @AfterAll
+    static void tearDownClass() {
+        s3ClientFactory.close();
+    }
+
     @BeforeEach
     void beforeEach() throws Exception {
         blobIdFactory = new MinIOGenerationAwareBlobId.Factory(clock, 
GenerationAwareBlobId.Configuration.DEFAULT, new PlainBlobId.Factory());
@@ -76,7 +99,6 @@ public class S3WithMinIOGenerationAwareBlobIdTest implements 
BlobStoreContract {
     @AfterEach
     void tearDown() {
         s3BlobStoreDAO.deleteAllBuckets().block();
-        s3ClientFactory.close();
     }
 
     @Override
@@ -95,20 +117,8 @@ public class S3WithMinIOGenerationAwareBlobIdTest 
implements BlobStoreContract {
     }
 
     public BlobStore createBlobStore(BlobId.Factory blobIdFactory) {
-        AwsS3AuthConfiguration awsS3AuthConfiguration = 
minoExtension.minioDocker().getAwsS3AuthConfiguration();
-
-        S3BlobStoreConfiguration s3Configuration = 
S3BlobStoreConfiguration.builder()
-            .authConfiguration(awsS3AuthConfiguration)
-            .region(DockerAwsS3Container.REGION)
-            .uploadRetrySpec(Optional.of(Retry.backoff(3, 
java.time.Duration.ofSeconds(1))
-                .filter(UPLOAD_RETRY_EXCEPTION_PREDICATE)))
-            .build();
-
-        s3ClientFactory = new S3ClientFactory(s3Configuration, new 
RecordingMetricFactory(), new NoopGaugeRegistry());
-        s3BlobStoreDAO = new S3BlobStoreDAO(s3ClientFactory, s3Configuration, 
blobIdFactory, S3RequestOption.DEFAULT);
-
         return BlobStoreFactory.builder()
-            .blobStoreDAO(s3BlobStoreDAO)
+            .blobStoreDAO(new S3BlobStoreDAO(s3ClientFactory, s3Configuration, 
blobIdFactory, S3RequestOption.DEFAULT))
             .blobIdFactory(blobIdFactory)
             .defaultBucketName()
             .deduplication();


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to