james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rouaz...@apache.org
Subject [3/3] james-project git commit: JAMES-2604 Fix ReIndexAll CLI calling
Date Fri, 23 Nov 2018 09:00:52 GMT
JAMES-2604 Fix ReIndexAll CLI calling


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

Branch: refs/heads/master
Commit: bac6c348c8e8d6fc3f46d7ec3d705cdd3e048526
Parents: c21204b
Author: Gautier DI FOLCO <gdifolco@linagora.com>
Authored: Tue Nov 20 11:08:43 2018 +0100
Committer: Raphael Ouazana <raphael.ouazana@linagora.com>
Committed: Fri Nov 23 09:59:45 2018 +0100

----------------------------------------------------------------------
 server/container/mailbox-jmx/pom.xml            | 18 +++--
 .../adapter/mailbox/ReIndexerManagement.java    |  3 +-
 .../mailbox/ReIndexerManagementTest.java        | 73 ++++++++++++++++++++
 3 files changed, 89 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/bac6c348/server/container/mailbox-jmx/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/mailbox-jmx/pom.xml b/server/container/mailbox-jmx/pom.xml
index e7c4648..8120de6 100644
--- a/server/container/mailbox-jmx/pom.xml
+++ b/server/container/mailbox-jmx/pom.xml
@@ -60,13 +60,23 @@
         </dependency>
 
         <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</artifactId>
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>org.assertj</groupId>
-            <artifactId>assertj-core</artifactId>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter-engine</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.junit.platform</groupId>
+            <artifactId>junit-platform-launcher</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.junit.vintage</groupId>
+            <artifactId>junit-vintage-engine</artifactId>
             <scope>test</scope>
         </dependency>
         <dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/bac6c348/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/ReIndexerManagement.java
----------------------------------------------------------------------
diff --git a/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/ReIndexerManagement.java
b/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/ReIndexerManagement.java
index 760b3d9..075795a 100644
--- a/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/ReIndexerManagement.java
+++ b/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/ReIndexerManagement.java
@@ -64,7 +64,8 @@ public class ReIndexerManagement implements ReIndexerManagementMBean {
                      .addContext(MDCBuilder.PROTOCOL, "CLI")
                      .addContext(MDCBuilder.ACTION, "reIndex")
                      .build()) {
-            reIndexer.reIndex();
+            TaskId taskId = taskManager.submit(reIndexer.reIndex());
+            taskManager.await(taskId);
         } catch (IOException e) {
             throw new RuntimeException(e);
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/bac6c348/server/container/mailbox-jmx/src/test/java/org/apache/james/adapter/mailbox/ReIndexerManagementTest.java
----------------------------------------------------------------------
diff --git a/server/container/mailbox-jmx/src/test/java/org/apache/james/adapter/mailbox/ReIndexerManagementTest.java
b/server/container/mailbox-jmx/src/test/java/org/apache/james/adapter/mailbox/ReIndexerManagementTest.java
new file mode 100644
index 0000000..276b613
--- /dev/null
+++ b/server/container/mailbox-jmx/src/test/java/org/apache/james/adapter/mailbox/ReIndexerManagementTest.java
@@ -0,0 +1,73 @@
+/****************************************************************
+ * 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.adapter.mailbox;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.indexer.ReIndexer;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.task.MemoryTaskManager;
+import org.apache.james.task.Task;
+import org.apache.james.task.TaskManager;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+public class ReIndexerManagementTest {
+    private ReIndexerManagement testee;
+    private TaskManager taskManager;
+    private ReIndexer reIndexer;
+
+    @BeforeEach
+    void setUp() {
+        taskManager = new MemoryTaskManager();
+        reIndexer = mock(ReIndexer.class);
+        testee = new ReIndexerManagement(taskManager, reIndexer);
+    }
+
+    @Test
+    void reIndexMailboxShouldWaitsForExecution() throws MailboxException {
+        Task task = mock(Task.class);
+        String namespace = "namespace";
+        String user = "user";
+        String name = "name";
+        when(reIndexer.reIndex(any(MailboxPath.class))).thenReturn(task);
+
+        assertThat(taskManager.list()).isEmpty();
+        testee.reIndex(namespace, user, name);
+        verify(reIndexer).reIndex(new MailboxPath(namespace, user, name));
+        assertThat(taskManager.list()).hasSize(1);
+    }
+
+    @Test
+    void reIndexShouldWaitsForExecution() throws MailboxException {
+        Task task = mock(Task.class);
+        when(reIndexer.reIndex()).thenReturn(task);
+
+        assertThat(taskManager.list()).isEmpty();
+        testee.reIndex();
+        verify(reIndexer).reIndex();
+        assertThat(taskManager.list()).hasSize(1);
+    }
+}


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