james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [01/21] james-project git commit: JAMES-2272 Introduce a generic Task
Date Thu, 04 Jan 2018 08:13:16 GMT
Repository: james-project
Updated Branches:
  refs/heads/master 7875cc08f -> 7d15ef0e6


JAMES-2272 Introduce a generic Task

Migration is a Task


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

Branch: refs/heads/master
Commit: 3f26590127a811c578104816d4b12937322a0c48
Parents: 7875cc0
Author: benwa <btellier@linagora.com>
Authored: Wed Dec 27 11:14:01 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Thu Jan 4 15:00:42 2018 +0700

----------------------------------------------------------------------
 backends-common/cassandra/pom.xml               |  4 ++
 .../backends/cassandra/migration/Migration.java | 26 ++++++++++
 mailbox/cassandra/pom.xml                       |  4 ++
 .../migration/AttachmentMessageIdCreation.java  | 18 ++++---
 .../mail/migration/AttachmentV2Migration.java   | 13 ++---
 .../cassandra/mail/migration/Migration.java     | 43 ----------------
 .../AttachmentMessageIdCreationTest.java        | 11 ++--
 .../migration/AttachmentV2MigrationTest.java    | 15 +++---
 pom.xml                                         |  5 ++
 .../modules/server/CassandraRoutesModule.java   |  4 +-
 server/pom.xml                                  |  1 +
 .../service/CassandraMigrationServiceTest.java  | 12 ++---
 server/task/pom.xml                             | 54 ++++++++++++++++++++
 .../main/java/org/apache/james/task/Task.java   | 44 ++++++++++++++++
 .../java/org/apache/james/task/TaskTest.java    | 52 +++++++++++++++++++
 15 files changed, 229 insertions(+), 77 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/3f265901/backends-common/cassandra/pom.xml
----------------------------------------------------------------------
diff --git a/backends-common/cassandra/pom.xml b/backends-common/cassandra/pom.xml
index 66d3bb3..36aa204 100644
--- a/backends-common/cassandra/pom.xml
+++ b/backends-common/cassandra/pom.xml
@@ -37,6 +37,10 @@
         </dependency>
         <dependency>
             <groupId>${project.groupId}</groupId>
+            <artifactId>james-server-task</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
             <artifactId>james-server-util-java8</artifactId>
         </dependency>
         <dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/3f265901/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/migration/Migration.java
----------------------------------------------------------------------
diff --git a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/migration/Migration.java
b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/migration/Migration.java
new file mode 100644
index 0000000..b4f15f4
--- /dev/null
+++ b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/migration/Migration.java
@@ -0,0 +1,26 @@
+/****************************************************************
+ * 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.backends.cassandra.migration;
+
+import org.apache.james.task.Task;
+
+public interface Migration extends Task {
+
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/3f265901/mailbox/cassandra/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/pom.xml b/mailbox/cassandra/pom.xml
index 73b5d45..5bffe2b 100644
--- a/mailbox/cassandra/pom.xml
+++ b/mailbox/cassandra/pom.xml
@@ -64,6 +64,10 @@
         </dependency>
         <dependency>
             <groupId>${project.groupId}</groupId>
+            <artifactId>james-server-task</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
             <artifactId>james-server-util</artifactId>
             <scope>test</scope>
         </dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/3f265901/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/migration/AttachmentMessageIdCreation.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/migration/AttachmentMessageIdCreation.java
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/migration/AttachmentMessageIdCreation.java
index adcc1ff..37e8358 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/migration/AttachmentMessageIdCreation.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/migration/AttachmentMessageIdCreation.java
@@ -21,6 +21,7 @@ package org.apache.james.mailbox.cassandra.mail.migration;
 
 import javax.inject.Inject;
 
+import org.apache.james.backends.cassandra.migration.Migration;
 import org.apache.james.mailbox.cassandra.mail.CassandraAttachmentMessageIdDAO;
 import org.apache.james.mailbox.cassandra.mail.CassandraMessageDAO;
 import org.apache.james.mailbox.cassandra.mail.CassandraMessageDAO.MessageIdAttachmentIds;
@@ -40,27 +41,28 @@ public class AttachmentMessageIdCreation implements Migration {
     }
 
     @Override
-    public MigrationResult run() {
+    public Result run() {
         try {
             return cassandraMessageDAO.retrieveAllMessageIdAttachmentIds()
                 .join()
                 .map(this::createIndex)
-                .reduce(MigrationResult.COMPLETED, Migration::combine);
+                .reduce(Result.COMPLETED, Migration::combine);
         } catch (Exception e) {
             LOGGER.error("Error while creation attachmentId -> messageIds index", e);
-            return MigrationResult.PARTIAL;
+            return Result.PARTIAL;
         }
     }
 
-    private MigrationResult createIndex(MessageIdAttachmentIds message) {
+    private Result createIndex(MessageIdAttachmentIds message) {
         try {
             message.getAttachmentId()
-                .stream()
-                .forEach(attachmentId -> attachmentMessageIdDAO.storeAttachmentForMessageId(attachmentId,
message.getMessageId()).join());
-            return MigrationResult.COMPLETED;
+                .forEach(attachmentId -> attachmentMessageIdDAO
+                    .storeAttachmentForMessageId(attachmentId, message.getMessageId())
+                    .join());
+            return Result.COMPLETED;
         } catch (Exception e) {
             LOGGER.error("Error while creation attachmentId -> messageIds index", e);
-            return MigrationResult.PARTIAL;
+            return Result.PARTIAL;
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/3f265901/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/migration/AttachmentV2Migration.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/migration/AttachmentV2Migration.java
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/migration/AttachmentV2Migration.java
index 8290deb..ca5c116 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/migration/AttachmentV2Migration.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/migration/AttachmentV2Migration.java
@@ -21,6 +21,7 @@ package org.apache.james.mailbox.cassandra.mail.migration;
 
 import javax.inject.Inject;
 
+import org.apache.james.backends.cassandra.migration.Migration;
 import org.apache.james.mailbox.cassandra.mail.CassandraAttachmentDAO;
 import org.apache.james.mailbox.cassandra.mail.CassandraAttachmentDAOV2;
 import org.apache.james.mailbox.cassandra.mail.CassandraBlobsDAO;
@@ -44,28 +45,28 @@ public class AttachmentV2Migration implements Migration {
     }
 
     @Override
-    public MigrationResult run() {
+    public Result run() {
         try {
             return attachmentDAOV1.retrieveAll()
                 .map(this::migrateAttachment)
-                .reduce(MigrationResult.COMPLETED, Migration::combine);
+                .reduce(Result.COMPLETED, Migration::combine);
         } catch (Exception e) {
             LOGGER.error("Error while performing attachmentDAO V2 migration", e);
-            return MigrationResult.PARTIAL;
+            return Result.PARTIAL;
         }
     }
 
-    private MigrationResult migrateAttachment(Attachment attachment) {
+    private Result migrateAttachment(Attachment attachment) {
         try {
             blobsDAO.save(attachment.getBytes())
                 .thenApply(blobId -> CassandraAttachmentDAOV2.from(attachment, blobId))
                 .thenCompose(attachmentDAOV2::storeAttachment)
                 .thenCompose(any -> attachmentDAOV1.deleteAttachment(attachment.getAttachmentId()))
                 .join();
-            return MigrationResult.COMPLETED;
+            return Result.COMPLETED;
         } catch (Exception e) {
             LOGGER.error("Error while performing attachmentDAO V2 migration", e);
-            return MigrationResult.PARTIAL;
+            return Result.PARTIAL;
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/3f265901/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/migration/Migration.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/migration/Migration.java
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/migration/Migration.java
deleted file mode 100644
index 247c72a..0000000
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/migration/Migration.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.mailbox.cassandra.mail.migration;
-
-public interface Migration {
-
-    enum MigrationResult {
-        COMPLETED,
-        PARTIAL
-    }
-
-    static MigrationResult combine(MigrationResult result1, MigrationResult result2) {
-        if (result1 == MigrationResult.COMPLETED
-            && result2 == MigrationResult.COMPLETED) {
-            return MigrationResult.COMPLETED;
-        }
-        return MigrationResult.PARTIAL;
-    }
-
-    /**
-     * Runs the migration
-     *
-     * @return Return true if fully migrated. Returns false otherwise.
-     */
-    MigrationResult run();
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/3f265901/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/migration/AttachmentMessageIdCreationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/migration/AttachmentMessageIdCreationTest.java
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/migration/AttachmentMessageIdCreationTest.java
index e333368..b4ec37e 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/migration/AttachmentMessageIdCreationTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/migration/AttachmentMessageIdCreationTest.java
@@ -37,6 +37,7 @@ import javax.mail.util.SharedByteArrayInputStream;
 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.backends.cassandra.migration.Migration;
 import org.apache.james.backends.cassandra.utils.CassandraUtils;
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.cassandra.ids.CassandraId;
@@ -99,7 +100,7 @@ public class AttachmentMessageIdCreationTest {
     @Test
     public void emptyMigrationShouldSucceed() {
         assertThat(migration.run())
-            .isEqualTo(Migration.MigrationResult.COMPLETED);
+            .isEqualTo(Migration.Result.COMPLETED);
     }
 
     @Test
@@ -110,7 +111,7 @@ public class AttachmentMessageIdCreationTest {
         cassandraMessageDAO.save(message).join();
 
         assertThat(migration.run())
-            .isEqualTo(Migration.MigrationResult.COMPLETED);
+            .isEqualTo(Migration.Result.COMPLETED);
     }
 
     @Test
@@ -121,7 +122,7 @@ public class AttachmentMessageIdCreationTest {
         cassandraMessageDAO.save(message).join();
 
         assertThat(migration.run())
-            .isEqualTo(Migration.MigrationResult.COMPLETED);
+            .isEqualTo(Migration.Result.COMPLETED);
     }
 
     @Test
@@ -145,7 +146,7 @@ public class AttachmentMessageIdCreationTest {
 
         when(cassandraMessageDAO.retrieveAllMessageIdAttachmentIds()).thenThrow(new RuntimeException());
 
-        assertThat(migration.run()).isEqualTo(Migration.MigrationResult.PARTIAL);
+        assertThat(migration.run()).isEqualTo(Migration.Result.PARTIAL);
     }
 
     @Test
@@ -162,7 +163,7 @@ public class AttachmentMessageIdCreationTest {
         when(attachmentMessageIdDAO.storeAttachmentForMessageId(any(AttachmentId.class),
any(MessageId.class)))
             .thenThrow(new RuntimeException());
 
-        assertThat(migration.run()).isEqualTo(Migration.MigrationResult.PARTIAL);
+        assertThat(migration.run()).isEqualTo(Migration.Result.PARTIAL);
     }
 
     private SimpleMailboxMessage createMessage(MessageId messageId, Collection<MessageAttachment>
attachments) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/3f265901/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/migration/AttachmentV2MigrationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/migration/AttachmentV2MigrationTest.java
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/migration/AttachmentV2MigrationTest.java
index 1b92747..0f456ac 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/migration/AttachmentV2MigrationTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/migration/AttachmentV2MigrationTest.java
@@ -32,6 +32,7 @@ import org.apache.james.backends.cassandra.CassandraCluster;
 import org.apache.james.backends.cassandra.DockerCassandraRule;
 import org.apache.james.backends.cassandra.init.CassandraConfiguration;
 import org.apache.james.backends.cassandra.init.CassandraModuleComposite;
+import org.apache.james.backends.cassandra.migration.Migration;
 import org.apache.james.backends.cassandra.utils.CassandraUtils;
 import org.apache.james.mailbox.cassandra.ids.BlobId;
 import org.apache.james.mailbox.cassandra.mail.CassandraAttachmentDAO;
@@ -91,7 +92,7 @@ public class AttachmentV2MigrationTest {
     @Test
     public void emptyMigrationShouldSucceed() {
         assertThat(migration.run())
-            .isEqualTo(Migration.MigrationResult.COMPLETED);
+            .isEqualTo(Migration.Result.COMPLETED);
     }
 
     @Test
@@ -100,7 +101,7 @@ public class AttachmentV2MigrationTest {
         attachmentDAO.storeAttachment(attachment2).join();
 
         assertThat(migration.run())
-            .isEqualTo(Migration.MigrationResult.COMPLETED);
+            .isEqualTo(Migration.Result.COMPLETED);
     }
 
     @Test
@@ -142,7 +143,7 @@ public class AttachmentV2MigrationTest {
 
         when(attachmentDAO.retrieveAll()).thenThrow(new RuntimeException());
 
-        assertThat(migration.run()).isEqualTo(Migration.MigrationResult.PARTIAL);
+        assertThat(migration.run()).isEqualTo(Migration.Result.PARTIAL);
     }
 
     @Test
@@ -157,7 +158,7 @@ public class AttachmentV2MigrationTest {
             attachment2));
         when(blobsDAO.save(any())).thenThrow(new RuntimeException());
 
-        assertThat(migration.run()).isEqualTo(Migration.MigrationResult.PARTIAL);
+        assertThat(migration.run()).isEqualTo(Migration.Result.PARTIAL);
     }
 
     @Test
@@ -176,7 +177,7 @@ public class AttachmentV2MigrationTest {
             .thenReturn(CompletableFuture.completedFuture(BlobId.forPayload(attachment2.getBytes())));
         when(attachmentDAOV2.storeAttachment(any())).thenThrow(new RuntimeException());
 
-        assertThat(migration.run()).isEqualTo(Migration.MigrationResult.PARTIAL);
+        assertThat(migration.run()).isEqualTo(Migration.Result.PARTIAL);
     }
 
     @Test
@@ -196,7 +197,7 @@ public class AttachmentV2MigrationTest {
         when(attachmentDAOV2.storeAttachment(any())).thenReturn(CompletableFuture.completedFuture(null));
         when(attachmentDAO.deleteAttachment(any())).thenThrow(new RuntimeException());
 
-        assertThat(migration.run()).isEqualTo(Migration.MigrationResult.PARTIAL);
+        assertThat(migration.run()).isEqualTo(Migration.Result.PARTIAL);
     }
 
     @Test
@@ -216,7 +217,7 @@ public class AttachmentV2MigrationTest {
         when(attachmentDAOV2.storeAttachment(any())).thenReturn(CompletableFuture.completedFuture(null));
         when(attachmentDAO.deleteAttachment(any())).thenReturn(CompletableFuture.completedFuture(null));
 
-        assertThat(migration.run()).isEqualTo(Migration.MigrationResult.PARTIAL);
+        assertThat(migration.run()).isEqualTo(Migration.Result.PARTIAL);
     }
 
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/3f265901/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 8956ad0..fdd34c0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1316,6 +1316,11 @@
             </dependency>
             <dependency>
                 <groupId>${project.groupId}</groupId>
+                <artifactId>james-server-task</artifactId>
+                <version>${project.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>${project.groupId}</groupId>
                 <artifactId>james-server-util</artifactId>
                 <version>${project.version}</version>
             </dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/3f265901/server/container/guice/protocols/webadmin-cassandra/src/main/java/org/apache/james/modules/server/CassandraRoutesModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/protocols/webadmin-cassandra/src/main/java/org/apache/james/modules/server/CassandraRoutesModule.java
b/server/container/guice/protocols/webadmin-cassandra/src/main/java/org/apache/james/modules/server/CassandraRoutesModule.java
index ae2340f..6fe2792 100644
--- a/server/container/guice/protocols/webadmin-cassandra/src/main/java/org/apache/james/modules/server/CassandraRoutesModule.java
+++ b/server/container/guice/protocols/webadmin-cassandra/src/main/java/org/apache/james/modules/server/CassandraRoutesModule.java
@@ -19,10 +19,10 @@
 
 package org.apache.james.modules.server;
 
+import org.apache.james.backends.cassandra.migration.Migration;
 import org.apache.james.backends.cassandra.versions.CassandraSchemaVersionManager;
 import org.apache.james.mailbox.cassandra.mail.migration.AttachmentMessageIdCreation;
 import org.apache.james.mailbox.cassandra.mail.migration.AttachmentV2Migration;
-import org.apache.james.mailbox.cassandra.mail.migration.Migration;
 import org.apache.james.webadmin.Routes;
 import org.apache.james.webadmin.routes.CassandraMigrationRoutes;
 import org.apache.james.webadmin.service.CassandraMigrationService;
@@ -47,7 +47,7 @@ public class CassandraRoutesModule extends AbstractModule {
         routesMultibinder.addBinding().to(CassandraMigrationRoutes.class);
 
         MapBinder<Integer, Migration> allMigrationClazzBinder = MapBinder.newMapBinder(binder(),
Integer.class, Migration.class);
-        allMigrationClazzBinder.addBinding(FROM_V2_TO_V3).toInstance(() -> Migration.MigrationResult.COMPLETED);
+        allMigrationClazzBinder.addBinding(FROM_V2_TO_V3).toInstance(() -> Migration.Result.COMPLETED);
         allMigrationClazzBinder.addBinding(FROM_V3_TO_V4).to(AttachmentV2Migration.class);
         allMigrationClazzBinder.addBinding(FROM_V4_TO_V5).to(AttachmentMessageIdCreation.class);
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/3f265901/server/pom.xml
----------------------------------------------------------------------
diff --git a/server/pom.xml b/server/pom.xml
index cff65bb..3414224 100644
--- a/server/pom.xml
+++ b/server/pom.xml
@@ -98,6 +98,7 @@
         <module>queue/queue-file</module>
         <module>queue/queue-jms</module>
 
+        <module>task</module>
         <module>testing</module>
     </modules>
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/3f265901/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/service/CassandraMigrationServiceTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/service/CassandraMigrationServiceTest.java
b/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/service/CassandraMigrationServiceTest.java
index 677f5d8..0e7496f 100644
--- a/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/service/CassandraMigrationServiceTest.java
+++ b/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/service/CassandraMigrationServiceTest.java
@@ -38,8 +38,8 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.commons.lang.NotImplementedException;
+import org.apache.james.backends.cassandra.migration.Migration;
 import org.apache.james.backends.cassandra.versions.CassandraSchemaVersionDAO;
-import org.apache.james.mailbox.cassandra.mail.migration.Migration;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
@@ -66,7 +66,7 @@ public class CassandraMigrationServiceTest {
     public void setUp() throws Exception {
         schemaVersionDAO = mock(CassandraSchemaVersionDAO.class);
         successfulMigration = mock(Migration.class);
-        when(successfulMigration.run()).thenReturn(Migration.MigrationResult.COMPLETED);
+        when(successfulMigration.run()).thenReturn(Migration.Result.COMPLETED);
         Map<Integer, Migration> allMigrationClazz = ImmutableMap.<Integer, Migration>builder()
             .put(OLDER_VERSION, successfulMigration)
             .put(CURRENT_VERSION, successfulMigration)
@@ -167,7 +167,7 @@ public class CassandraMigrationServiceTest {
         Migration wait1SecondMigration = mock(Migration.class);
         doAnswer(invocation -> {
             Thread.sleep(1000);
-            return Migration.MigrationResult.COMPLETED;
+            return Migration.Result.COMPLETED;
         }).when(wait1SecondMigration).run();
         Map<Integer, Migration> allMigrationClazz = ImmutableMap.<Integer, Migration>builder()
             .put(OLDER_VERSION, wait1SecondMigration)
@@ -201,7 +201,7 @@ public class CassandraMigrationServiceTest {
     @Test
     public void partialMigrationShouldThrow() throws Exception {
         Migration migration1 = mock(Migration.class);
-        when(migration1.run()).thenReturn(Migration.MigrationResult.PARTIAL);
+        when(migration1.run()).thenReturn(Migration.Result.PARTIAL);
         Migration migration2 = successfulMigration;
 
         Map<Integer, Migration> allMigrationClazz = ImmutableMap.<Integer, Migration>builder()
@@ -218,9 +218,9 @@ public class CassandraMigrationServiceTest {
     @Test
     public void partialMigrationShouldAbortMigrations() throws Exception {
         Migration migration1 = mock(Migration.class);
-        when(migration1.run()).thenReturn(Migration.MigrationResult.PARTIAL);
+        when(migration1.run()).thenReturn(Migration.Result.PARTIAL);
         Migration migration2 = mock(Migration.class);
-        when(migration2.run()).thenReturn(Migration.MigrationResult.COMPLETED);
+        when(migration2.run()).thenReturn(Migration.Result.COMPLETED);
 
         Map<Integer, Migration> allMigrationClazz = ImmutableMap.<Integer, Migration>builder()
             .put(OLDER_VERSION, migration1)

http://git-wip-us.apache.org/repos/asf/james-project/blob/3f265901/server/task/pom.xml
----------------------------------------------------------------------
diff --git a/server/task/pom.xml b/server/task/pom.xml
new file mode 100644
index 0000000..96a049d
--- /dev/null
+++ b/server/task/pom.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <artifactId>james-server</artifactId>
+        <groupId>org.apache.james</groupId>
+        <version>3.1.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>james-server-task</artifactId>
+    <name>Apache James :: Server :: Task</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>james-server-util-java8</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>nl.jqno.equalsverifier</groupId>
+            <artifactId>equalsverifier</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</artifactId>
+        </dependency>
+    </dependencies>
+
+</project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/3f265901/server/task/src/main/java/org/apache/james/task/Task.java
----------------------------------------------------------------------
diff --git a/server/task/src/main/java/org/apache/james/task/Task.java b/server/task/src/main/java/org/apache/james/task/Task.java
new file mode 100644
index 0000000..87ce233
--- /dev/null
+++ b/server/task/src/main/java/org/apache/james/task/Task.java
@@ -0,0 +1,44 @@
+/****************************************************************
+ * 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.task;
+
+public interface Task {
+
+    enum Result {
+        COMPLETED,
+        PARTIAL
+    }
+
+    static Result combine(Result result1, Result result2) {
+        if (result1 == Result.COMPLETED
+            && result2 == Result.COMPLETED) {
+            return Result.COMPLETED;
+        }
+        return Result.PARTIAL;
+    }
+
+    /**
+     * Runs the migration
+     *
+     * @return Return true if fully migrated. Returns false otherwise.
+     */
+    Result run();
+
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/3f265901/server/task/src/test/java/org/apache/james/task/TaskTest.java
----------------------------------------------------------------------
diff --git a/server/task/src/test/java/org/apache/james/task/TaskTest.java b/server/task/src/test/java/org/apache/james/task/TaskTest.java
new file mode 100644
index 0000000..55ec2f4
--- /dev/null
+++ b/server/task/src/test/java/org/apache/james/task/TaskTest.java
@@ -0,0 +1,52 @@
+/****************************************************************
+ * 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.task;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.Test;
+
+public class TaskTest {
+
+    @Test
+    public void combineShouldReturnCompletedWhenBothCompleted() {
+        assertThat(Task.combine(Task.Result.COMPLETED, Task.Result.COMPLETED))
+            .isEqualTo(Task.Result.COMPLETED);
+    }
+
+    @Test
+    public void combineShouldReturnPartialWhenPartialLeft() {
+        assertThat(Task.combine(Task.Result.PARTIAL, Task.Result.COMPLETED))
+            .isEqualTo(Task.Result.PARTIAL);
+    }
+
+    @Test
+    public void combineShouldReturnPartialWhenPartialRight() {
+        assertThat(Task.combine(Task.Result.COMPLETED, Task.Result.PARTIAL))
+            .isEqualTo(Task.Result.PARTIAL);
+    }
+
+    @Test
+    public void combineShouldReturnPartialWhenBothPartial() {
+        assertThat(Task.combine(Task.Result.PARTIAL, Task.Result.PARTIAL))
+            .isEqualTo(Task.Result.PARTIAL);
+    }
+
+}
\ No newline at end of file


---------------------------------------------------------------------
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