jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1143111 - in /jackrabbit/sandbox/spi2microkernel/src: main/java/org/apache/jackrabbit/spi2microkernel/ test/java/org/apache/jackrabbit/spi2microkernel/
Date Tue, 05 Jul 2011 15:37:04 GMT
Author: thomasm
Date: Tue Jul  5 15:37:04 2011
New Revision: 1143111

URL: http://svn.apache.org/viewvc?rev=1143111&view=rev
Log:
New method waitForCommit to avoid polling delays.

Modified:
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SubscriptionImpl.java
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTest.java
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java

Modified: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SubscriptionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SubscriptionImpl.java?rev=1143111&r1=1143110&r2=1143111&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SubscriptionImpl.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SubscriptionImpl.java
Tue Jul  5 15:37:04 2011
@@ -69,10 +69,9 @@ public class SubscriptionImpl implements
     }
 
     public EventBundle[] getEvents(long timeout) throws RepositoryException, InterruptedException
{
-        Thread.sleep(timeout);
 
         List<EventBundle> eventBundles = new ArrayList<EventBundle>();
-        
+
         synchronized (eventSources) {
             if (!eventSources.isEmpty()) {
                 EventSource current = eventSources.remove();
@@ -82,13 +81,14 @@ public class SubscriptionImpl implements
                     eventBundles.addAll(current.getEventsBundles(next.getStartRevision()));
                     current = next;
                 }
-                
-                String head = microKernel.getHeadRevision();
+
+                String old = current.getStartRevision();
+                String head = microKernel.waitForCommit(old, 1000);
                 eventBundles.addAll(current.getEventsBundles(head));
                 eventSources.add(current.update(head));
             }
         }
-        
+
         return eventBundles.toArray(new EventBundle[eventBundles.size()]);
     }
 
@@ -238,7 +238,7 @@ public class SubscriptionImpl implements
                     case '-': removeNode(jsopTokenizer, eventTemplate, events); break;
                     case '^': setProperty(jsopTokenizer, eventTemplate, events); break;
                     case '>': moveNode(jsopTokenizer, eventTemplate, events); break;
-                    default: // skip 
+                    default: // skip
                 }
             }
 
@@ -287,7 +287,7 @@ public class SubscriptionImpl implements
                 if (tokenType == ',') {
                     jsopTokenizer.read();
                 }
-                
+
                 Name name = Paths.stringToName(jsopTokenizer.getToken());
                 Path path = createPath(parentId.getPath(), name);
 

Modified: jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTest.java?rev=1143111&r1=1143110&r2=1143111&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTest.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTest.java
Tue Jul  5 15:37:04 2011
@@ -19,6 +19,7 @@
 
 package org.apache.jackrabbit.spi2microkernel;
 
+import junit.framework.Assert;
 import org.apache.jackrabbit.mk.MicroKernelFactory;
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.json.JsopTokenizer;
@@ -65,8 +66,13 @@ public class MicrokernelTest {
         String head = mk.getHeadRevision();
 
         String s1 = mk.getNodes("/test", head);
-        String s2 = mk.getNodes("/test/", head);
-        assertEquals(s1, s2);
+        assertEquals("{\"stringProp\":\"stringVal\",\"intProp\":42,\"multiIntProp\":[1,2,3],\"floatProp\":42.2,\":childNodeCount\":0}",
s1);
+        try {
+            String s2 = mk.getNodes("/test/", head);
+            Assert.fail("Success with invalid path: " + s2);
+        } catch (Exception e) {
+            // expected
+        }
     }
 
     @Test
@@ -215,7 +221,7 @@ public class MicrokernelTest {
                 "-\"{}node\"",
                 head, "");
 
-        mk.getJournal(init, head); 
+        mk.getJournal(init, head);
     }
 
     @Test

Modified: jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java?rev=1143111&r1=1143110&r2=1143111&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
Tue Jul  5 15:37:04 2011
@@ -23,6 +23,7 @@ import org.apache.jackrabbit.mk.api.Micr
 import org.apache.jackrabbit.mk.json.JsonBuilder;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
 import org.apache.jackrabbit.spi2microkernel.util.Arrays;
+import org.apache.jackrabbit.spi2microkernel.util.Loop;
 import org.apache.jackrabbit.spi2microkernel.util.Paths;
 import org.junit.After;
 import org.junit.Before;
@@ -878,7 +879,7 @@ public class RepositoryTest {
         mixTest.setName("mix:test");
         mixTest.setMixin(true);
         ntMgr.registerNodeType(mixTest, false);
-        
+
         Node testNode = getNode(testPath);
         NodeType[] mix = testNode.getMixinNodeTypes();
         assertEquals(0, mix.length);
@@ -969,10 +970,10 @@ public class RepositoryTest {
                                         failedEvents.add(event);
                                     }
                                     break;
-                                default: 
+                                default:
                                     failedEvents.add(event);
                             }
-                        }                        
+                        }
                         catch (RepositoryException e) {
                             failedEvents.add(event);
                         }
@@ -981,7 +982,7 @@ public class RepositoryTest {
             },
             Event.NODE_ADDED | Event.NODE_REMOVED | Event.NODE_MOVED | Event.PROPERTY_ADDED
|
             Event.PROPERTY_REMOVED | Event.PROPERTY_CHANGED | Event.PERSIST, "/", true, null,
null, false);
-        
+
         Node n = getNode(testPath);
         n.setProperty("prop0", "val0");
         Node n1 = n.addNode("1");
@@ -994,16 +995,18 @@ public class RepositoryTest {
         n.addNode("3");
         n1.setProperty("prop1", "val1 new");
         n1.getProperty("prop2").remove();
-        n.getNode("2").remove();  
+        n.getNode("2").remove();
         getSession().save();
 
-        Thread.sleep(5000);
-        assertTrue(addNodes.isEmpty());
-        assertTrue(removeNodes.isEmpty());
-        assertTrue(addProperties.isEmpty());
-        assertTrue(removeProperties.isEmpty());
-        assertTrue(setProperties.isEmpty());
-        assertTrue(failedEvents.isEmpty());
+        new Loop() { public void test() {
+            assertTrue(addNodes.isEmpty());
+            assertTrue(removeNodes.isEmpty());
+            assertTrue(addProperties.isEmpty());
+            assertTrue(removeProperties.isEmpty());
+            assertTrue(setProperties.isEmpty());
+            assertTrue(failedEvents.isEmpty());
+        }};
+
     }
 
     //------------------------------------------< private >---



Mime
View raw message