Skip to content

Commit 2d99658

Browse files
committed
[BUILD] Use Lifecycle.PER_CLASS in distributed integration tests
1 parent 84331f8 commit 2d99658

14 files changed

Lines changed: 231 additions & 16 deletions
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/****************************************************************
2+
* Licensed to the Apache Software Foundation (ASF) under one *
3+
* or more contributor license agreements. See the NOTICE file *
4+
* distributed with this work for additional information *
5+
* regarding copyright ownership. The ASF licenses this file *
6+
* to you under the Apache License, Version 2.0 (the *
7+
* "License"); you may not use this file except in compliance *
8+
* with the License. You may obtain a copy of the License at *
9+
* *
10+
* http://www.apache.org/licenses/LICENSE-2.0 *
11+
* *
12+
* Unless required by applicable law or agreed to in writing, *
13+
* software distributed under the License is distributed on an *
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
15+
* KIND, either express or implied. See the License for the *
16+
* specific language governing permissions and limitations *
17+
* under the License. *
18+
****************************************************************/
19+
20+
package org.apache.james;
21+
22+
import jakarta.inject.Inject;
23+
24+
import org.apache.james.utils.GuiceProbe;
25+
26+
public class CleanupTasksPerformerProbe implements GuiceProbe {
27+
28+
private final CleanupTasksPerformer cleanupTasksPerformer;
29+
30+
@Inject
31+
public CleanupTasksPerformerProbe(CleanupTasksPerformer cleanupTasksPerformer) {
32+
this.cleanupTasksPerformer = cleanupTasksPerformer;
33+
}
34+
35+
public void clean() {
36+
cleanupTasksPerformer.clean();
37+
}
38+
}

server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedAuthenticationTest.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
import org.apache.james.modules.RabbitMQExtension;
3232
import org.apache.james.modules.TestJMAPServerModule;
3333
import org.apache.james.modules.blobstore.BlobStoreConfiguration;
34+
import org.apache.james.CleanupTasksPerformerProbe;
35+
import org.apache.james.GuiceJamesServer;
36+
import org.apache.james.utils.GuiceProbe;
37+
import org.junit.jupiter.api.AfterEach;
38+
39+
import com.google.inject.multibindings.Multibinder;
3440
import org.junit.jupiter.api.extension.RegisterExtension;
3541

3642
class DistributedAuthenticationTest implements AuthenticationContract {
@@ -52,6 +58,12 @@ class DistributedAuthenticationTest implements AuthenticationContract {
5258
.extension(new AwsS3BlobStoreExtension())
5359
.server(configuration -> CassandraRabbitMQJamesServerMain.createServer(configuration)
5460
.overrideWith(new TestJMAPServerModule()))
55-
.lifeCycle(JamesServerExtension.Lifecycle.PER_ENCLOSING_CLASS)
61+
.overrideWith(binder -> Multibinder.newSetBinder(binder, GuiceProbe.class).addBinding().to(CleanupTasksPerformerProbe.class)))
62+
.lifeCycle(JamesServerExtension.Lifecycle.PER_CLASS)
5663
.build();
57-
}
64+
65+
@AfterEach
66+
void cleanUp(GuiceJamesServer server) {
67+
server.getProbe(CleanupTasksPerformerProbe.class).clean();
68+
}
69+
}

server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedBase.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
import org.apache.james.CassandraExtension;
2323
import org.apache.james.CassandraRabbitMQJamesConfiguration;
2424
import org.apache.james.CassandraRabbitMQJamesServerMain;
25+
import org.apache.james.CleanupTasksPerformerProbe;
2526
import org.apache.james.DockerOpenSearchExtension;
27+
import org.apache.james.GuiceJamesServer;
2628
import org.apache.james.JamesServerBuilder;
2729
import org.apache.james.JamesServerExtension;
2830
import org.apache.james.SearchConfiguration;
@@ -33,8 +35,12 @@
3335
import org.apache.james.modules.RabbitMQExtension;
3436
import org.apache.james.modules.TestJMAPServerModule;
3537
import org.apache.james.modules.blobstore.BlobStoreConfiguration;
38+
import org.apache.james.utils.GuiceProbe;
39+
import org.junit.jupiter.api.AfterEach;
3640
import org.junit.jupiter.api.extension.RegisterExtension;
3741

42+
import com.google.inject.multibindings.Multibinder;
43+
3844
public class DistributedBase {
3945
@RegisterExtension
4046
static JamesServerExtension testExtension = new JamesServerBuilder<CassandraRabbitMQJamesConfiguration>(tmpDir ->
@@ -54,6 +60,13 @@ public class DistributedBase {
5460
.extension(new RabbitMQExtension())
5561
.extension(new AwsS3BlobStoreExtension())
5662
.server(configuration -> CassandraRabbitMQJamesServerMain.createServer(configuration)
57-
.overrideWith(new TestJMAPServerModule(), new DelegationProbeModule(), new IdentityProbeModule(), new JmapPreviewProbeModule()))
63+
.overrideWith(new TestJMAPServerModule(), new DelegationProbeModule(), new IdentityProbeModule(), new JmapPreviewProbeModule())
64+
.overrideWith(binder -> Multibinder.newSetBinder(binder, GuiceProbe.class).addBinding().to(CleanupTasksPerformerProbe.class)))
65+
.lifeCycle(JamesServerExtension.Lifecycle.PER_CLASS)
5866
.build();
67+
68+
@AfterEach
69+
void cleanUp(GuiceJamesServer server) {
70+
server.getProbe(CleanupTasksPerformerProbe.class).clean();
71+
}
5972
}

server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedBlobCopyTest.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
import org.apache.james.modules.RabbitMQExtension;
3434
import org.apache.james.modules.TestJMAPServerModule;
3535
import org.apache.james.modules.blobstore.BlobStoreConfiguration;
36+
import org.apache.james.CleanupTasksPerformerProbe;
37+
import org.apache.james.GuiceJamesServer;
38+
import org.apache.james.utils.GuiceProbe;
39+
import org.junit.jupiter.api.AfterEach;
40+
41+
import com.google.inject.multibindings.Multibinder;
3642
import org.junit.jupiter.api.extension.RegisterExtension;
3743

3844
import com.google.common.collect.ImmutableMap;
@@ -57,6 +63,14 @@ public class DistributedBlobCopyTest implements BlobCopyContract {
5763
.extension(new AwsS3BlobStoreExtension())
5864
.server(configuration -> CassandraRabbitMQJamesServerMain.createServer(configuration)
5965
.overrideWith(new TestJMAPServerModule(ImmutableMap.of("upload.quota.limit", BlobCopyContract$.MODULE$.TWENTY_KILO_BYTES_UPLOAD_QUOTA_LIMIT())),
60-
new DelegationProbeModule()))
66+
new DelegationProbeModule())
67+
.overrideWith(binder -> Multibinder.newSetBinder(binder, GuiceProbe.class).addBinding().to(CleanupTasksPerformerProbe.class)))
68+
.lifeCycle(JamesServerExtension.Lifecycle.PER_CLASS)
69+
6170
.build();
71+
72+
@AfterEach
73+
void cleanUp(GuiceJamesServer server) {
74+
server.getProbe(CleanupTasksPerformerProbe.class).clean();
75+
}
6276
}

server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedCustomMethodTest.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
import org.apache.james.modules.RabbitMQExtension;
3232
import org.apache.james.modules.TestJMAPServerModule;
3333
import org.apache.james.modules.blobstore.BlobStoreConfiguration;
34+
import org.apache.james.CleanupTasksPerformerProbe;
35+
import org.apache.james.GuiceJamesServer;
36+
import org.apache.james.utils.GuiceProbe;
37+
import org.junit.jupiter.api.AfterEach;
38+
39+
import com.google.inject.multibindings.Multibinder;
3440
import org.junit.jupiter.api.extension.RegisterExtension;
3541

3642
public class DistributedCustomMethodTest implements CustomMethodContract {
@@ -52,5 +58,12 @@ public class DistributedCustomMethodTest implements CustomMethodContract {
5258
.server(configuration -> CassandraRabbitMQJamesServerMain.createServer(configuration)
5359
.overrideWith(new TestJMAPServerModule())
5460
.overrideWith(new CustomMethodModule()))
61+
.overrideWith(binder -> Multibinder.newSetBinder(binder, GuiceProbe.class).addBinding().to(CleanupTasksPerformerProbe.class)))
62+
.lifeCycle(JamesServerExtension.Lifecycle.PER_CLASS)
5563
.build();
56-
}
64+
65+
@AfterEach
66+
void cleanUp(GuiceJamesServer server) {
67+
server.getProbe(CleanupTasksPerformerProbe.class).clean();
68+
}
69+
}

server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedCustomNamespaceTest.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
import org.apache.james.modules.RabbitMQExtension;
3232
import org.apache.james.modules.TestJMAPServerModule;
3333
import org.apache.james.modules.blobstore.BlobStoreConfiguration;
34+
import org.apache.james.CleanupTasksPerformerProbe;
35+
import org.apache.james.GuiceJamesServer;
36+
import org.apache.james.utils.GuiceProbe;
37+
import org.junit.jupiter.api.AfterEach;
38+
39+
import com.google.inject.multibindings.Multibinder;
3440
import org.junit.jupiter.api.extension.RegisterExtension;
3541

3642
public class DistributedCustomNamespaceTest implements CustomNamespaceContract {
@@ -52,5 +58,12 @@ public class DistributedCustomNamespaceTest implements CustomNamespaceContract {
5258
.server(configuration -> CassandraRabbitMQJamesServerMain.createServer(configuration)
5359
.overrideWith(new TestJMAPServerModule())
5460
.overrideWith(new CustomNamespaceModule()))
61+
.overrideWith(binder -> Multibinder.newSetBinder(binder, GuiceProbe.class).addBinding().to(CleanupTasksPerformerProbe.class)))
62+
.lifeCycle(JamesServerExtension.Lifecycle.PER_CLASS)
5563
.build();
56-
}
64+
65+
@AfterEach
66+
void cleanUp(GuiceJamesServer server) {
67+
server.getProbe(CleanupTasksPerformerProbe.class).clean();
68+
}
69+
}

server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedEmailChangeMethodTest.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535
import org.apache.james.modules.RabbitMQExtension;
3636
import org.apache.james.modules.TestJMAPServerModule;
3737
import org.apache.james.modules.blobstore.BlobStoreConfiguration;
38+
import org.apache.james.CleanupTasksPerformerProbe;
39+
import org.apache.james.GuiceJamesServer;
40+
import org.apache.james.utils.GuiceProbe;
41+
import org.junit.jupiter.api.AfterEach;
42+
43+
import com.google.inject.multibindings.Multibinder;
3844
import org.junit.jupiter.api.extension.RegisterExtension;
3945

4046
import com.google.inject.name.Names;
@@ -58,11 +64,19 @@ public class DistributedEmailChangeMethodTest implements EmailChangesMethodContr
5864
.server(configuration -> CassandraRabbitMQJamesServerMain.createServer(configuration)
5965
.overrideWith(new TestJMAPServerModule())
6066
.overrideWith(binder -> binder.bind(Limit.class).annotatedWith(Names.named(CassandraMailboxChangeRepository.LIMIT_NAME)).toInstance(Limit.of(5)))
61-
.overrideWith(binder -> binder.bind(Limit.class).annotatedWith(Names.named(CassandraEmailChangeRepository.LIMIT_NAME)).toInstance(Limit.of(5))))
67+
.overrideWith(binder -> binder.bind(Limit.class).annotatedWith(Names.named(CassandraEmailChangeRepository.LIMIT_NAME)).toInstance(Limit.of(5)))
68+
.overrideWith(binder -> Multibinder.newSetBinder(binder, GuiceProbe.class).addBinding().to(CleanupTasksPerformerProbe.class)))
69+
.lifeCycle(JamesServerExtension.Lifecycle.PER_CLASS)
70+
6271
.build();
6372

6473
@Override
6574
public State.Factory stateFactory() {
6675
return new CassandraStateFactory();
6776
}
77+
78+
@AfterEach
79+
void cleanUp(GuiceJamesServer server) {
80+
server.getProbe(CleanupTasksPerformerProbe.class).clean();
81+
}
6882
}

server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedEmailQueryMethodNoViewTest.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
import org.apache.james.modules.RabbitMQExtension;
3333
import org.apache.james.modules.TestJMAPServerModule;
3434
import org.apache.james.modules.blobstore.BlobStoreConfiguration;
35+
import org.apache.james.CleanupTasksPerformerProbe;
36+
import org.apache.james.GuiceJamesServer;
37+
import org.apache.james.utils.GuiceProbe;
38+
import org.junit.jupiter.api.AfterEach;
39+
40+
import com.google.inject.multibindings.Multibinder;
3541
import org.junit.jupiter.api.Disabled;
3642
import org.junit.jupiter.api.Test;
3743
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -61,7 +67,10 @@ public class DistributedEmailQueryMethodNoViewTest implements EmailQueryMethodCo
6167
.enable()
6268
.randomPort()
6369
.disableEmailQueryView()
64-
.build())))
70+
.build()))
71+
.overrideWith(binder -> Multibinder.newSetBinder(binder, GuiceProbe.class).addBinding().to(CleanupTasksPerformerProbe.class)))
72+
.lifeCycle(JamesServerExtension.Lifecycle.PER_CLASS)
73+
6574
.build();
6675

6776
@Test
@@ -87,4 +96,9 @@ public void inMailboxSortedBySentAtShouldCollapseThreads(GuiceJamesServer server
8796
@Disabled("JAMES-3340 Not supported for no email query view")
8897
public void inMailboxBeforeSortedByReceivedAtShouldCollapseThreads(GuiceJamesServer server) {
8998
}
99+
100+
@AfterEach
101+
void cleanUp(GuiceJamesServer server) {
102+
server.getProbe(CleanupTasksPerformerProbe.class).clean();
103+
}
90104
}

server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedEmailSubmissionSetMethodFutureReleaseTest.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838
import org.apache.james.modules.TestJMAPServerModule;
3939
import org.apache.james.modules.blobstore.BlobStoreConfiguration;
4040
import org.apache.james.utils.UpdatableTickingClock;
41+
import org.apache.james.CleanupTasksPerformerProbe;
42+
import org.apache.james.GuiceJamesServer;
43+
import org.apache.james.utils.GuiceProbe;
44+
import org.junit.jupiter.api.AfterEach;
45+
46+
import com.google.inject.multibindings.Multibinder;
4147
import org.junit.jupiter.api.Disabled;
4248
import org.junit.jupiter.api.extension.RegisterExtension;
4349

@@ -68,7 +74,10 @@ public class DistributedEmailSubmissionSetMethodFutureReleaseTest implements Ema
6874
.extension(new ClockExtension())
6975
.server(configuration -> CassandraRabbitMQJamesServerMain.createServer(configuration)
7076
.overrideWith(new TestJMAPServerModule(), new DelegationProbeModule()))
71-
.overrideServerModule(binder -> binder.bind(Boolean.class).annotatedWith(Names.named("supportsDelaySends")).toInstance(true))
77+
.overrideServerModule(binder -> binder.bind(Boolean.class).annotatedWith(Names.named("supportsDelaySends")).toInstance(true)
78+
.overrideWith(binder -> Multibinder.newSetBinder(binder, GuiceProbe.class).addBinding().to(CleanupTasksPerformerProbe.class)))
79+
.lifeCycle(JamesServerExtension.Lifecycle.PER_CLASS)
80+
7281
.build();
7382

7483
@Override
@@ -95,4 +104,9 @@ public void emailSubmissionSetCreateShouldDelayEmailWithHoldFor(GuiceJamesServer
95104
@Override
96105
public void emailSubmissionSetCreateShouldDelayEmailWithHoldUntil(GuiceJamesServer server, UpdatableTickingClock updatableTickingClock){
97106
}
98-
}
107+
108+
@AfterEach
109+
void cleanUp(GuiceJamesServer server) {
110+
server.getProbe(CleanupTasksPerformerProbe.class).clean();
111+
}
112+
}

server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedMailboxChangeMethodTest.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@
3737
import org.apache.james.modules.RabbitMQExtension;
3838
import org.apache.james.modules.TestJMAPServerModule;
3939
import org.apache.james.modules.blobstore.BlobStoreConfiguration;
40+
import org.apache.james.CleanupTasksPerformerProbe;
41+
import org.apache.james.GuiceJamesServer;
42+
import org.apache.james.utils.GuiceProbe;
43+
import org.junit.jupiter.api.AfterEach;
44+
45+
import com.google.inject.multibindings.Multibinder;
4046
import org.junit.jupiter.api.extension.RegisterExtension;
4147

4248
import com.google.inject.name.Names;
@@ -60,7 +66,10 @@ public class DistributedMailboxChangeMethodTest implements MailboxChangesMethodC
6066
.server(configuration -> CassandraRabbitMQJamesServerMain.createServer(configuration)
6167
.overrideWith(new TestJMAPServerModule())
6268
.overrideWith(binder -> binder.bind(Limit.class).annotatedWith(Names.named(CassandraMailboxChangeRepository.LIMIT_NAME)).toInstance(Limit.of(5)))
63-
.overrideWith(binder -> binder.bind(Limit.class).annotatedWith(Names.named(CassandraEmailChangeRepository.LIMIT_NAME)).toInstance(Limit.of(5))))
69+
.overrideWith(binder -> binder.bind(Limit.class).annotatedWith(Names.named(CassandraEmailChangeRepository.LIMIT_NAME)).toInstance(Limit.of(5)))
70+
.overrideWith(binder -> Multibinder.newSetBinder(binder, GuiceProbe.class).addBinding().to(CleanupTasksPerformerProbe.class)))
71+
.lifeCycle(JamesServerExtension.Lifecycle.PER_CLASS)
72+
6473
.build();
6574

6675
@Override
@@ -72,4 +81,9 @@ public State.Factory stateFactory() {
7281
public MailboxId generateMailboxId() {
7382
return CassandraId.timeBased();
7483
}
84+
85+
@AfterEach
86+
void cleanUp(GuiceJamesServer server) {
87+
server.getProbe(CleanupTasksPerformerProbe.class).clean();
88+
}
7589
}

0 commit comments

Comments
 (0)