Skip to content

Commit fd81515

Browse files
committed
Opensearch isolation upon server resuse
1 parent 5d5e8d9 commit fd81515

7 files changed

Lines changed: 77 additions & 6 deletions

File tree

backends-common/opensearch/src/main/java/org/apache/james/backends/opensearch/DeleteByQueryPerformer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class DeleteByQueryPerformer {
3131
private final ReactorOpenSearchClient client;
3232
private final WriteAliasName aliasName;
3333

34-
DeleteByQueryPerformer(ReactorOpenSearchClient client, WriteAliasName aliasName) {
34+
public DeleteByQueryPerformer(ReactorOpenSearchClient client, WriteAliasName aliasName) {
3535
this.client = client;
3636
this.aliasName = aliasName;
3737
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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.backends.opensearch.DeleteByQueryPerformer;
25+
import org.apache.james.backends.opensearch.ReactorOpenSearchClient;
26+
import org.apache.james.mailbox.opensearch.OpenSearchMailboxConfiguration;
27+
import org.apache.james.utils.GuiceProbe;
28+
import org.opensearch.client.opensearch._types.query_dsl.MatchAllQuery;
29+
30+
public class OpenSearchCleanupProbe implements GuiceProbe {
31+
32+
private final DeleteByQueryPerformer deleteByQueryPerformer;
33+
34+
@Inject
35+
public OpenSearchCleanupProbe(ReactorOpenSearchClient client, OpenSearchMailboxConfiguration configuration) {
36+
this.deleteByQueryPerformer = new DeleteByQueryPerformer(client, configuration.getWriteAliasMailboxName());
37+
}
38+
39+
public void cleanUp() {
40+
deleteByQueryPerformer.perform(new MatchAllQuery.Builder().build().toQuery()).block();
41+
}
42+
}

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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.james.GuiceJamesServer;
2828
import org.apache.james.JamesServerBuilder;
2929
import org.apache.james.JamesServerExtension;
30+
import org.apache.james.OpenSearchCleanupProbe;
3031
import org.apache.james.SearchConfiguration;
3132
import org.apache.james.jmap.rfc8621.contract.IdentityProbeModule;
3233
import org.apache.james.jmap.rfc8621.contract.JmapPreviewProbeModule;
@@ -61,12 +62,17 @@ public class DistributedBase {
6162
.extension(new AwsS3BlobStoreExtension())
6263
.server(configuration -> CassandraRabbitMQJamesServerMain.createServer(configuration)
6364
.overrideWith(new TestJMAPServerModule(), new DelegationProbeModule(), new IdentityProbeModule(), new JmapPreviewProbeModule())
64-
.overrideWith(binder -> Multibinder.newSetBinder(binder, GuiceProbe.class).addBinding().to(CleanupTasksPerformerProbe.class)))
65+
.overrideWith(binder -> {
66+
Multibinder<GuiceProbe> probes = Multibinder.newSetBinder(binder, GuiceProbe.class);
67+
probes.addBinding().to(CleanupTasksPerformerProbe.class);
68+
probes.addBinding().to(OpenSearchCleanupProbe.class);
69+
}))
6570
.lifeCycle(JamesServerExtension.Lifecycle.PER_CLASS)
6671
.build();
6772

6873
@AfterEach
6974
void cleanUp(GuiceJamesServer server) {
7075
server.getProbe(CleanupTasksPerformerProbe.class).clean();
76+
server.getProbe(OpenSearchCleanupProbe.class).cleanUp();
7177
}
7278
}

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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.james.CassandraRabbitMQJamesServerMain;
2525
import org.apache.james.CleanupTasksPerformerProbe;
2626
import org.apache.james.DockerOpenSearchExtension;
27+
import org.apache.james.OpenSearchCleanupProbe;
2728
import org.apache.james.GuiceJamesServer;
2829
import org.apache.james.JamesServerBuilder;
2930
import org.apache.james.JamesServerExtension;
@@ -63,13 +64,18 @@ public class DistributedBlobCopyTest implements BlobCopyContract {
6364
.server(configuration -> CassandraRabbitMQJamesServerMain.createServer(configuration)
6465
.overrideWith(new TestJMAPServerModule(ImmutableMap.of("upload.quota.limit", BlobCopyContract$.MODULE$.TWENTY_KILO_BYTES_UPLOAD_QUOTA_LIMIT())),
6566
new DelegationProbeModule())
66-
.overrideWith(binder -> Multibinder.newSetBinder(binder, GuiceProbe.class).addBinding().to(CleanupTasksPerformerProbe.class)))
67+
.overrideWith(binder -> {
68+
Multibinder<GuiceProbe> probes = Multibinder.newSetBinder(binder, GuiceProbe.class);
69+
probes.addBinding().to(CleanupTasksPerformerProbe.class);
70+
probes.addBinding().to(OpenSearchCleanupProbe.class);
71+
}))
6772
.lifeCycle(JamesServerExtension.Lifecycle.PER_CLASS)
6873

6974
.build();
7075

7176
@AfterEach
7277
void cleanUp(GuiceJamesServer server) {
7378
server.getProbe(CleanupTasksPerformerProbe.class).clean();
79+
server.getProbe(OpenSearchCleanupProbe.class).cleanUp();
7480
}
7581
}

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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.james.GuiceJamesServer;
2828
import org.apache.james.JamesServerBuilder;
2929
import org.apache.james.JamesServerExtension;
30+
import org.apache.james.OpenSearchCleanupProbe;
3031
import org.apache.james.jmap.JMAPConfiguration;
3132
import org.apache.james.jmap.rfc8621.contract.EmailQueryMethodContract;
3233
import org.apache.james.modules.AwsS3BlobStoreExtension;
@@ -67,7 +68,11 @@ public class DistributedEmailQueryMethodNoViewTest implements EmailQueryMethodCo
6768
.randomPort()
6869
.disableEmailQueryView()
6970
.build()))
70-
.overrideWith(binder -> Multibinder.newSetBinder(binder, GuiceProbe.class).addBinding().to(CleanupTasksPerformerProbe.class)))
71+
.overrideWith(binder -> {
72+
Multibinder<GuiceProbe> probes = Multibinder.newSetBinder(binder, GuiceProbe.class);
73+
probes.addBinding().to(CleanupTasksPerformerProbe.class);
74+
probes.addBinding().to(OpenSearchCleanupProbe.class);
75+
}))
7176
.lifeCycle(JamesServerExtension.Lifecycle.PER_CLASS)
7277

7378
.build();
@@ -99,5 +104,6 @@ public void inMailboxBeforeSortedByReceivedAtShouldCollapseThreads(GuiceJamesSer
99104
@AfterEach
100105
void cleanUp(GuiceJamesServer server) {
101106
server.getProbe(CleanupTasksPerformerProbe.class).clean();
107+
server.getProbe(OpenSearchCleanupProbe.class).cleanUp();
102108
}
103109
}

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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.apache.james.CleanupTasksPerformerProbe;
2626
import org.apache.james.ClockExtension;
2727
import org.apache.james.DockerOpenSearchExtension;
28+
import org.apache.james.OpenSearchCleanupProbe;
2829
import org.apache.james.GuiceJamesServer;
2930
import org.apache.james.JamesServerBuilder;
3031
import org.apache.james.JamesServerExtension;
@@ -72,7 +73,11 @@ public class DistributedEmailSubmissionSetMethodFutureReleaseTest implements Ema
7273
.extension(new ClockExtension())
7374
.server(configuration -> CassandraRabbitMQJamesServerMain.createServer(configuration)
7475
.overrideWith(new TestJMAPServerModule(), new DelegationProbeModule())
75-
.overrideWith(binder -> Multibinder.newSetBinder(binder, GuiceProbe.class).addBinding().to(CleanupTasksPerformerProbe.class)))
76+
.overrideWith(binder -> {
77+
Multibinder<GuiceProbe> probes = Multibinder.newSetBinder(binder, GuiceProbe.class);
78+
probes.addBinding().to(CleanupTasksPerformerProbe.class);
79+
probes.addBinding().to(OpenSearchCleanupProbe.class);
80+
}))
7681
.overrideServerModule(binder -> binder.bind(Boolean.class).annotatedWith(Names.named("supportsDelaySends")).toInstance(true))
7782
.lifeCycle(JamesServerExtension.Lifecycle.PER_CLASS)
7883

@@ -106,5 +111,6 @@ public void emailSubmissionSetCreateShouldDelayEmailWithHoldUntil(GuiceJamesServ
106111
@AfterEach
107112
void cleanUp(GuiceJamesServer server) {
108113
server.getProbe(CleanupTasksPerformerProbe.class).clean();
114+
server.getProbe(OpenSearchCleanupProbe.class).cleanUp();
109115
}
110116
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.james.CassandraRabbitMQJamesServerMain;
2525
import org.apache.james.CleanupTasksPerformerProbe;
2626
import org.apache.james.DockerOpenSearchExtension;
27+
import org.apache.james.OpenSearchCleanupProbe;
2728
import org.apache.james.GuiceJamesServer;
2829
import org.apache.james.JamesServerBuilder;
2930
import org.apache.james.JamesServerExtension;
@@ -70,7 +71,11 @@ public class DistributedVacationRelayIntegrationTest implements VacationRelayInt
7071
.server(configuration -> CassandraRabbitMQJamesServerMain.createServer(configuration)
7172
.overrideWith(new TestJMAPServerModule(), new DelegationProbeModule(), new IdentityProbeModule())
7273
.overrideWith((binder -> binder.bind(DNSService.class).toInstance(inMemoryDNSService)))
73-
.overrideWith(binder -> Multibinder.newSetBinder(binder, GuiceProbe.class).addBinding().to(CleanupTasksPerformerProbe.class)))
74+
.overrideWith(binder -> {
75+
Multibinder<GuiceProbe> probes = Multibinder.newSetBinder(binder, GuiceProbe.class);
76+
probes.addBinding().to(CleanupTasksPerformerProbe.class);
77+
probes.addBinding().to(OpenSearchCleanupProbe.class);
78+
}))
7479
.lifeCycle(JamesServerExtension.Lifecycle.PER_CLASS)
7580

7681
.build();

0 commit comments

Comments
 (0)