james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [02/10] james-project git commit: JAMES-2541 Fix MailRepositoryContract concurrent testing
Date Thu, 04 Oct 2018 08:13:46 GMT
JAMES-2541 Fix MailRepositoryContract concurrent testing


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

Branch: refs/heads/master
Commit: 264c29ffde234c37dd791775d3c9ee37f253a878
Parents: f0b3f6e
Author: Benoit Tellier <btellier@linagora.com>
Authored: Tue Sep 11 11:19:12 2018 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Thu Oct 4 15:12:07 2018 +0700

----------------------------------------------------------------------
 .../james/mailrepository/MailRepositoryContract.java      | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/264c29ff/server/mailrepository/mailrepository-api/src/test/java/org/apache/james/mailrepository/MailRepositoryContract.java
----------------------------------------------------------------------
diff --git a/server/mailrepository/mailrepository-api/src/test/java/org/apache/james/mailrepository/MailRepositoryContract.java
b/server/mailrepository/mailrepository-api/src/test/java/org/apache/james/mailrepository/MailRepositoryContract.java
index 48f1a48..20b0884 100644
--- a/server/mailrepository/mailrepository-api/src/test/java/org/apache/james/mailrepository/MailRepositoryContract.java
+++ b/server/mailrepository/mailrepository-api/src/test/java/org/apache/james/mailrepository/MailRepositoryContract.java
@@ -423,13 +423,13 @@ public interface MailRepositoryContract {
         MailRepository testee = retrieveRepository();
         int nbKeys = 20;
         ConcurrentHashMap.KeySetView<MailKey, Boolean> expectedResult = ConcurrentHashMap.newKeySet();
-        List<Object> locks = IntStream.range(0, 10)
+        List<Object> locks = IntStream.range(0, nbKeys)
             .boxed()
             .collect(Guavate.toImmutableList());
 
         Random random = new Random();
         ThrowingRunnable add = () -> {
-            int keyIndex = computeKeyIndex(nbKeys, random.nextInt());
+            int keyIndex = computeKeyIndex(nbKeys, Math.abs(random.nextInt()));
             MailKey key =  computeKey(keyIndex);
             synchronized (locks.get(keyIndex)) {
                 testee.store(createMail(key));
@@ -438,7 +438,7 @@ public interface MailRepositoryContract {
         };
 
         ThrowingRunnable remove = () -> {
-            int keyIndex = computeKeyIndex(nbKeys, random.nextInt());
+            int keyIndex = computeKeyIndex(nbKeys, Math.abs(random.nextInt()));
             MailKey key =  computeKey(keyIndex);
             synchronized (locks.get(keyIndex)) {
                 testee.remove(key);
@@ -455,9 +455,7 @@ public interface MailRepositoryContract {
             .operation((a, b) -> distribution.sample().run())
             .threadCount(10)
             .operationCount(10)
-            .build()
-            .run()
-            .awaitTermination(1, TimeUnit.MINUTES);
+            .runSuccessfullyWithin(1, TimeUnit.MINUTES);
 
         assertThat(testee.list()).containsOnlyElementsOf(expectedResult);
     }


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