jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1143269 - in /jackrabbit/sandbox/microkernel/src: main/java/org/apache/jackrabbit/mk/ main/java/org/apache/jackrabbit/mk/api/ main/java/org/apache/jackrabbit/mk/mem/ main/java/org/apache/jackrabbit/mk/util/ test/java/org/apache/jackrabbit/...
Date Wed, 06 Jul 2011 07:00:39 GMT
Author: thomasm
Date: Wed Jul  6 07:00:39 2011
New Revision: 1143269

URL: http://svn.apache.org/viewvc?rev=1143269&view=rev
Log:
Allow waitForCommit to be interrupted.

Added:
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/CommitGateTest.java
Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/CommitGate.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java?rev=1143269&r1=1143268&r2=1143269&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
Wed Jul  6 07:00:39 2011
@@ -115,7 +115,7 @@ public class MicroKernelImpl implements 
         return buff.endArray().toString();
     }
 
-    public String waitForCommit(String oldHeadRevision, long maxWaitMillis) throws MicroKernelException
{
+    public String waitForCommit(String oldHeadRevision, long maxWaitMillis) throws MicroKernelException,
InterruptedException {
         return gate.waitForCommit(oldHeadRevision, maxWaitMillis);
     }
 

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java?rev=1143269&r1=1143268&r2=1143269&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java
Wed Jul  6 07:00:39 2011
@@ -133,9 +133,10 @@ public interface MicroKernel {
      *            method should not wait).
      * @return the current head revision
      * @throws MicroKernelException if an error occurs
+     * @throws InterruptedException if the thread was interrupted
      */
 
-    String waitForCommit(String oldHeadRevision, long maxWaitMillis) throws MicroKernelException;
+    String waitForCommit(String oldHeadRevision, long maxWaitMillis) throws MicroKernelException,
InterruptedException;
 
     /**
      * Returns a revision journal, starting with <code>fromRevisionId</code>

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java?rev=1143269&r1=1143268&r2=1143269&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
Wed Jul  6 07:00:39 2011
@@ -175,7 +175,7 @@ public class MemoryKernelImpl implements
         return buff.endArray().toString();
     }
 
-    public String waitForCommit(String oldHeadRevision, long maxWaitMillis) {
+    public String waitForCommit(String oldHeadRevision, long maxWaitMillis) throws InterruptedException
{
         return gate.waitForCommit(oldHeadRevision, maxWaitMillis);
     }
 

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/CommitGate.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/CommitGate.java?rev=1143269&r1=1143268&r2=1143269&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/CommitGate.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/CommitGate.java
Wed Jul  6 07:00:39 2011
@@ -35,8 +35,9 @@ public class CommitGate {
      * @param lastHead the last head
      * @param millis the maximum number of milliseconds to wait (0 means don't wait)
      * @return the new head (or old head, if no new commit occurred)
+     * @throws InterruptedException if the thread was interrupted
      */
-    public String waitForCommit(String lastHead, long millis) {
+    public String waitForCommit(String lastHead, long millis) throws InterruptedException
{
         if (millis == 0 || (currentHead != null && !currentHead.equals(lastHead)))
{
             return currentHead;
         }
@@ -49,11 +50,7 @@ public class CommitGate {
                 old.countDown();
             }
         }
-        try {
-            latch.await(millis, TimeUnit.MILLISECONDS);
-        } catch (InterruptedException e) {
-            // ignore
-        }
+        latch.await(millis, TimeUnit.MILLISECONDS);
         return currentHead;
     }
 

Added: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/CommitGateTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/CommitGateTest.java?rev=1143269&view=auto
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/CommitGateTest.java
(added)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/CommitGateTest.java
Wed Jul  6 07:00:39 2011
@@ -0,0 +1,75 @@
+/*
+ * 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.jackrabbit.mk.util;
+
+import java.util.concurrent.atomic.AtomicLong;
+import junit.framework.TestCase;
+
+/**
+ * Test the commit gate.
+ */
+public class CommitGateTest extends TestCase {
+
+    public void test() throws InterruptedException {
+        final CommitGate gate = new CommitGate();
+        gate.commit("start");
+        final AtomicLong tick = new AtomicLong();
+        final AtomicLong spurious = new AtomicLong();
+        final int waitMillis = 10;
+        int threadCount = 10;
+        Thread[] threads = new Thread[threadCount];
+        for (int i = 0; i < 10; i++) {
+            Thread t = threads[i] = new Thread() {
+                public void run() {
+                    String head = null;
+                    while (true) {
+                        String nh;
+                        try {
+                            nh = gate.waitForCommit(head, waitMillis);
+                            if (nh.equals(head)) {
+                                spurious.incrementAndGet();
+                            } else {
+                                tick.incrementAndGet();
+                            }
+                            head = nh;
+                            if (head.equals("end")) {
+                                break;
+                            }
+                        } catch (InterruptedException e) {
+                            //
+                        }
+                    }
+                }
+            };
+            t.start();
+        }
+        Thread.sleep(waitMillis * 10);
+        assertTrue(threadCount < spurious.get());
+        assertEquals(10, tick.get());
+        int commitCount = 100;
+        for (int i = 0; i < commitCount; i++) {
+            gate.commit(Integer.toString(i));
+            Thread.sleep(1);
+        }
+        gate.commit("end");
+        for (Thread j : threads) {
+            j.join();
+        }
+        assertTrue(tick.get() >= threadCount * commitCount);
+    }
+
+}



Mime
View raw message