jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1493041 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeProcessor.java oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
Date Fri, 14 Jun 2013 11:49:46 GMT
Author: mduerig
Date: Fri Jun 14 11:49:46 2013
New Revision: 1493041

URL: http://svn.apache.org/r1493041
Log:
OAK-144 Implement Observation
OAK-867: Oak whiteboard
make removeEventListener blocking again

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeProcessor.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeProcessor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeProcessor.java?rev=1493041&r1=1493040&r2=1493041&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeProcessor.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeProcessor.java
Fri Jun 14 11:49:46 2013
@@ -114,9 +114,17 @@ class ChangeProcessor implements Runnabl
     public void stop() {
         stopping = true; // do this outside synchronization
         synchronized (this) {
-            checkState(registration != null, "Change processor not started");
-            changeListener.dispose();
-            registration.unregister();
+            try {
+                while (running) {
+                    wait();
+                }
+                checkState(registration != null, "Change processor not started");
+                changeListener.dispose();
+                registration.unregister();
+            }
+            catch (InterruptedException e) {
+                Thread.currentThread().interrupt();
+            }
         }
     }
 
@@ -145,6 +153,7 @@ class ChangeProcessor implements Runnabl
             log.error("Unable to generate or send events", e);
         } finally {
             running = false;
+            synchronized (this) { notifyAll(); }
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java?rev=1493041&r1=1493040&r2=1493041&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
Fri Jun 14 11:49:46 2013
@@ -2037,8 +2037,8 @@ public class RepositoryTest extends Abst
     public void observationDispose() throws RepositoryException, InterruptedException, ExecutionException,
             TimeoutException {
 
+        final AtomicReference<Boolean> stopGeneratingEvents = new AtomicReference<Boolean>(false);
         final AtomicReference<CountDownLatch> hasEvents = new AtomicReference<CountDownLatch>(new
CountDownLatch(1));
-        final AtomicReference<CountDownLatch> waitForRemove = new AtomicReference<CountDownLatch>(new
CountDownLatch(1));
         final Session observingSession = createAdminSession();
         try {
             final ObservationManager obsMgr = observingSession.getWorkspace().getObservationManager();
@@ -2048,13 +2048,6 @@ public class RepositoryTest extends Abst
                     while (events.hasNext()) {
                         events.next();
                         hasEvents.get().countDown();
-                        try {
-                            // After receiving an event wait until event listener is removed
-                            waitForRemove.get().await();
-                        }
-                        catch (InterruptedException e) {
-                            Thread.currentThread().interrupt();
-                        }
                     }
                 }
             };
@@ -2063,30 +2056,37 @@ public class RepositoryTest extends Abst
                     Event.PROPERTY_ADDED | Event.PROPERTY_REMOVED | Event.PROPERTY_CHANGED
| Event.PERSIST,
                     "/", true, null, null, false);
 
-            // Generate two events
-            Node n = getNode(TEST_PATH);
-            n.setProperty("prop1", "val1");
-            n.setProperty("prop2", "val2");
-            n.getSession().save();
+            // Generate events
+            Executors.newSingleThreadExecutor().submit(new Callable<Void>() {
+                @Override
+                public Void call() throws Exception {
+                    Node n = getNode(TEST_PATH);
+                    for (int c = 0; !stopGeneratingEvents.get() ; c++) {
+                        n.addNode("c" + c);
+                        n.getSession().save();
+                    }
+                    return null;
+                }
+            });
 
-            // Make sure we see the first event
+            // Make sure we see the events
             assertTrue(hasEvents.get().await(2, TimeUnit.SECONDS));
 
-            // Remove event listener before it receives the second event
+            // Remove event listener
             Executors.newSingleThreadExecutor().submit(new Callable<Void>() {
                 @Override
                 public Void call() throws Exception {
                     obsMgr.removeEventListener(listener);
+                    hasEvents.set(new CountDownLatch(1));
                     return null;
                 }
             }).get(2, TimeUnit.SECONDS);
-            hasEvents.set(new CountDownLatch(1));
-            waitForRemove.get().countDown();
 
-            // Make sure we don't see the second event
+            // Make sure we don't see any more events
             assertFalse(hasEvents.get().await(2, TimeUnit.SECONDS));
         }
         finally {
+            stopGeneratingEvents.set(true);
             observingSession.logout();
         }
     }



Mime
View raw message