This is an automated email from the ASF dual-hosted git repository. btellier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 991c8f922e466530881f04bc8ef4aa7e6f3ac80e Author: Benoit TELLIER <[email protected]> AuthorDate: Tue Sep 30 07:22:20 2025 +0200 [REMOVAL] Remove tests targeting solely CassandraJamesServerMain --- .../james/CassandraDuplicatingJamesServerTest.java | 43 ----- .../org/apache/james/CassandraJamesServerTest.java | 54 ------- .../apache/james/CassandraLdapJamesServerTest.java | 107 ------------- .../james/CassandraLdapJmapJamesServerTest.java | 40 ----- .../CassandraMailRepositoryIntegrationTest.java | 69 -------- .../james/DefaultCassandraJamesServerTest.java | 47 ------ .../james/WithCassandraBlobStoreImmutableTest.java | 39 ----- .../apache/james/WithCassandraBlobStoreTest.java | 176 --------------------- 8 files changed, 575 deletions(-) diff --git a/server/apps/cassandra-app/src/test/java/org/apache/james/CassandraDuplicatingJamesServerTest.java b/server/apps/cassandra-app/src/test/java/org/apache/james/CassandraDuplicatingJamesServerTest.java deleted file mode 100644 index 1a634eca87..0000000000 --- a/server/apps/cassandra-app/src/test/java/org/apache/james/CassandraDuplicatingJamesServerTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james; - -import java.util.Optional; - -import org.apache.james.jmap.JmapJamesServerContract; -import org.apache.james.modules.TestJMAPServerModule; -import org.apache.james.server.blob.deduplication.StorageStrategy; -import org.junit.jupiter.api.extension.RegisterExtension; - -class CassandraDuplicatingJamesServerTest implements JamesServerConcreteContract, JmapJamesServerContract { - @RegisterExtension - static JamesServerExtension testExtension = new JamesServerBuilder<CassandraJamesServerConfiguration>(tmpDir -> - CassandraJamesServerConfiguration.builder() - .workingDirectory(tmpDir) - .configurationFromClasspath() - .blobStore(new BlobStoreConfiguration(StorageStrategy.PASSTHROUGH, Optional.empty())) - .build()) - .extension(new DockerOpenSearchExtension()) - .extension(new CassandraExtension()) - .server(configuration -> CassandraJamesServerMain.createServer(configuration) - .overrideWith(new TestJMAPServerModule())) - .lifeCycle(JamesServerExtension.Lifecycle.PER_CLASS) - .build(); -} diff --git a/server/apps/cassandra-app/src/test/java/org/apache/james/CassandraJamesServerTest.java b/server/apps/cassandra-app/src/test/java/org/apache/james/CassandraJamesServerTest.java deleted file mode 100644 index e8109c56e0..0000000000 --- a/server/apps/cassandra-app/src/test/java/org/apache/james/CassandraJamesServerTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.apache.james.jmap.JmapJamesServerContract; -import org.apache.james.junit.categories.BasicFeature; -import org.apache.james.modules.ConfigurationProbe; -import org.apache.james.modules.TestJMAPServerModule; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; - -@Tag(BasicFeature.TAG) -class CassandraJamesServerTest implements JamesServerConcreteContract, JmapJamesServerContract { - @RegisterExtension - static JamesServerExtension testExtension = TestingDistributedJamesServerBuilder.withSearchConfiguration(SearchConfiguration.openSearch()) - .extension(new DockerOpenSearchExtension()) - .extension(new CassandraExtension()) - .server(configuration -> CassandraJamesServerMain.createServer(configuration) - .overrideWith(new TestJMAPServerModule())) - .lifeCycle(JamesServerExtension.Lifecycle.PER_CLASS) - .build(); - - @Test - void moveBatchSizeShouldEqualsConfigurationValue(GuiceJamesServer jamesServer) { - int moveBatchSize = jamesServer.getProbe(ConfigurationProbe.class).getMoveBatchSize(); - assertThat(moveBatchSize).isEqualTo(100); - } - - @Test - void copyBatchSizeShouldEqualsConfigurationValue(GuiceJamesServer jamesServer) { - int copyBatchSize = jamesServer.getProbe(ConfigurationProbe.class).getCopyBatchSize(); - assertThat(copyBatchSize).isEqualTo(100); - } -} diff --git a/server/apps/cassandra-app/src/test/java/org/apache/james/CassandraLdapJamesServerTest.java b/server/apps/cassandra-app/src/test/java/org/apache/james/CassandraLdapJamesServerTest.java deleted file mode 100644 index 54744e02e9..0000000000 --- a/server/apps/cassandra-app/src/test/java/org/apache/james/CassandraLdapJamesServerTest.java +++ /dev/null @@ -1,107 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james; - -import static org.apache.james.user.ldap.DockerLdapSingleton.JAMES_USER; -import static org.apache.james.user.ldap.DockerLdapSingleton.PASSWORD; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.awaitility.Durations.ONE_HUNDRED_MILLISECONDS; - -import java.time.Duration; - -import org.apache.commons.net.imap.IMAPClient; -import org.apache.james.core.Domain; -import org.apache.james.data.LdapTestExtension; -import org.apache.james.data.UsersRepositoryModuleChooser; -import org.apache.james.junit.categories.BasicFeature; -import org.apache.james.modules.TestJMAPServerModule; -import org.apache.james.modules.protocols.ImapGuiceProbe; -import org.apache.james.modules.protocols.SmtpGuiceProbe; -import org.apache.james.utils.SMTPMessageSender; -import org.apache.james.utils.SMTPSendingException; -import org.apache.james.utils.SpoolerProbe; -import org.apache.james.utils.TestIMAPClient; -import org.awaitility.Awaitility; -import org.awaitility.core.ConditionFactory; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; - -@Tag(BasicFeature.TAG) -class CassandraLdapJamesServerTest implements JamesServerConcreteContract { - private static Duration slowPacedPollInterval = ONE_HUNDRED_MILLISECONDS; - private static ConditionFactory calmlyAwait = Awaitility.with() - .pollInterval(slowPacedPollInterval) - .and() - .with() - .pollDelay(slowPacedPollInterval) - .await(); - private IMAPClient imapClient = new IMAPClient(); - - @RegisterExtension - TestIMAPClient testIMAPClient = new TestIMAPClient(); - SMTPMessageSender messageSender = new SMTPMessageSender(Domain.LOCALHOST.asString()); - static LdapTestExtension ldap = new LdapTestExtension(); - - @RegisterExtension - static JamesServerExtension testExtension = TestingDistributedJamesServerBuilder - .forConfiguration(configuration -> configuration - .searchConfiguration(SearchConfiguration.openSearch()) - .usersRepository(UsersRepositoryModuleChooser.Implementation.LDAP)) - .extension(new DockerOpenSearchExtension()) - .extension(new CassandraExtension()) - .extension(ldap) - .server(configuration -> CassandraJamesServerMain.createServer(configuration) - .overrideWith(new TestJMAPServerModule())) - .build(); - - @Test - void userFromLdapShouldLoginViaImapProtocol(GuiceJamesServer server) throws Exception { - imapClient.connect(JAMES_SERVER_HOST, server.getProbe(ImapGuiceProbe.class).getImapPort()); - - assertThat(imapClient.login(JAMES_USER.asString(), PASSWORD)).isTrue(); - } - - @Test - void mailsShouldBeWellReceivedBeforeFirstUserConnectionWithLdap(GuiceJamesServer server) throws Exception { - messageSender.connect(JAMES_SERVER_HOST, server.getProbe(SmtpGuiceProbe.class).getSmtpPort()) - .sendMessage("[email protected]", JAMES_USER.asString() + "@localhost"); - - calmlyAwait.until(() -> server.getProbe(SpoolerProbe.class).processingFinished()); - - testIMAPClient.connect(JAMES_SERVER_HOST, server.getProbe(ImapGuiceProbe.class).getImapPort()) - .login(JAMES_USER, PASSWORD) - .select("INBOX") - .awaitMessage(calmlyAwait); - } - - @Test - void receivingMailShouldIssueAnSmtpErrorWhenLdapIsNotAvailable(GuiceJamesServer server) { - try { - ldap.getLdapRule().stop(); - assertThatThrownBy(() -> messageSender.connect(JAMES_SERVER_HOST, server.getProbe(SmtpGuiceProbe.class).getSmtpPort()) - .sendMessage("[email protected]", JAMES_USER.asString() + "@localhost")) - .isInstanceOf(SMTPSendingException.class); - } finally { - ldap.getLdapRule().start(); - } - } -} diff --git a/server/apps/cassandra-app/src/test/java/org/apache/james/CassandraLdapJmapJamesServerTest.java b/server/apps/cassandra-app/src/test/java/org/apache/james/CassandraLdapJmapJamesServerTest.java deleted file mode 100644 index 58eaf9de9f..0000000000 --- a/server/apps/cassandra-app/src/test/java/org/apache/james/CassandraLdapJmapJamesServerTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james; - -import org.apache.james.data.LdapTestExtension; -import org.apache.james.data.UsersRepositoryModuleChooser; -import org.apache.james.jmap.JmapJamesServerContract; -import org.apache.james.modules.TestJMAPServerModule; -import org.junit.jupiter.api.extension.RegisterExtension; - -class CassandraLdapJmapJamesServerTest implements JmapJamesServerContract { - @RegisterExtension - static JamesServerExtension testExtension = TestingDistributedJamesServerBuilder - .forConfiguration(configuration -> configuration - .searchConfiguration(SearchConfiguration.openSearch()) - .usersRepository(UsersRepositoryModuleChooser.Implementation.LDAP)) - .extension(new DockerOpenSearchExtension()) - .extension(new CassandraExtension()) - .extension(new LdapTestExtension()) - .server(configuration -> CassandraJamesServerMain.createServer(configuration) - .overrideWith(new TestJMAPServerModule())) - .build(); -} diff --git a/server/apps/cassandra-app/src/test/java/org/apache/james/CassandraMailRepositoryIntegrationTest.java b/server/apps/cassandra-app/src/test/java/org/apache/james/CassandraMailRepositoryIntegrationTest.java deleted file mode 100644 index 3634152afa..0000000000 --- a/server/apps/cassandra-app/src/test/java/org/apache/james/CassandraMailRepositoryIntegrationTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james; - -import static org.awaitility.Durations.FIVE_HUNDRED_MILLISECONDS; - -import java.time.Duration; - -import org.apache.james.mailrepository.api.MailRepositoryUrl; -import org.apache.james.modules.TestJMAPServerModule; -import org.apache.james.modules.protocols.SmtpGuiceProbe; -import org.apache.james.utils.DataProbeImpl; -import org.apache.james.utils.MailRepositoryProbeImpl; -import org.apache.james.utils.SMTPMessageSender; -import org.awaitility.Awaitility; -import org.awaitility.core.ConditionFactory; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; - -class CassandraMailRepositoryIntegrationTest { - private static final MailRepositoryUrl SENDER_DENIED_URL = MailRepositoryUrl.from("cassandra://var/mail/sender-denied/"); - private static final Duration ONE_MILLISECOND = Duration.ofMillis(1); - private static ConditionFactory await = Awaitility.with() - .pollInterval(FIVE_HUNDRED_MILLISECONDS) - .and() - .with() - .pollDelay(ONE_MILLISECOND) - .await(); - private SMTPMessageSender smtpMessageSender = new SMTPMessageSender("other.com"); - - @RegisterExtension - static JamesServerExtension testExtension = TestingDistributedJamesServerBuilder.withSearchConfiguration(SearchConfiguration.openSearch()) - .extension(new DockerOpenSearchExtension()) - .extension(new CassandraExtension()) - .server(configuration -> CassandraJamesServerMain.createServer(configuration) - .overrideWith(new TestJMAPServerModule())) - .build(); - - @Test - void deniedSenderMailShouldBeStoredInCassandraMailRepositoryWhenConfigured(GuiceJamesServer server) throws Exception { - server.getProbe(DataProbeImpl.class) - .fluent() - .addDomain("domain.com") - .addUser("[email protected]", "secret"); - - smtpMessageSender.connect("127.0.0.1", server.getProbe(SmtpGuiceProbe.class).getSmtpPort()) - .sendMessage("[email protected]", "[email protected]"); - - MailRepositoryProbeImpl repositoryProbe = server.getProbe(MailRepositoryProbeImpl.class); - await.until(() -> repositoryProbe.getRepositoryMailCount(SENDER_DENIED_URL) == 1); - } -} diff --git a/server/apps/cassandra-app/src/test/java/org/apache/james/DefaultCassandraJamesServerTest.java b/server/apps/cassandra-app/src/test/java/org/apache/james/DefaultCassandraJamesServerTest.java deleted file mode 100644 index 160f417a2c..0000000000 --- a/server/apps/cassandra-app/src/test/java/org/apache/james/DefaultCassandraJamesServerTest.java +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.apache.commons.configuration2.BaseHierarchicalConfiguration; -import org.apache.james.modules.TestJMAPServerModule; -import org.apache.james.server.core.configuration.ConfigurationProvider; -import org.apache.james.utils.FailingPropertiesProvider; -import org.apache.james.utils.PropertiesProvider; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; - -class DefaultCassandraJamesServerTest { - @RegisterExtension - static JamesServerExtension testExtension = TestingDistributedJamesServerBuilder.withSearchConfiguration(SearchConfiguration.openSearch()) - .extension(new DockerOpenSearchExtension()) - .extension(new CassandraExtension()) - .server(configuration -> CassandraJamesServerMain.createServer(configuration) - .overrideWith(new TestJMAPServerModule()) - .overrideWith(binder -> binder.bind(PropertiesProvider.class).to(FailingPropertiesProvider.class)) - .overrideWith(binder -> binder.bind(ConfigurationProvider.class).toInstance((s, l) -> new BaseHierarchicalConfiguration()))) - .build(); - - @Test - void cassandraJamesServerShouldStartWithNoConfigurationFile(GuiceJamesServer server) { - assertThat(server.isStarted()).isTrue(); - } -} diff --git a/server/apps/cassandra-app/src/test/java/org/apache/james/WithCassandraBlobStoreImmutableTest.java b/server/apps/cassandra-app/src/test/java/org/apache/james/WithCassandraBlobStoreImmutableTest.java deleted file mode 100644 index 366f1b4857..0000000000 --- a/server/apps/cassandra-app/src/test/java/org/apache/james/WithCassandraBlobStoreImmutableTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.james; - -import org.apache.james.jmap.JmapJamesServerContract; -import org.apache.james.modules.TestJMAPServerModule; -import org.junit.jupiter.api.extension.RegisterExtension; - -class WithCassandraBlobStoreImmutableTest implements JmapJamesServerContract, JamesServerConcreteContract { - @RegisterExtension - static JamesServerExtension jamesServerExtension = baseExtensionBuilder() - .lifeCycle(JamesServerExtension.Lifecycle.PER_CLASS) - .build(); - - static JamesServerBuilder<CassandraJamesServerConfiguration> baseExtensionBuilder() { - return TestingDistributedJamesServerBuilder.withSearchConfiguration(SearchConfiguration.openSearch()) - .extension(new DockerOpenSearchExtension()) - .extension(new CassandraExtension()) - .server(configuration -> CassandraJamesServerMain.createServer(configuration) - .overrideWith(new TestJMAPServerModule())); - } -} diff --git a/server/apps/cassandra-app/src/test/java/org/apache/james/WithCassandraBlobStoreTest.java b/server/apps/cassandra-app/src/test/java/org/apache/james/WithCassandraBlobStoreTest.java deleted file mode 100644 index a7f0e7b021..0000000000 --- a/server/apps/cassandra-app/src/test/java/org/apache/james/WithCassandraBlobStoreTest.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.james; - -import static org.apache.james.jmap.JMAPTestingConstants.LOCALHOST_IP; -import static org.assertj.core.api.Assertions.assertThat; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.nio.ByteBuffer; -import java.nio.channels.SocketChannel; -import java.nio.charset.StandardCharsets; -import java.util.List; -import java.util.function.Predicate; - -import org.apache.james.backends.cassandra.StatementRecorder; -import org.apache.james.backends.cassandra.TestingSession; -import org.apache.james.backends.cassandra.init.SessionWithInitializedTablesFactory; -import org.apache.james.core.Domain; -import org.apache.james.junit.categories.BasicFeature; -import org.apache.james.mailbox.DefaultMailboxes; -import org.apache.james.mailbox.store.BatchSizes; -import org.apache.james.modules.MailboxProbeImpl; -import org.apache.james.modules.TestJMAPServerModule; -import org.apache.james.util.Port; -import org.apache.james.utils.DataProbeImpl; -import org.apache.james.utils.GuiceProbe; -import org.apache.james.utils.SMTPMessageSender; -import org.apache.james.utils.SpoolerProbe; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; - -import com.datastax.oss.driver.api.core.CqlSession; -import com.github.fge.lambdas.Throwing; -import com.google.common.collect.ImmutableList; -import com.google.inject.AbstractModule; -import com.google.inject.Inject; -import com.google.inject.Provides; -import com.google.inject.Singleton; -import com.google.inject.multibindings.Multibinder; - -import reactor.core.publisher.Mono; -import reactor.core.scheduler.Schedulers; - -@Tag(BasicFeature.TAG) -class WithCassandraBlobStoreTest implements MailsShouldBeWellReceivedConcreteContract { - private static class TestingSessionProbe implements GuiceProbe { - private final TestingSession testingSession; - - @Inject - private TestingSessionProbe(TestingSession testingSession) { - this.testingSession = testingSession; - } - - public TestingSession getTestingSession() { - return testingSession; - } - } - - private static class TestingSessionModule extends AbstractModule { - @Override - protected void configure() { - Multibinder.newSetBinder(binder(), GuiceProbe.class) - .addBinding() - .to(TestingSessionProbe.class); - - bind(CqlSession.class).to(TestingSession.class); - } - - @Provides - @Singleton - TestingSession provideSession(SessionWithInitializedTablesFactory factory) { - return new TestingSession(factory.get()); - } - } - - @RegisterExtension - static JamesServerExtension jamesServerExtension = TestingDistributedJamesServerBuilder.withSearchConfiguration(SearchConfiguration.scanning()) - .extension(new CassandraExtension()) - .server(configuration -> CassandraJamesServerMain.createServer(configuration) - .overrideWith(new TestJMAPServerModule())) - .overrideServerModule(new TestingSessionModule()) - .overrideServerModule(binder -> binder.bind(BatchSizes.class).toInstance(BatchSizes.uniqueBatchSize(5))) - .lifeCycle(JamesServerExtension.Lifecycle.PER_TEST) - .build(); - - @Test - void imapFetchBackPressureShouldNotLoadMoreDataThanNecessary(GuiceJamesServer server) throws Exception { - // 800K message - String msgIn = "MIME-Version: 1.0\r\n\r\nCONTENT\r\n\r\n" + "0123456789\r\n0123456789\r\n0123456789\r\n".repeat(25 * 1024); - - server.getProbe(DataProbeImpl.class).fluent() - .addDomain(DOMAIN) - .addUser(JAMES_USER, PASSWORD) - .addUser(SENDER, PASSWORD); - - MailboxProbeImpl mailboxProbe = server.getProbe(MailboxProbeImpl.class); - mailboxProbe.createMailbox("#private", JAMES_USER, DefaultMailboxes.INBOX); - - int messageCount = 20; - - Port smtpPort = Port.of(smtpPort(server)); - try (SMTPMessageSender sender = new SMTPMessageSender(Domain.LOCALHOST.asString())) { - Mono.fromRunnable( - Throwing.runnable(() -> { - sender.connect(JAMES_SERVER_HOST, smtpPort).authenticate(SENDER, PASSWORD); - sender.sendMessageWithHeaders("[email protected]", JAMES_USER, msgIn); - })) - .repeat(messageCount - 1) - .subscribeOn(Schedulers.fromExecutor(EXECUTOR)) - .blockLast(); - } - - CALMLY_AWAIT_FIVE_MINUTE.until(() -> server.getProbe(SpoolerProbe.class).processingFinished()); - - SocketChannel clientConnection = SocketChannel.open(); - clientConnection.connect(new InetSocketAddress(LOCALHOST_IP, imapPort(server))); - readBytes(clientConnection); - clientConnection.write(ByteBuffer.wrap(String.format("a0 LOGIN %s %s\r\n", JAMES_USER, PASSWORD).getBytes(StandardCharsets.UTF_8))); - readBytes(clientConnection); - - clientConnection.write(ByteBuffer.wrap(("A1 SELECT INBOX\r\n").getBytes(StandardCharsets.UTF_8))); - // Select completes first - readStringUntil(clientConnection, s -> s.contains("A1 OK [READ-WRITE] SELECT completed.")); - - TestingSession testingSession = server.getProbe(TestingSessionProbe.class).getTestingSession(); - - StatementRecorder statementRecorder = testingSession.recordStatements(); - clientConnection.write(ByteBuffer.wrap(("A2 UID FETCH 1:500 (BODY.PEEK[])\r\n").getBytes(StandardCharsets.UTF_8))); - - // Await backpressure to trigger - Thread.sleep(2000); - assertThat(statementRecorder - .listExecutedStatements(StatementRecorder.Selector.preparedStatement("SELECT * FROM blobs WHERE id=:id"))) - .hasSizeLessThanOrEqualTo(30); // times 2 for header and blob, 10 skipped 5 prefetch. - } - - private byte[] readBytes(SocketChannel channel) throws IOException { - ByteBuffer line = ByteBuffer.allocate(1024); - channel.read(line); - line.rewind(); - byte[] bline = new byte[line.remaining()]; - line.get(bline); - return bline; - } - - private List<String> readStringUntil(SocketChannel channel, Predicate<String> condition) throws IOException { - ImmutableList.Builder<String> result = ImmutableList.builder(); - while (true) { - String line = new String(readBytes(channel), StandardCharsets.US_ASCII); - System.out.println(line); - result.add(line); - if (condition.test(line)) { - return result.build(); - } - } - } -} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
