geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jlmonte...@apache.org
Subject [geronimo-jcache-simple] 01/02: Use a latch instead of a sleep. More deterministic
Date Tue, 05 Jun 2018 09:01:24 GMT
This is an automated email from the ASF dual-hosted git repository.

jlmonteiro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/geronimo-jcache-simple.git

commit 34bf0418aec7d95198e18089e7628d21fb49e587
Author: Jean-Louis Monteiro <jeanouii@gmail.com>
AuthorDate: Tue Jun 5 11:00:16 2018 +0200

    Use a latch instead of a sleep. More deterministic
---
 .../geronimo/jcache/simple/tck/ExpiryListenerTest.java  | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/test/java/org/apache/geronimo/jcache/simple/tck/ExpiryListenerTest.java b/src/test/java/org/apache/geronimo/jcache/simple/tck/ExpiryListenerTest.java
index 2045437..ded8f40 100644
--- a/src/test/java/org/apache/geronimo/jcache/simple/tck/ExpiryListenerTest.java
+++ b/src/test/java/org/apache/geronimo/jcache/simple/tck/ExpiryListenerTest.java
@@ -26,6 +26,7 @@ import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Properties;
+import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
 import javax.cache.Cache;
@@ -54,32 +55,42 @@ public class ExpiryListenerTest {
                 new Properties() {{
                     setProperty("evictionPause", "2");
                 }});
-        final CacheEntryExpiredListenerImpl listener = new CacheEntryExpiredListenerImpl();
+
+        final CountDownLatch latch = new CountDownLatch(1);
+        final CacheEntryExpiredListenerImpl listener = new CacheEntryExpiredListenerImpl(latch);
         cacheManager.createCache("default", new MutableConfiguration<String, String>()
                 .setExpiryPolicyFactory(new FactoryBuilder.SingletonFactory<ExpiryPolicy>(
                         new CreatedExpiryPolicy(new Duration(TimeUnit.MILLISECONDS, 2))))
-                .addCacheEntryListenerConfiguration(new MutableCacheEntryListenerConfiguration<String,
String>(
+                .addCacheEntryListenerConfiguration(new MutableCacheEntryListenerConfiguration<>(
                         FactoryBuilder.factoryOf(listener),
                         null, false, false
                 )));
         final Cache<String, String> cache = cacheManager.getCache("default");
         assertFalse(cache.containsKey("foo"));
         cache.put("foo", "bar");
-        Thread.sleep(20);
+        latch.await(1, TimeUnit.MINUTES);
         assertEquals(1, listener.events.size());
         cachingProvider.close();
     }
 
     private static class CacheEntryExpiredListenerImpl implements CacheEntryExpiredListener<String,
String>, Serializable {
+
         private final Collection<CacheEntryEvent<? extends String, ? extends String>>
events =
                 new ArrayList<CacheEntryEvent<? extends String, ? extends String>>();
 
+        private CountDownLatch latch;
+
+        public CacheEntryExpiredListenerImpl(final CountDownLatch latch) {
+            this.latch = latch;
+        }
+
         @Override
         public void onExpired(final Iterable<CacheEntryEvent<? extends String, ? extends
String>> cacheEntryEvents)
                 throws CacheEntryListenerException {
             for (final CacheEntryEvent<? extends String, ? extends String> cacheEntryEvent
: cacheEntryEvents) {
                 events.add(cacheEntryEvent);
             }
+            latch.countDown();
         }
     }
 }

-- 
To stop receiving notification emails like this one, please contact
jlmonteiro@apache.org.

Mime
View raw message