james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [08/21] james-project git commit: MAILBOX-342 Don't use mapper provider for AnnotationMapperTest
Date Fri, 06 Jul 2018 09:27:34 GMT
MAILBOX-342 Don't use mapper provider for AnnotationMapperTest

In Cassandra test by limiting loaded modules, 27s -> 4s


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/4bd253a6
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/4bd253a6
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/4bd253a6

Branch: refs/heads/master
Commit: 4bd253a64c5347756238984f4f9268a1cedb6abd
Parents: ddb928d
Author: benwa <btellier@linagora.com>
Authored: Thu Jul 5 10:20:45 2018 +0700
Committer: benwa <btellier@linagora.com>
Committed: Fri Jul 6 16:25:50 2018 +0700

----------------------------------------------------------------------
 .../mail/CassandraAnnotationMapper.java         |  3 ++
 .../mail/CassandraAnnotationMapperTest.java     | 46 ++++++--------------
 .../jpa/mail/JpaAnnotationMapperTest.java       | 25 +++++++++--
 .../mail/MemoryAnnotationMapperTest.java        | 21 ++++++---
 .../store/mail/model/AnnotationMapperTest.java  | 13 +++---
 5 files changed, 59 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/4bd253a6/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAnnotationMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAnnotationMapper.java
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAnnotationMapper.java
index f689e39..7a96dd7 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAnnotationMapper.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAnnotationMapper.java
@@ -33,6 +33,8 @@ import java.util.Set;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
+import javax.inject.Inject;
+
 import org.apache.james.backends.cassandra.utils.CassandraUtils;
 import org.apache.james.mailbox.cassandra.ids.CassandraId;
 import org.apache.james.mailbox.cassandra.table.CassandraAnnotationTable;
@@ -54,6 +56,7 @@ public class CassandraAnnotationMapper extends NonTransactionalMapper implements
     private final Session session;
     private final CassandraUtils cassandraUtils;
 
+    @Inject
     public CassandraAnnotationMapper(Session session, CassandraUtils cassandraUtils) {
         this.session = session;
         this.cassandraUtils = cassandraUtils;

http://git-wip-us.apache.org/repos/asf/james-project/blob/4bd253a6/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraAnnotationMapperTest.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraAnnotationMapperTest.java
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraAnnotationMapperTest.java
index fd8e8e3..53aca9e 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraAnnotationMapperTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraAnnotationMapperTest.java
@@ -21,22 +21,12 @@ package org.apache.james.mailbox.cassandra.mail;
 
 import org.apache.james.backends.cassandra.CassandraCluster;
 import org.apache.james.backends.cassandra.DockerCassandraRule;
-import org.apache.james.backends.cassandra.init.CassandraModuleComposite;
-import org.apache.james.blob.cassandra.CassandraBlobModule;
-import org.apache.james.mailbox.cassandra.modules.CassandraAclModule;
+import org.apache.james.mailbox.cassandra.ids.CassandraId;
+import org.apache.james.mailbox.cassandra.mail.utils.GuiceUtils;
 import org.apache.james.mailbox.cassandra.modules.CassandraAnnotationModule;
-import org.apache.james.mailbox.cassandra.modules.CassandraApplicableFlagsModule;
-import org.apache.james.mailbox.cassandra.modules.CassandraAttachmentModule;
-import org.apache.james.mailbox.cassandra.modules.CassandraDeletedMessageModule;
-import org.apache.james.mailbox.cassandra.modules.CassandraFirstUnseenModule;
-import org.apache.james.mailbox.cassandra.modules.CassandraMailboxCounterModule;
-import org.apache.james.mailbox.cassandra.modules.CassandraMailboxModule;
-import org.apache.james.mailbox.cassandra.modules.CassandraMailboxRecentsModule;
-import org.apache.james.mailbox.cassandra.modules.CassandraMessageModule;
-import org.apache.james.mailbox.cassandra.modules.CassandraModSeqModule;
-import org.apache.james.mailbox.cassandra.modules.CassandraUidModule;
+import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.store.mail.AnnotationMapper;
 import org.apache.james.mailbox.store.mail.model.AnnotationMapperTest;
-import org.apache.james.mailbox.store.mail.model.MapperProvider;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.ClassRule;
@@ -50,21 +40,7 @@ public class CassandraAnnotationMapperTest extends AnnotationMapperTest
{
     @Override
     @Before
     public void setUp() throws Exception {
-        CassandraModuleComposite modules = new CassandraModuleComposite(
-                new CassandraAclModule(),
-                new CassandraMailboxModule(),
-                new CassandraMessageModule(),
-                new CassandraMailboxCounterModule(),
-                new CassandraMailboxRecentsModule(),
-                new CassandraModSeqModule(),
-                new CassandraUidModule(),
-                new CassandraAttachmentModule(),
-                new CassandraAnnotationModule(),
-                new CassandraFirstUnseenModule(),
-                new CassandraApplicableFlagsModule(),
-                new CassandraDeletedMessageModule(),
-                new CassandraBlobModule());
-        this.cassandra = CassandraCluster.create(modules, cassandraServer.getIp(), cassandraServer.getBindingPort());
+        this.cassandra = CassandraCluster.create(new CassandraAnnotationModule(), cassandraServer.getHost());
         super.setUp();
     }
     
@@ -72,9 +48,15 @@ public class CassandraAnnotationMapperTest extends AnnotationMapperTest
{
     public void tearDown() {
         cassandra.close();
     }
-    
+
+    @Override
+    protected AnnotationMapper createAnnotationMapper() {
+        return GuiceUtils.testInjector(cassandra)
+            .getInstance(CassandraAnnotationMapper.class);
+    }
+
     @Override
-    protected MapperProvider createMapperProvider() {
-        return new CassandraMapperProvider(cassandra);
+    protected MailboxId generateMailboxId() {
+        return CassandraId.timeBased();
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/4bd253a6/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/JpaAnnotationMapperTest.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/JpaAnnotationMapperTest.java
b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/JpaAnnotationMapperTest.java
index e6b0dfa..c697b2e 100644
--- a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/JpaAnnotationMapperTest.java
+++ b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/JpaAnnotationMapperTest.java
@@ -19,24 +19,41 @@
 
 package org.apache.james.mailbox.jpa.mail;
 
+import java.util.concurrent.atomic.AtomicInteger;
+
 import org.apache.james.backends.jpa.JpaTestCluster;
+import org.apache.james.mailbox.jpa.JPAId;
 import org.apache.james.mailbox.jpa.JPAMailboxFixture;
+import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.store.mail.AnnotationMapper;
 import org.apache.james.mailbox.store.mail.model.AnnotationMapperTest;
-import org.apache.james.mailbox.store.mail.model.MapperProvider;
+import org.junit.After;
 import org.junit.Before;
 
 public class JpaAnnotationMapperTest extends AnnotationMapperTest {
 
     public static final JpaTestCluster JPA_TEST_CLUSTER = JpaTestCluster.create(JPAMailboxFixture.MAILBOX_PERSISTANCE_CLASSES);
 
+    private final AtomicInteger counter = new AtomicInteger();
+
     @Override
     @Before
     public void setUp() throws Exception {
         super.setUp();
     }
-    
+
+    @After
+    public void tearDown() {
+        JPA_TEST_CLUSTER.clear(JPAMailboxFixture.MAILBOX_TABLE_NAMES);
+    }
+
+    @Override
+    protected AnnotationMapper createAnnotationMapper() {
+        return new TransactionalAnnotationMapper(new JPAAnnotationMapper(JPA_TEST_CLUSTER.getEntityManagerFactory()));
+    }
+
     @Override
-    protected MapperProvider createMapperProvider() {
-        return new JPAMapperProvider(JPA_TEST_CLUSTER);
+    protected MailboxId generateMailboxId() {
+        return JPAId.of(counter.incrementAndGet());
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/4bd253a6/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/MemoryAnnotationMapperTest.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/MemoryAnnotationMapperTest.java
b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/MemoryAnnotationMapperTest.java
index 1e3c04e..6e736fb 100644
--- a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/MemoryAnnotationMapperTest.java
+++ b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/MemoryAnnotationMapperTest.java
@@ -19,20 +19,31 @@
 
 package org.apache.james.mailbox.inmemory.mail;
 
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.james.mailbox.inmemory.InMemoryId;
+import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.store.mail.AnnotationMapper;
 import org.apache.james.mailbox.store.mail.model.AnnotationMapperTest;
-import org.apache.james.mailbox.store.mail.model.MapperProvider;
 import org.junit.Before;
 
 public class MemoryAnnotationMapperTest extends AnnotationMapperTest {
-    
+
+    private final AtomicInteger counter = new AtomicInteger();
+
     @Override
     @Before
     public void setUp() throws Exception {
         super.setUp();
     }
-    
+
+    @Override
+    protected AnnotationMapper createAnnotationMapper() {
+        return new InMemoryAnnotationMapper();
+    }
+
     @Override
-    protected MapperProvider createMapperProvider() {
-        return new InMemoryMapperProvider();
+    protected MailboxId generateMailboxId() {
+        return InMemoryId.of(counter.incrementAndGet());
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/4bd253a6/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AnnotationMapperTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AnnotationMapperTest.java
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AnnotationMapperTest.java
index 06b8f2a..e1552fb 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AnnotationMapperTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AnnotationMapperTest.java
@@ -26,7 +26,6 @@ import org.apache.james.mailbox.model.MailboxAnnotation;
 import org.apache.james.mailbox.model.MailboxAnnotationKey;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.store.mail.AnnotationMapper;
-import org.junit.Assume;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -51,20 +50,18 @@ public abstract class AnnotationMapperTest {
     private static final MailboxAnnotation PRIVATE_GRANDCHILD_ANNOTATION = MailboxAnnotation.newInstance(PRIVATE_GRANDCHILD_KEY,
"My private comment");
 
     private AnnotationMapper annotationMapper;
-    private MapperProvider mapperProvider;
     private MailboxId mailboxId;
 
     @Rule
     public ExpectedException expected = ExpectedException.none();
 
-    protected abstract MapperProvider createMapperProvider();
+    protected abstract AnnotationMapper createAnnotationMapper();
 
-    public void setUp() throws Exception {
-        mapperProvider = createMapperProvider();
-        Assume.assumeTrue(mapperProvider.getSupportedCapabilities().contains(MapperProvider.Capabilities.ANNOTATION));
+    protected abstract MailboxId generateMailboxId();
 
-        this.annotationMapper = mapperProvider.createAnnotationMapper();
-        this.mailboxId = mapperProvider.generateId();
+    public void setUp() throws Exception {
+        this.annotationMapper = createAnnotationMapper();
+        this.mailboxId = generateMailboxId();
     }
 
     @Test


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


Mime
View raw message