jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1185731 - in /jackrabbit/sandbox/jackrabbit-mk: jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/ jackrabbit-spi2microkernel/src/test/java/org/ap...
Date Tue, 18 Oct 2011 16:01:17 GMT
Author: mduerig
Date: Tue Oct 18 16:01:17 2011
New Revision: 1185731

URL: http://svn.apache.org/viewvc?rev=1185731&view=rev
Log:
Microkernel based Jackrabbit prototype (WIP)
increase tolerance for ill formatted commit info

Modified:
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/CommitInfo.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SubscriptionImpl.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/CommitInfoTest.java

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java?rev=1185731&r1=1185730&r2=1185731&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
Tue Oct 18 16:01:17 2011
@@ -999,8 +999,12 @@ public final class WorkspaceManager impl
                 return null;
             } catch (RepositoryException e) {
                 log.error("Workspace=" + sessionInfo.getWorkspaceName() + ": Exception while
retrieving event bundles", e);
+            } catch (Exception e) {
+                log.error("Workspace=" + sessionInfo.getWorkspaceName() + ": Exception while
retrieving event bundles", e);
+                throw e;
             }
 
+
             if (!Thread.interrupted() && bundles != null && bundles.length
> 0) {
                 onEventReceived(bundles, internalEventListeners);
             }

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/CommitInfo.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/CommitInfo.java?rev=1185731&r1=1185730&r2=1185731&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/CommitInfo.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/CommitInfo.java
Tue Oct 18 16:01:17 2011
@@ -47,6 +47,14 @@ public class CommitInfo {
         jsonObject = new JSONObject();
     }
 
+    public String getMessage() {
+        return getValue("Message");
+    }
+
+    public CommitInfo setMessage(String message) {
+        return setValue("Message", message);
+    }
+
     public String getUserId() {
         return getValue("UserId");
     }

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SubscriptionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SubscriptionImpl.java?rev=1185731&r1=1185730&r2=1185731&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SubscriptionImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SubscriptionImpl.java
Tue Oct 18 16:01:17 2011
@@ -302,11 +302,18 @@ public class SubscriptionImpl implements
         private EventBundle createEventBundle(JSONObject jsonObject) throws RepositoryException
{
             String revisionId = getString(jsonObject, "id", false);
             String msg = getString(jsonObject, "msg", true);
-            CommitInfo commitInfo = parseCommitMessage(msg);
-            if (commitInfo == null) {
-                // Skip alien commits
-                return null;
+            if (msg == null) {
+                return null;  // Skip alien commits
             }
+            
+            CommitInfo commitInfo;
+            try {
+                commitInfo = CommitInfo.parse(msg);
+            }
+            catch (IllegalArgumentException e) {
+                return null;  // Skip alien commits
+            }
+
             long timeStamp = getLong(jsonObject, "ts");
             String changes = getString(jsonObject, "changes", false);
             log.debug("Creating event bundle from changes in revision " + revisionId + "
at " + timeStamp);
@@ -338,10 +345,6 @@ public class SubscriptionImpl implements
             return new EventBundleImpl(events, isLocal);
         }
 
-        private CommitInfo parseCommitMessage(String msg) {
-            return msg == null ? null : CommitInfo.parse(msg);
-        }
-
         private Collection<Event> getEvents(String changes, EventTemplate eventTemplate)
throws RepositoryException {
             Collection<Event> events = new LinkedList<Event>();
             JsopTokenizer jsopTokenizer = new JsopTokenizer(changes);

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/CommitInfoTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/CommitInfoTest.java?rev=1185731&r1=1185730&r2=1185731&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/CommitInfoTest.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/CommitInfoTest.java
Tue Oct 18 16:01:17 2011
@@ -3,33 +3,80 @@ package org.apache.jackrabbit.spi2microk
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
 
 public class CommitInfoTest {
 
     @Test
     public void testEncode() {
-        CommitInfo msg = new CommitInfo().setUserId("user").setUserData("data").setSessionId("session");
-        assertEquals("user", msg.getUserId());
-        assertEquals("data", msg.getUserData());
-        assertEquals("session", msg.getSessionId());
-        assertEquals(msg, CommitInfo.parse(msg.toJson()));
-
-        msg = new CommitInfo().setUserId("").setUserData("data").setSessionId("session");
-        assertEquals("", msg.getUserId());
-        assertEquals("data", msg.getUserData());
-        assertEquals("session", msg.getSessionId());
-        assertEquals(msg, CommitInfo.parse(msg.toJson()));
-
-        msg = new CommitInfo().setUserId("user").setUserData("").setSessionId("session");
-        assertEquals("user", msg.getUserId());
-        assertEquals("", msg.getUserData());
-        assertEquals("session", msg.getSessionId());
-        assertEquals(msg, CommitInfo.parse(msg.toJson()));
-
-        msg = new CommitInfo().setUserId("").setUserData("").setSessionId("session");
-        assertEquals("", msg.getUserId());
-        assertEquals("", msg.getUserData());
-        assertEquals("session", msg.getSessionId());
-        assertEquals(msg, CommitInfo.parse(msg.toJson()));
+        CommitInfo info = new CommitInfo()
+                .setUserId("user")
+                .setUserData("data")
+                .setSessionId("session")
+                .setMessage("message")
+                .setValue("foo", "bar");
+
+        assertEquals("user", info.getUserId());
+        assertEquals("data", info.getUserData());
+        assertEquals("session", info.getSessionId());
+        assertEquals("message", info.getMessage());
+        assertEquals("bar", info.getValue("foo"));
+        assertNull(info.getValue("any"));
+        assertEquals(info, CommitInfo.parse(info.toJson()));
+
+        info = new CommitInfo()
+                .setUserData("data")
+                .setSessionId("session")
+                .setMessage("message");
+
+        assertNull(info.getUserId());
+        assertEquals("data", info.getUserData());
+        assertEquals("session", info.getSessionId());
+        assertEquals("message", info.getMessage());
+        assertEquals(info, CommitInfo.parse(info.toJson()));
+
+        info = new CommitInfo()
+                .setUserId("user")
+                .setSessionId("session")
+                .setMessage("message");
+
+        assertEquals("user", info.getUserId());
+        assertNull(info.getUserData());
+        assertEquals("session", info.getSessionId());
+        assertEquals("message", info.getMessage());
+        assertEquals(info, CommitInfo.parse(info.toJson()));
+
+        info = new CommitInfo();
+        assertNull(info.getUserId());
+        assertNull(info.getUserData());
+        assertNull(info.getSessionId());
+        assertNull(info.getMessage());
+        assertEquals(info, CommitInfo.parse(info.toJson()));
+    }
+
+    @Test
+    public void testDecode() {
+        CommitInfo info = CommitInfo.parse("{}");
+        assertEquals(null, info.getUserId());
+        assertEquals(null, info.getUserData());
+        assertEquals(null, info.getSessionId());
+
+        info = CommitInfo.parse('{' +
+                "\"UserId\":\"apache\"," +
+                "\"UserData\":\"jackrabbit\"," +
+                "\"SessionId\":\"none\"," +
+                "\"Message\":\"hello world\"," +
+                "\"foo\":\"bar\"}");
+        
+        assertEquals("apache", info.getUserId());
+        assertEquals("jackrabbit", info.getUserData());
+        assertEquals("none", info.getSessionId());
+        assertEquals("hello world", info.getMessage());
+        assertEquals("bar", info.getValue("foo"));
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testDecodeInvalid() {
+        CommitInfo.parse("invalid");
     }
 }



Mime
View raw message