You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2020/07/31 09:24:49 UTC

[james-project] 28/28: JAMES-3350 DomainList::autoDetect leads to slow tests

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 fd0a2b6affa73c1c54c3fe521a09cede1b89e81b
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Wed Jul 29 11:27:28 2020 +0700

    JAMES-3350 DomainList::autoDetect leads to slow tests
    
    Switching it off where not necessary unlocks (locally) a 33s => 3s test speedup.
    
    I don't know if the speedup is as impressive on a CI environment but this test speedup is definitly welcomed!
    
    I ended up testing the hostname retrieval only once on top of the memory server in order to limit the expensiveness of this test.
---
 .../org/apache/james/DomainAutodetectionTest.java  | 60 ++++++++++++++++++++++
 1 file changed, 60 insertions(+)

diff --git a/server/container/guice/memory-guice/src/test/java/org/apache/james/DomainAutodetectionTest.java b/server/container/guice/memory-guice/src/test/java/org/apache/james/DomainAutodetectionTest.java
new file mode 100644
index 0000000..ebf9872
--- /dev/null
+++ b/server/container/guice/memory-guice/src/test/java/org/apache/james/DomainAutodetectionTest.java
@@ -0,0 +1,60 @@
+/****************************************************************
+ * 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 java.net.InetAddress;
+
+import org.apache.james.domainlist.lib.DomainListConfiguration;
+import org.apache.james.modules.TestJMAPServerModule;
+import org.apache.james.utils.DataProbeImpl;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+class DomainAutodetectionTest {
+    @RegisterExtension
+    static JamesServerExtension jamesServerExtension = new JamesServerBuilder<>(JamesServerBuilder.defaultConfigurationProvider())
+        .server(configuration -> MemoryJamesServerMain.createServer(configuration)
+            .overrideWith(new TestJMAPServerModule())
+            .overrideWith(binder -> binder.bind(DomainListConfiguration.class)
+                .toInstance(DomainListConfiguration.builder()
+                    .autoDetect(true)
+                    .autoDetectIp(false)
+                    .build())))
+        .lifeCycle(JamesServerExtension.Lifecycle.PER_CLASS)
+        .build();
+
+    @Test
+    void hostnameShouldBeRetrievedWhenRestarting(GuiceJamesServer jamesServer) throws Exception {
+        jamesServer.stop();
+        jamesServer.start();
+        String expectedDefaultDomain = InetAddress.getLocalHost().getHostName();
+
+        assertThat(jamesServer.getProbe(DataProbeImpl.class).getDefaultDomain()).isEqualTo(expectedDefaultDomain);
+    }
+
+    @Test
+    void hostnameShouldBeUsedAsDefaultDomain(GuiceJamesServer jamesServer) throws Exception {
+        String expectedDefaultDomain = InetAddress.getLocalHost().getHostName();
+
+        assertThat(jamesServer.getProbe(DataProbeImpl.class).getDefaultDomain()).isEqualTo(expectedDefaultDomain);
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org