WICKET-5316: testcase showing the problem with lock releases

Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/9ed0fbdb
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/9ed0fbdb
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/9ed0fbdb

Branch: refs/heads/code-coverage-jacoco
Commit: 9ed0fbdb5a561c8ab4e35013a6b6beaddc72bffe
Parents: 2f97834
Author: Emond Papegaaij <[email protected]>
Authored: Wed Aug 14 15:01:43 2013 +0200
Committer: Emond Papegaaij <[email protected]>
Committed: Wed Aug 14 15:01:43 2013 +0200

----------------------------------------------------------------------
 .../wicket/page/PageAccessSynchronizerTest.java | 58 ++++++++++++++++++++
 1 file changed, 58 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/9ed0fbdb/wicket-core/src/test/java/org/apache/wicket/page/PageAccessSynchronizerTest.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/test/java/org/apache/wicket/page/PageAccessSynchronizerTest.java
 
b/wicket-core/src/test/java/org/apache/wicket/page/PageAccessSynchronizerTest.java
index c3770f4..b5cb403 100644
--- 
a/wicket-core/src/test/java/org/apache/wicket/page/PageAccessSynchronizerTest.java
+++ 
b/wicket-core/src/test/java/org/apache/wicket/page/PageAccessSynchronizerTest.java
@@ -17,7 +17,9 @@
 package org.apache.wicket.page;
 
 import java.util.Random;
+import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.wicket.MockPage;
@@ -327,4 +329,60 @@ public class PageAccessSynchronizerTest extends Assert
                PageLock pageLock2 = locks.get(Integer.valueOf(pageId));
                assertNotNull(pageLock2);
        }
+
+       /**
+        * https://issues.apache.org/jira/browse/WICKET-5316
+        * 
+        * @throws Exception
+        */
+       @Test
+       public void failToReleaseUnderLoad() throws Exception
+       {
+               final ConcurrentLinkedQueue<Exception> errors = new 
ConcurrentLinkedQueue<Exception>();
+               final long endTime = System.currentTimeMillis() + 
Duration.seconds(20).getMilliseconds();
+               final PageAccessSynchronizer sync = new 
PageAccessSynchronizer(Duration.seconds(10));
+               final CountDownLatch latch = new CountDownLatch(100);
+               for (int count = 0; count < 100; count++)
+               {
+                       new Thread()
+                       {
+                               @Override
+                               public void run()
+                               {
+                                       try
+                                       {
+                                               while 
(System.currentTimeMillis() < endTime)
+                                               {
+                                                       try
+                                                       {
+                                                               
logger.debug(Thread.currentThread().getName() + " locking");
+                                                               
sync.lockPage(0);
+                                                               Thread.sleep(1);
+                                                               
logger.debug(Thread.currentThread().getName() + " locked");
+                                                               
sync.unlockAllPages();
+                                                               
logger.debug(Thread.currentThread().getName() + " unlocked");
+                                                               Thread.sleep(5);
+                                                       }
+                                                       catch 
(InterruptedException e)
+                                                       {
+                                                               throw new 
RuntimeException(e);
+                                                       }
+                                               }
+                                       }
+                                       catch (Exception e)
+                                       {
+                                               logger.error(e.getMessage(), e);
+                                               errors.add(e);
+                                       }
+                                       finally
+                                       {
+                                               latch.countDown();
+                                       }
+                               }
+                       }.start();
+               }
+               latch.await();
+               if (!errors.isEmpty())
+                       throw errors.remove();
+       }
 }

Reply via email to