This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git


The following commit(s) were added to refs/heads/master by this push:
     new 84160f7  JAMES-2777 fix too strong expectation about task cancellation
84160f7 is described below

commit 84160f79385bf0d89a53fd319090ec658af0f557
Author: Matthieu Baechler <[email protected]>
AuthorDate: Wed Jun 12 16:13:18 2019 +0200

    JAMES-2777 fix too strong expectation about task cancellation
---
 .../backends/cassandra/migration/MigrationTask.java      |  2 +-
 .../migration/CassandraMigrationServiceTest.java         | 16 ++++++++--------
 .../backends/cassandra/migration/MigrationTest.java      |  8 ++++----
 .../apache/james/vault/DeletedMessageVaultContract.java  | 14 +++++++-------
 .../java/org/apache/james/CleanupTasksPerformer.java     |  3 ++-
 .../webadmin/routes/CassandraMigrationRoutesTest.java    |  4 ++--
 .../task/src/main/java/org/apache/james/task/Task.java   |  2 +-
 .../org/apache/james/task/MemoryTaskManagerTest.java     |  2 ++
 8 files changed, 27 insertions(+), 24 deletions(-)

diff --git 
a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/migration/MigrationTask.java
 
b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/migration/MigrationTask.java
index 7fd3bdd..40c7c62 100644
--- 
a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/migration/MigrationTask.java
+++ 
b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/migration/MigrationTask.java
@@ -48,7 +48,7 @@ public class MigrationTask implements Migration {
     }
 
     @Override
-    public Result run() {
+    public Result run() throws InterruptedException {
         return migration.run();
     }
 
diff --git 
a/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/migration/CassandraMigrationServiceTest.java
 
b/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/migration/CassandraMigrationServiceTest.java
index e0a849e..709d63b 100644
--- 
a/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/migration/CassandraMigrationServiceTest.java
+++ 
b/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/migration/CassandraMigrationServiceTest.java
@@ -97,7 +97,7 @@ public class CassandraMigrationServiceTest {
     }
 
     @Test
-    public void upgradeToVersionShouldNotThrowWhenCurrentVersionIsUpToDate() {
+    public void upgradeToVersionShouldNotThrowWhenCurrentVersionIsUpToDate() 
throws InterruptedException {
         
when(schemaVersionDAO.getCurrentSchemaVersion()).thenReturn(Mono.just(Optional.of(CURRENT_VERSION)));
 
         assertThat(testee.upgradeToVersion(OLDER_VERSION).run())
@@ -105,7 +105,7 @@ public class CassandraMigrationServiceTest {
     }
 
     @Test
-    public void upgradeToVersionShouldUpdateToVersion() {
+    public void upgradeToVersionShouldUpdateToVersion() throws 
InterruptedException {
         
when(schemaVersionDAO.getCurrentSchemaVersion()).thenReturn(Mono.just(Optional.of(OLDER_VERSION)));
 
         testee.upgradeToVersion(CURRENT_VERSION).run();
@@ -114,7 +114,7 @@ public class CassandraMigrationServiceTest {
     }
 
     @Test
-    public void upgradeToLastVersionShouldNotThrowWhenVersionIsUpToDate() {
+    public void upgradeToLastVersionShouldNotThrowWhenVersionIsUpToDate() 
throws InterruptedException {
 
         
when(schemaVersionDAO.getCurrentSchemaVersion()).thenReturn(Mono.just(Optional.of(LATEST_VERSION)));
 
@@ -123,7 +123,7 @@ public class CassandraMigrationServiceTest {
     }
 
     @Test
-    public void upgradeToLastVersionShouldUpdateToLatestVersion() {
+    public void upgradeToLastVersionShouldUpdateToLatestVersion() throws 
InterruptedException {
         
when(schemaVersionDAO.getCurrentSchemaVersion()).thenReturn(Mono.just(Optional.of(OLDER_VERSION)));
 
         testee.upgradeToLastVersion().run();
@@ -132,7 +132,7 @@ public class CassandraMigrationServiceTest {
     }
 
     @Test
-    public void upgradeToVersionShouldThrowOnMissingVersion() {
+    public void upgradeToVersionShouldThrowOnMissingVersion() throws 
InterruptedException {
         Map<SchemaVersion, Migration> allMigrationClazz = 
ImmutableMap.<SchemaVersion, Migration>builder()
             .put(OLDER_VERSION, successfulMigration)
             .put(LATEST_VERSION, successfulMigration)
@@ -146,7 +146,7 @@ public class CassandraMigrationServiceTest {
     }
 
     @Test
-    public void 
upgradeToVersionShouldUpdateIntermediarySuccessfulMigrationsInCaseOfError() {
+    public void 
upgradeToVersionShouldUpdateIntermediarySuccessfulMigrationsInCaseOfError() 
throws InterruptedException {
         try {
             Map<SchemaVersion, Migration> allMigrationClazz = 
ImmutableMap.<SchemaVersion, Migration>builder()
                 .put(OLDER_VERSION, successfulMigration)
@@ -165,7 +165,7 @@ public class CassandraMigrationServiceTest {
     }
 
     @Test
-    public void partialMigrationShouldThrow() {
+    public void partialMigrationShouldThrow() throws InterruptedException {
         Migration migration1 = mock(Migration.class);
         when(migration1.run()).thenReturn(Migration.Result.PARTIAL);
         Migration migration2 = successfulMigration;
@@ -182,7 +182,7 @@ public class CassandraMigrationServiceTest {
     }
 
     @Test
-    public void partialMigrationShouldAbortMigrations() {
+    public void partialMigrationShouldAbortMigrations() throws 
InterruptedException {
         Migration migration1 = mock(Migration.class);
         when(migration1.run()).thenReturn(Migration.Result.PARTIAL);
         Migration migration2 = mock(Migration.class);
diff --git 
a/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/migration/MigrationTest.java
 
b/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/migration/MigrationTest.java
index f1a0092..23a3a3d 100644
--- 
a/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/migration/MigrationTest.java
+++ 
b/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/migration/MigrationTest.java
@@ -27,7 +27,7 @@ import org.junit.Test;
 
 public class MigrationTest {
     @Test
-    public void 
combineShouldNotExecuteSecondMigrationExecutionWhenTheFirstOneIsFailing() {
+    public void 
combineShouldNotExecuteSecondMigrationExecutionWhenTheFirstOneIsFailing() 
throws InterruptedException {
         AtomicBoolean migration2Done = new AtomicBoolean(false);
 
         Migration migration1 = () -> Migration.Result.PARTIAL;
@@ -42,7 +42,7 @@ public class MigrationTest {
     }
 
     @Test
-    public void combineShouldTriggerSecondMigrationWhenTheFirstOneSucceed() {
+    public void combineShouldTriggerSecondMigrationWhenTheFirstOneSucceed() 
throws InterruptedException {
         AtomicBoolean migration2Done = new AtomicBoolean(false);
 
         Migration migration1 = () -> Migration.Result.COMPLETED;
@@ -57,7 +57,7 @@ public class MigrationTest {
     }
 
     @Test
-    public void combineShouldExecuteTheFirstMigrationWhenSecondWillFail() {
+    public void combineShouldExecuteTheFirstMigrationWhenSecondWillFail() 
throws InterruptedException {
         AtomicBoolean migration1Done = new AtomicBoolean(false);
 
         Migration migration1 = () -> {
@@ -73,7 +73,7 @@ public class MigrationTest {
     }
 
     @Test
-    public void combineShouldExecuteTheFirstMigration() {
+    public void combineShouldExecuteTheFirstMigration() throws 
InterruptedException {
         AtomicBoolean migration1Done = new AtomicBoolean(false);
 
         Migration migration1 = () -> {
diff --git 
a/mailbox/plugin/deleted-messages-vault/src/test/java/org/apache/james/vault/DeletedMessageVaultContract.java
 
b/mailbox/plugin/deleted-messages-vault/src/test/java/org/apache/james/vault/DeletedMessageVaultContract.java
index c28f79f..2abaea5 100644
--- 
a/mailbox/plugin/deleted-messages-vault/src/test/java/org/apache/james/vault/DeletedMessageVaultContract.java
+++ 
b/mailbox/plugin/deleted-messages-vault/src/test/java/org/apache/james/vault/DeletedMessageVaultContract.java
@@ -221,14 +221,14 @@ public interface DeletedMessageVaultContract {
     }
 
     @Test
-    default void deleteExpiredMessagesTaskShouldCompleteWhenNoMail() {
+    default void deleteExpiredMessagesTaskShouldCompleteWhenNoMail() throws 
InterruptedException {
         Task.Result result = getVault().deleteExpiredMessagesTask().run();
 
         assertThat(result).isEqualTo(Task.Result.COMPLETED);
     }
 
     @Test
-    default void deleteExpiredMessagesTaskShouldCompleteWhenAllMailsDeleted() {
+    default void deleteExpiredMessagesTaskShouldCompleteWhenAllMailsDeleted() 
throws InterruptedException {
         Mono.from(getVault().append(USER, DELETED_MESSAGE, new 
ByteArrayInputStream(CONTENT))).block();
         Mono.from(getVault().delete(USER, 
DELETED_MESSAGE.getMessageId())).block();
 
@@ -238,7 +238,7 @@ public interface DeletedMessageVaultContract {
     }
 
     @Test
-    default void deleteExpiredMessagesTaskShouldCompleteWhenOnlyRecentMails() {
+    default void deleteExpiredMessagesTaskShouldCompleteWhenOnlyRecentMails() 
throws InterruptedException {
         Mono.from(getVault().append(USER, DELETED_MESSAGE, new 
ByteArrayInputStream(CONTENT))).block();
 
         Task.Result result = getVault().deleteExpiredMessagesTask().run();
@@ -247,7 +247,7 @@ public interface DeletedMessageVaultContract {
     }
 
     @Test
-    default void deleteExpiredMessagesTaskShouldCompleteWhenOnlyOldMails() {
+    default void deleteExpiredMessagesTaskShouldCompleteWhenOnlyOldMails() 
throws InterruptedException {
         Mono.from(getVault().append(USER, OLD_DELETED_MESSAGE, new 
ByteArrayInputStream(CONTENT))).block();
 
         Task.Result result = getVault().deleteExpiredMessagesTask().run();
@@ -256,7 +256,7 @@ public interface DeletedMessageVaultContract {
     }
 
     @Test
-    default void deleteExpiredMessagesTaskShouldDoNothingWhenEmpty() {
+    default void deleteExpiredMessagesTaskShouldDoNothingWhenEmpty() throws 
InterruptedException {
         getVault().deleteExpiredMessagesTask().run();
 
         assertThat(Flux.from(getVault().search(USER, 
ALL)).collectList().block())
@@ -264,7 +264,7 @@ public interface DeletedMessageVaultContract {
     }
 
     @Test
-    default void deleteExpiredMessagesTaskShouldNotDeleteRecentMails() {
+    default void deleteExpiredMessagesTaskShouldNotDeleteRecentMails() throws 
InterruptedException {
         Mono.from(getVault().append(USER, DELETED_MESSAGE, new 
ByteArrayInputStream(CONTENT))).block();
 
         getVault().deleteExpiredMessagesTask().run();
@@ -274,7 +274,7 @@ public interface DeletedMessageVaultContract {
     }
 
     @Test
-    default void deleteExpiredMessagesTaskShouldDeleteOldMails() {
+    default void deleteExpiredMessagesTaskShouldDeleteOldMails() throws 
InterruptedException {
         Mono.from(getVault().append(USER, OLD_DELETED_MESSAGE, new 
ByteArrayInputStream(CONTENT))).block();
 
         getVault().deleteExpiredMessagesTask().run();
diff --git 
a/server/container/guice/guice-common/src/main/java/org/apache/james/CleanupTasksPerformer.java
 
b/server/container/guice/guice-common/src/main/java/org/apache/james/CleanupTasksPerformer.java
index c9e8396..9bcb45b 100644
--- 
a/server/container/guice/guice-common/src/main/java/org/apache/james/CleanupTasksPerformer.java
+++ 
b/server/container/guice/guice-common/src/main/java/org/apache/james/CleanupTasksPerformer.java
@@ -27,6 +27,7 @@ import javax.inject.Inject;
 import org.apache.james.task.Task;
 import org.apache.james.util.Runnables;
 
+import com.github.fge.lambdas.Throwing;
 import reactor.core.publisher.Flux;
 
 public class CleanupTasksPerformer {
@@ -47,7 +48,7 @@ public class CleanupTasksPerformer {
         Runnables
             .runParallel(
                 Flux.fromIterable(cleanupTasks)
-                    .map(cleanupTask -> cleanupTask::run));
+                    .map(cleanupTask -> 
Throwing.runnable(cleanupTask::run).sneakyThrow()));
     }
 
 }
diff --git 
a/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/routes/CassandraMigrationRoutesTest.java
 
b/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/routes/CassandraMigrationRoutesTest.java
index 5e09109..d7490e6 100644
--- 
a/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/routes/CassandraMigrationRoutesTest.java
+++ 
b/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/routes/CassandraMigrationRoutesTest.java
@@ -66,7 +66,7 @@ public class CassandraMigrationRoutesTest {
     private CassandraSchemaVersionDAO schemaVersionDAO;
     private MemoryTaskManager taskManager;
 
-    private void createServer() {
+    private void createServer() throws InterruptedException {
         Migration successfulMigration = mock(Migration.class);
         when(successfulMigration.run()).thenReturn(Migration.Result.COMPLETED);
 
@@ -92,7 +92,7 @@ public class CassandraMigrationRoutesTest {
     }
 
     @Before
-    public void setUp() {
+    public void setUp() throws InterruptedException {
         createServer();
     }
 
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
index 82b7670..0c79ec0 100644
--- a/server/task/src/main/java/org/apache/james/task/Task.java
+++ b/server/task/src/main/java/org/apache/james/task/Task.java
@@ -74,7 +74,7 @@ public interface Task {
      *
      * @return Return true if fully migrated. Returns false otherwise.
      */
-    Result run();
+    Result run() throws InterruptedException;
 
 
     default String type() {
diff --git 
a/server/task/src/test/java/org/apache/james/task/MemoryTaskManagerTest.java 
b/server/task/src/test/java/org/apache/james/task/MemoryTaskManagerTest.java
index c2166cd..89608c2 100644
--- a/server/task/src/test/java/org/apache/james/task/MemoryTaskManagerTest.java
+++ b/server/task/src/test/java/org/apache/james/task/MemoryTaskManagerTest.java
@@ -92,6 +92,8 @@ class MemoryTaskManagerTest {
         TaskId id = memoryTaskManager.submit(() -> {
             waitForTaskToBeLaunched.countDown();
             waitForResult();
+            //We sleep to handover the CPU to the scheduler
+            Thread.sleep(1);
             count.incrementAndGet();
             return Task.Result.COMPLETED;
         });


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to