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 2019/10/22 05:44:02 UTC
[james-project] 03/04: JAMES-2866 singleton are not shared between
extensions
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 fe58c21aa67aa32f9dc6fdb5e44a8a44ef46de1d
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Tue Oct 22 01:01:24 2019 +0200
JAMES-2866 singleton are not shared between extensions
---
.../apache/james/utils/GuiceMailetLoaderTest.java | 22 +++++++++++++++++++++
...ustom-mailets-implementation-3.5.0-SNAPSHOT.jar | Bin 11147 -> 11069 bytes
...ailets-3.5.0-SNAPSHOT-jar-with-dependencies.jar | Bin 30473134 -> 30057150 bytes
.../james/transport/mailets/MyExtensionModule.java | 5 +++--
.../james/transport/mailets/MyGenericMailet.java | 17 ++++++++++++++++
5 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuiceMailetLoaderTest.java b/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuiceMailetLoaderTest.java
index b5333d6..e261c1a 100644
--- a/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuiceMailetLoaderTest.java
+++ b/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuiceMailetLoaderTest.java
@@ -33,6 +33,7 @@ import org.apache.mailet.Mailet;
import org.apache.mailet.base.test.FakeMail;
import org.apache.mailet.base.test.FakeMailContext;
import org.apache.mailet.base.test.FakeMailetConfig;
+import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -183,4 +184,25 @@ public class GuiceMailetLoaderTest {
assertThatCode(() -> mailet.service(FakeMail.defaultFakeMail())).doesNotThrowAnyException();
}
+
+ @Ignore("JAMES-2866 singleton are not shared between extensions")
+ @Test
+ public void allMailetsShouldShareTheSameSingleton() throws Exception {
+ GuiceGenericLoader genericLoader = new GuiceGenericLoader(
+ Guice.createInjector(),
+ new ExtendedClassLoader(RECURSIVE_CLASSPATH_FILE_SYSTEM),
+ new ExtensionConfiguration(ImmutableList.of(new ClassName("org.apache.james.transport.mailets.MyExtensionModule"))));
+ GuiceMailetLoader guiceMailetLoader = new GuiceMailetLoader(genericLoader, NO_MAILET_CONFIG_OVERRIDES);
+
+ Mailet mailet1 = guiceMailetLoader.getMailet(FakeMailetConfig.builder()
+ .mailetName("MyGenericMailet")
+ .mailetContext(FakeMailContext.defaultContext())
+ .build());
+ Mailet mailet2 = guiceMailetLoader.getMailet(FakeMailetConfig.builder()
+ .mailetName("MyGenericMailet")
+ .mailetContext(FakeMailContext.defaultContext())
+ .build());
+
+ assertThat(mailet1).isEqualTo(mailet2);
+ }
}
diff --git a/server/container/guice/mailet/src/test/resources/recursive/extensions-jars/custom-mailets-implementation-3.5.0-SNAPSHOT.jar b/server/container/guice/mailet/src/test/resources/recursive/extensions-jars/custom-mailets-implementation-3.5.0-SNAPSHOT.jar
index bd866d9..8dda0fc 100644
Binary files a/server/container/guice/mailet/src/test/resources/recursive/extensions-jars/custom-mailets-implementation-3.5.0-SNAPSHOT.jar and b/server/container/guice/mailet/src/test/resources/recursive/extensions-jars/custom-mailets-implementation-3.5.0-SNAPSHOT.jar differ
diff --git a/server/container/guice/mailet/src/test/resources/recursive/extensions-jars/james-server-guice-custom-mailets-3.5.0-SNAPSHOT-jar-with-dependencies.jar b/server/container/guice/mailet/src/test/resources/recursive/extensions-jars/james-server-guice-custom-mailets-3.5.0-SNAPSHOT-jar-with-dependencies.jar
index 2f73d5b..1158dc5 100644
Binary files a/server/container/guice/mailet/src/test/resources/recursive/extensions-jars/james-server-guice-custom-mailets-3.5.0-SNAPSHOT-jar-with-dependencies.jar and b/server/container/guice/mailet/src/test/resources/recursive/extensions-jars/james-server-guice-custom-mailets-3.5.0-SNAPSHOT-jar-with-dependencies.jar differ
diff --git a/server/container/guice/testing/custom-mailets-implementation/src/main/java/org/apache/james/transport/mailets/MyExtensionModule.java b/server/container/guice/testing/custom-mailets-implementation/src/main/java/org/apache/james/transport/mailets/MyExtensionModule.java
index cd6b70f..924a01d 100644
--- a/server/container/guice/testing/custom-mailets-implementation/src/main/java/org/apache/james/transport/mailets/MyExtensionModule.java
+++ b/server/container/guice/testing/custom-mailets-implementation/src/main/java/org/apache/james/transport/mailets/MyExtensionModule.java
@@ -20,11 +20,12 @@
package org.apache.james.transport.mailets;
import com.google.inject.AbstractModule;
+import com.google.inject.Scopes;
public class MyExtensionModule extends AbstractModule {
@Override
protected void configure() {
- bind(MyInterface.class)
- .to(MyInterfaceImplementation.class);
+ bind(MyInterfaceImplementation.class).in(Scopes.SINGLETON);
+ bind(MyInterface.class).to(MyInterfaceImplementation.class);
}
}
diff --git a/server/container/guice/testing/custom-mailets/src/main/java/org/apache/james/transport/mailets/MyGenericMailet.java b/server/container/guice/testing/custom-mailets/src/main/java/org/apache/james/transport/mailets/MyGenericMailet.java
index a0e28d4..17c7039 100644
--- a/server/container/guice/testing/custom-mailets/src/main/java/org/apache/james/transport/mailets/MyGenericMailet.java
+++ b/server/container/guice/testing/custom-mailets/src/main/java/org/apache/james/transport/mailets/MyGenericMailet.java
@@ -19,6 +19,8 @@
package org.apache.james.transport.mailets;
+import java.util.Objects;
+
import javax.inject.Inject;
import javax.mail.MessagingException;
@@ -37,4 +39,19 @@ public class MyGenericMailet extends GenericMailet {
public void service(Mail mail) throws MessagingException {
myInterface.doSomething();
}
+
+ @Override
+ public final boolean equals(Object o) {
+ if (o instanceof MyGenericMailet) {
+ MyGenericMailet that = (MyGenericMailet) o;
+
+ return Objects.equals(this.myInterface, that.myInterface);
+ }
+ return false;
+ }
+
+ @Override
+ public final int hashCode() {
+ return Objects.hash(myInterface);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org