jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r935321 [2/2] - in /jackrabbit/sandbox/jackrabbit-j3/src: main/java/org/apache/jackrabbit/j3/ main/java/org/apache/jackrabbit/j3/mc/ main/java/org/apache/jackrabbit/j3/mc/jdbc/ main/java/org/apache/jackrabbit/j3/mc/mem/ main/java/org/apache...
Date Sun, 18 Apr 2010 09:52:28 GMT
Modified: jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/observation/EventImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/observation/EventImpl.java?rev=935321&r1=935320&r2=935321&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/observation/EventImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/observation/EventImpl.java
Sun Apr 18 09:52:27 2010
@@ -16,11 +16,19 @@
  */
 package org.apache.jackrabbit.j3.observation;
 
+import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
 import java.util.Map;
 import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.NodeType;
 import javax.jcr.observation.Event;
+import org.apache.jackrabbit.j3.NodeImpl;
 import org.apache.jackrabbit.j3.SessionImpl;
+import org.apache.jackrabbit.j3.ChangeSet;
+import org.apache.jackrabbit.j3.mc.Bundle;
+import org.apache.jackrabbit.j3.util.ExceptionFactory;
 import org.apache.jackrabbit.j3.util.Log;
 import org.apache.jackrabbit.j3.util.LogObject;
 
@@ -29,31 +37,44 @@ import org.apache.jackrabbit.j3.util.Log
  */
 public abstract class EventImpl implements Event, LogObject {
 
-    protected final EventList eventList;
+    public static final int TOKEN_USER_ID = 1;
+    public static final int TOKEN_USER_DATA = 2;
+    static final int TOKEN_ADD_LOCK = 3;
+    static final int TOKEN_ADD_MIXIN = 4;
+    static final int TOKEN_ADD_NODE = 5;
+    static final int TOKEN_ADD_PROPERTY = 6;
+    static final int TOKEN_MODIFY_PROPERTY = 7;
+    static final int TOKEN_REMOVE_NODE = 8;
 
-    EventImpl(SessionImpl session) {
-        this.eventList = session.getEventList();
+    protected final ChangeSet changes;
+
+    EventImpl(ChangeSet changes) {
+        this.changes = changes;
     }
 
-    abstract void apply() throws RepositoryException;
+    public abstract void apply() throws RepositoryException;
+
+    public abstract NodeImpl getParentNode();
+
+    public abstract void writeTo(Bundle bundle);
 
     protected Log getLog() {
-        return eventList.getLog();
+        return changes.getLog();
     }
 
     public String getUserData() {
         getLog().code(this, "getUserData");
-        return eventList.getUserData();
+        return changes.getUserData();
     }
 
     public String getUserID() {
         getLog().code(this, "getUserID");
-        return eventList.getUserID();
+        return changes.getUserID();
     }
 
     public long getDate() {
         getLog().code(this, "getDate");
-        return eventList.getPersistedDate();
+        return changes.getPersistedDate();
     }
 
     public Map<String, String> getInfo() {
@@ -75,8 +96,57 @@ public abstract class EventImpl implemen
 
     public void applyAndAdd() throws RepositoryException {
         apply();
-        eventList.add(this);
+        changes.addEvent(this);
     }
 
-}
+    SessionImpl getSession() {
+        return changes.getSession();
+    }
 
+    public static EventImpl readFrom(ChangeSet changes, Bundle bundle) throws RepositoryException
{
+        while (true) {
+            int type = bundle.readVarInt();
+            switch (type) {
+            case TOKEN_USER_ID:
+                changes.setUserId(bundle.readVal().getString());
+                break;
+            case TOKEN_USER_DATA:
+                changes.setUserData(bundle.readVal().getString());
+                break;
+            case TOKEN_ADD_LOCK:
+                return EventAddLock.readFrom(changes, bundle);
+            case TOKEN_ADD_MIXIN:
+                return EventAddMixin.readFrom(changes, bundle);
+            case TOKEN_ADD_NODE:
+                return EventAddNode.readFrom(changes, bundle);
+            case TOKEN_ADD_PROPERTY:
+                return EventAddProperty.readFrom(changes, bundle);
+            case TOKEN_MODIFY_PROPERTY:
+                return EventModifyProperty.readFrom(changes, bundle);
+            case TOKEN_REMOVE_NODE:
+                return EventRemoveNode.readFrom(changes, bundle);
+            default:
+                throw ExceptionFactory.repository("Unsupported event type {0}", type);
+            }
+        }
+    }
+
+    public static Iterator<EventImpl> readFrom(ChangeSet changes, Bundle[] bundles)
{
+        ArrayList<EventImpl> events = new ArrayList<EventImpl>();
+        for (Bundle b : bundles) {
+            while (b.getPos() < b.length()) {
+                try {
+                    events.add(EventImpl.readFrom(changes, b));
+                } catch (RepositoryException e) {
+                    ExceptionFactory.runtime(e);
+                }
+            }
+        }
+        return events.iterator();
+    }
+
+    public boolean matchesNodeTypeSet(HashSet<NodeType> nodeTypeSet) throws RepositoryException
{
+        return getParentNode().matchesNodeTypeSet(nodeTypeSet);
+    }
+
+}

Added: jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/observation/EventJournalImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/observation/EventJournalImpl.java?rev=935321&view=auto
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/observation/EventJournalImpl.java
(added)
+++ jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/observation/EventJournalImpl.java
Sun Apr 18 09:52:27 2010
@@ -0,0 +1,124 @@
+/*
+ * 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.j3.observation;
+
+import java.util.Iterator;
+import javax.jcr.observation.EventJournal;
+import org.apache.jackrabbit.j3.SessionImpl;
+import org.apache.jackrabbit.j3.ChangeSet;
+import org.apache.jackrabbit.j3.mc.Bundle;
+import org.apache.jackrabbit.j3.mc.StorageSession;
+import org.apache.jackrabbit.j3.util.Constants;
+import org.apache.jackrabbit.j3.util.ExceptionFactory;
+import org.apache.jackrabbit.j3.util.Log;
+import org.apache.jackrabbit.j3.util.LogObject;
+
+/**
+ * The implementation of the corresponding JCR interface.
+ */
+public class EventJournalImpl implements EventJournal, LogObject {
+
+    private final SessionImpl session;
+    private final EventFilter filter;
+    private final Log log;
+    private long nextDate;
+    private long pos;
+    private EventImpl next;
+    private Iterator<EventImpl> events;
+
+    protected EventJournalImpl(SessionImpl session, EventFilter filter, Log log) {
+        this.session = session;
+        this.filter = filter;
+        this.log = log;
+    }
+
+    private void fetch() {
+        while (true) {
+            if (events == null) {
+                StorageSession storageSession = session.getStorageSession();
+                Bundle[] bundles = storageSession.getEvents(nextDate, Constants.JOURNAL_LOAD_SIZE);
+                nextDate = -1;
+                if (bundles == null) {
+                    next = null;
+                    break;
+                }
+                ChangeSet changes = new ChangeSet(session, null, 0);
+                events = EventImpl.readFrom(changes, bundles);
+            }
+            if (!events.hasNext()) {
+                events = null;
+            } else {
+                next = events.next();
+                if (filter == null || filter.matches(next)) {
+                    break;
+                }
+            }
+        }
+    }
+
+    public void skipTo(long date) {
+        log.code(this, "skipTo", date);
+        nextDate = date;
+        pos = 0;
+        events = null;
+    }
+
+    public EventImpl nextEvent() {
+        log.code(this, "nextEventListener");
+        pos++;
+        fetch();
+        EventImpl result = next;
+        if (result == null) {
+            throw ExceptionFactory.noSuchElement();
+        }
+        fetch();
+        return result;
+    }
+
+    public long getPosition() {
+        log.code(this, "getPosition");
+        return pos;
+    }
+
+    public long getSize() {
+        log.code(this, "getSize");
+        return -1;
+    }
+
+    public void skip(long skipNum) {
+        log.code(this, "skip", skipNum);
+        for (int i = 0; i < skipNum; i++) {
+            nextEvent();
+        }
+    }
+
+    public boolean hasNext() {
+        log.code(this, "hasNext");
+        fetch();
+        return next != null;
+    }
+
+    public Object next() {
+        log.code(this, "hasNext");
+        return nextEvent();
+    }
+
+    public void remove() {
+        log.code(this, "hasNext");
+    }
+
+}

Modified: jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/observation/EventModifyProperty.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/observation/EventModifyProperty.java?rev=935321&r1=935320&r2=935321&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/observation/EventModifyProperty.java
(original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/observation/EventModifyProperty.java
Sun Apr 18 09:52:27 2010
@@ -20,7 +20,8 @@ import javax.jcr.RepositoryException;
 import javax.jcr.lock.LockException;
 import javax.jcr.observation.Event;
 import org.apache.jackrabbit.j3.NodeImpl;
-import org.apache.jackrabbit.j3.SessionImpl;
+import org.apache.jackrabbit.j3.ChangeSet;
+import org.apache.jackrabbit.j3.mc.Bundle;
 import org.apache.jackrabbit.j3.mc.Val;
 
 /**
@@ -32,17 +33,13 @@ public class EventModifyProperty extends
     private final Val value;
     private String path;
 
-    public EventModifyProperty(SessionImpl session, NodeImpl node, Val propertyName, Val
value) {
-        super(session);
+    public EventModifyProperty(ChangeSet changes, NodeImpl node, Val propertyName, Val value)
{
+        super(changes);
         this.node = node;
         this.propertyName = propertyName;
         this.value = value;
     }
 
-    public void apply() throws LockException {
-        node.doSetProperty(propertyName, value);
-    }
-
     public int getType() {
         return Event.PROPERTY_CHANGED;
     }
@@ -54,4 +51,30 @@ public class EventModifyProperty extends
         return path;
     }
 
+    @Override
+    public void apply() throws LockException {
+        node.doSetProperty(propertyName, value);
+    }
+
+    @Override
+    public void writeTo(Bundle bundle) {
+        bundle.writeVarInt(TOKEN_MODIFY_PROPERTY);
+        bundle.writeVal(node.getNodeState().getId());
+        bundle.writeVal(propertyName);
+        bundle.writeVal(value);
+    }
+
+    public static EventModifyProperty readFrom(ChangeSet changes, Bundle bundle) throws RepositoryException
{
+        Val id = bundle.readVal();
+        NodeImpl node = changes.getSession().getNode(null, id);
+        Val propertyName = bundle.readVal();
+        Val value = bundle.readVal();
+        return new EventModifyProperty(changes, node, propertyName, value);
+    }
+
+    @Override
+    public NodeImpl getParentNode() {
+        return node;
+    }
+
 }
\ No newline at end of file

Modified: jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/observation/EventRemoveNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/observation/EventRemoveNode.java?rev=935321&r1=935320&r2=935321&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/observation/EventRemoveNode.java
(original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/observation/EventRemoveNode.java
Sun Apr 18 09:52:27 2010
@@ -16,10 +16,13 @@
  */
 package org.apache.jackrabbit.j3.observation;
 
+import javax.jcr.RepositoryException;
 import javax.jcr.lock.LockException;
 import javax.jcr.observation.Event;
 import org.apache.jackrabbit.j3.NodeImpl;
-import org.apache.jackrabbit.j3.SessionImpl;
+import org.apache.jackrabbit.j3.ChangeSet;
+import org.apache.jackrabbit.j3.mc.Bundle;
+import org.apache.jackrabbit.j3.mc.Val;
 
 /**
  * Remove a node.
@@ -27,13 +30,13 @@ import org.apache.jackrabbit.j3.SessionI
 public class EventRemoveNode extends EventImpl {
     private final NodeImpl node;
 
-    public EventRemoveNode(SessionImpl session, NodeImpl node) {
-        super(session);
+    public EventRemoveNode(ChangeSet changes, NodeImpl node) {
+        super(changes);
         this.node = node;
     }
 
     public void apply() throws LockException {
-        // TODO remove all child nodes as well (maybe as a background process)
+        // TODO remove all child nodes as well (maybe as a background thread)
         node.doRemove();
     }
 
@@ -41,4 +44,25 @@ public class EventRemoveNode extends Eve
         return Event.NODE_REMOVED;
     }
 
+    public int getEventToken() {
+        return TOKEN_REMOVE_NODE;
+    }
+
+    @Override
+    public void writeTo(Bundle bundle) {
+        bundle.writeVarInt(TOKEN_REMOVE_NODE);
+        bundle.writeVal(node.getNodeState().getId());
+    }
+
+    public static EventRemoveNode readFrom(ChangeSet changes, Bundle bundle) throws RepositoryException
{
+        Val id = bundle.readVal();
+        NodeImpl node = changes.getSession().getNode(null, id);
+        return new EventRemoveNode(changes, node);
+    }
+
+    @Override
+    public NodeImpl getParentNode() {
+        return node;
+    }
+
 }

Modified: jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/observation/ObservationManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/observation/ObservationManagerImpl.java?rev=935321&r1=935320&r2=935321&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/observation/ObservationManagerImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/observation/ObservationManagerImpl.java
Sun Apr 18 09:52:27 2010
@@ -25,6 +25,7 @@ import javax.jcr.observation.EventListen
 import javax.jcr.observation.ObservationManager;
 import org.apache.jackrabbit.j3.RangeIteratorImpl;
 import org.apache.jackrabbit.j3.SessionImpl;
+import org.apache.jackrabbit.j3.ChangeSet;
 import org.apache.jackrabbit.j3.util.Log;
 import org.apache.jackrabbit.j3.util.LogObject;
 
@@ -50,7 +51,8 @@ public class ObservationManagerImpl impl
     public void addEventListener(EventListener listener, int eventTypes, String absPath,
boolean isDeep, String[] uuid,
             String[] nodeTypeName, boolean noLocal) throws RepositoryException {
         log.code(this, "addEventListener", listener, eventTypes, absPath, isDeep, uuid, nodeTypeName,
noLocal);
-        EventConsumer consumer = new EventConsumer(session, listener, eventTypes, absPath,
isDeep, uuid, nodeTypeName, noLocal);
+        EventFilter filter = new EventFilter(session, eventTypes, absPath, isDeep, uuid,
nodeTypeName, noLocal);
+        EventConsumer consumer = new EventConsumer(session, listener, filter);
         eventConsumers.add(consumer);
     }
 
@@ -73,15 +75,20 @@ public class ObservationManagerImpl impl
 
     public EventJournal getEventJournal() throws RepositoryException {
         log.code(this, "getEventJournal");
-        // TODO Auto-generated method stub
-        return null;
+        return new EventJournalImpl(session, null, log);
     }
 
     public EventJournal getEventJournal(int eventTypes, String absPath, boolean isDeep, String[]
uuid,
             String[] nodeTypeName) throws RepositoryException {
         log.code(this, "getEventJournal", eventTypes, absPath, isDeep, uuid, nodeTypeName);
-        // TODO Auto-generated method stub
-        return null;
+        EventFilter filter = new EventFilter(session, eventTypes, absPath, isDeep, uuid,
nodeTypeName, false);
+        return new EventJournalImpl(session, filter, log);
+    }
+
+    public void dispatchEvents(ChangeSet changes) {
+        for (EventConsumer consumer : eventConsumers) {
+            consumer.dispatch(changes);
+        }
     }
 
     /**
@@ -95,7 +102,7 @@ public class ObservationManagerImpl impl
 
         public EventListener nextEventListener() {
             log.code(this, "nextEventListener");
-            return goNext().getListener();
+            return getNext().getListener();
         }
 
         public EventListener next() {
@@ -104,10 +111,4 @@ public class ObservationManagerImpl impl
 
     }
 
-    public void dispatchEvents(EventList events) {
-        for (EventConsumer consumer : eventConsumers) {
-            consumer.dispatch(events);
-        }
-    }
-
 }

Modified: jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/query/RowIteratorImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/query/RowIteratorImpl.java?rev=935321&r1=935320&r2=935321&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/query/RowIteratorImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/query/RowIteratorImpl.java
Sun Apr 18 09:52:27 2010
@@ -33,7 +33,7 @@ public class RowIteratorImpl extends Ran
 
     public Row nextRow() {
         log.code(this, "nextRow");
-        return goNext();
+        return getNext();
     }
 
 }

Modified: jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/security/AccessControlManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/security/AccessControlManagerImpl.java?rev=935321&r1=935320&r2=935321&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/security/AccessControlManagerImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/security/AccessControlManagerImpl.java
Sun Apr 18 09:52:27 2010
@@ -120,7 +120,7 @@ public class AccessControlManagerImpl im
 
         public AccessControlPolicy nextAccessControlPolicy() {
             log.code(this, "nextAccessControlPolicy");
-            return goNext();
+            return getNext();
         }
 
     }

Modified: jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/util/Constants.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/util/Constants.java?rev=935321&r1=935320&r2=935321&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/util/Constants.java
(original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/util/Constants.java
Sun Apr 18 09:52:27 2010
@@ -28,13 +28,20 @@ public class Constants {
 
     public static final String DEFAULT_URL = "mem:";
 
-    public static final int MEM_CACHE_PER_REPOSITORY = 16 * 1024 * 1024;
+    public static final int MAX_STORE_RETRY = 3;
 
+    public static final int MEM_CACHE_PER_REPOSITORY = 16 * 1024 * 1024;
+    public static final int MEM_CACHE_PER_SESSION = 1024 * 1024;
     public static final int MEM_MAP_ENTRY = 32;
+    public static final int MEM_EVENT = 64;
     public static final int MEM_NODE_DATA = 48;
     public static final int MEM_VAL_LONG =  32;
     public static final int MEM_VAL_BINARY = 32;
     public static final int MEM_VAL_STRING = 64;
     public static final int MEM_VAL_OBJ = 16;
+    public static final int SIZE_EVENT_BUNDLE = 20 * 1024;
+
+    public static final int BUNDLE_MIN_COMPRESS = 3;
+    public static final int JOURNAL_LOAD_SIZE = 16;
 
 }

Modified: jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/version/VersionIteratorImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/version/VersionIteratorImpl.java?rev=935321&r1=935320&r2=935321&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/version/VersionIteratorImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/version/VersionIteratorImpl.java
Sun Apr 18 09:52:27 2010
@@ -33,7 +33,7 @@ public class VersionIteratorImpl extends
 
     public Version nextVersion() {
         log.code(this, "nextVersion");
-        return goNext();
+        return getNext();
     }
 
 }

Modified: jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestAll.java?rev=935321&r1=935320&r2=935321&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestAll.java (original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestAll.java Sun
Apr 18 09:52:27 2010
@@ -34,12 +34,23 @@ public class TestAll {
     public static Test suite() {
         TestSuite suite = new TestSuite("org.apache.jackrabbit.j3");
 
+        int todo;
+        // repository lock mechanism (required for sessions, journal?)
+        // Repository.OPTION_JOURNALED_OBSERVATION_SUPPORTED
+        // external events
+        // auto-close sessions, optionally log open stack trace
+        // ability to auto-delete old event journal entries
+        // ability to disable the even journal
+
+        // events: save space for n=addNode+n.setProperty+... or n.setProperty+n.setProperty+...
+
         suite.addTestSuite(TestBundle.class);
         suite.addTestSuite(TestNamespaceRegistry.class);
         suite.addTestSuite(TestNodeTypeRegistry.class);
         suite.addTestSuite(TestSecurity.class);
         suite.addTestSuite(TestCache.class);
         suite.addTestSuite(TestCreateNodesTraverse.class);
+        suite.addTestSuite(TestEventJournal.class);
 
         for (int i = 0; i < TestBase.URL.length; i++) {
             suite.addTestSuite(TestConcurrentWrite.class);

Modified: jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestBundle.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestBundle.java?rev=935321&r1=935320&r2=935321&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestBundle.java
(original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestBundle.java
Sun Apr 18 09:52:27 2010
@@ -26,6 +26,40 @@ import org.apache.jackrabbit.j3.mc.Val;
  */
 public class TestBundle extends TestCase {
 
+    public void testNodeId() {
+        try {
+            RepositoryImpl.getNodeId(268435456, 0);
+            fail();
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+        try {
+            RepositoryImpl.getNodeId(-1, 0);
+            fail();
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+        for (int workspaceId = 0; workspaceId < 268435455;) {
+            for (long baseNodeId = 0; baseNodeId < Integer.MAX_VALUE;) {
+                long nodeId = RepositoryImpl.getNodeId(workspaceId, baseNodeId);
+                long w = RepositoryImpl.getWorkspaceId(nodeId);
+                long b = RepositoryImpl.getBaseNodeId(nodeId);
+                assertEquals(workspaceId, w);
+                assertEquals(baseNodeId, b);
+                if (baseNodeId < 1000) {
+                    baseNodeId++;
+                } else {
+                    baseNodeId += baseNodeId;
+                }
+            }
+            if (workspaceId < 3000) {
+                workspaceId++;
+            } else {
+                workspaceId += workspaceId;
+            }
+        }
+    }
+
     public void testVal() {
         Val x = Val.get(Val.get(20));
         x = x.addOrdered(Val.get(10));
@@ -44,7 +78,7 @@ public class TestBundle extends TestCase
     public void testBundle() {
         Bundle bundle = Bundle.create(512);
         bundle.writeVal(Val.get("Hello")).writeVal(Val.get("World"));
-        assertEquals(12, bundle.length());
+        assertEquals(12, bundle.getPos());
         bundle.reset();
         assertEquals("Hello", bundle.readVal().getString());
         assertEquals("World", bundle.readVal().getString());
@@ -96,7 +130,7 @@ public class TestBundle extends TestCase
 
     static void testLength(boolean allowSmaller, Val v) {
         Bundle bundle = Bundle.create(512);
-        int len = bundle.writeVal(v).length();
+        int len = bundle.writeVal(v).getPos();
         // System.out.println("length: " + len + ": " + v);
         bundle.reset();
         Val v2 = bundle.readVal();

Modified: jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestConcurrentWrite.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestConcurrentWrite.java?rev=935321&r1=935320&r2=935321&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestConcurrentWrite.java
(original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestConcurrentWrite.java
Sun Apr 18 09:52:27 2010
@@ -47,6 +47,9 @@ public class TestConcurrentWrite extends
        assertEquals("testParent", n2.getName());
        s2.logout();
 
+       n.remove();
+       session.save();
+
    }
 
    public void tearDown() throws Exception {

Added: jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestEventJournal.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestEventJournal.java?rev=935321&view=auto
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestEventJournal.java
(added)
+++ jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestEventJournal.java
Sun Apr 18 09:52:27 2010
@@ -0,0 +1,50 @@
+/*
+ * 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.j3;
+
+import javax.jcr.Node;
+import javax.jcr.Session;
+import javax.jcr.observation.Event;
+import javax.jcr.observation.EventJournal;
+
+/**
+ * Test the event journal.
+ */
+public class TestEventJournal extends TestBase {
+
+    public void test() throws Exception {
+        Node n = session.getRootNode().addNode("testEventJournal");
+        session.getWorkspace().getObservationManager().setUserData("userData");
+        n.setProperty("test", 1);
+        session.save();
+
+        Session session2 = openSession();
+        EventJournal ej = session2.getWorkspace().getObservationManager().getEventJournal();
+        Event e = ej.nextEvent();
+        assertEquals("/testEventJournal", e.getPath());
+        assertEquals(Event.NODE_ADDED, e.getType());
+        assertEquals("userData", e.getUserData());
+        e = ej.nextEvent();
+        assertEquals("/testEventJournal/test", e.getPath());
+        assertEquals(Event.PROPERTY_ADDED, e.getType());
+        assertEquals("userData", e.getUserData());
+
+        n.remove();
+        session.save();
+    }
+
+}

Modified: jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestLock.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestLock.java?rev=935321&r1=935320&r2=935321&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestLock.java
(original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestLock.java
Sun Apr 18 09:52:27 2010
@@ -41,5 +41,9 @@ public class TestLock extends TestBase {
             // expected
         }
         session2.logout();
+
+        n.remove();
+        session.save();
     }
+
 }

Modified: jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestObservation.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestObservation.java?rev=935321&r1=935320&r2=935321&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestObservation.java
(original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestObservation.java
Sun Apr 18 09:52:27 2010
@@ -47,7 +47,7 @@ public class TestObservation extends Tes
         session2.logout();
 
         assertEquals(2, eventList.size());
-        assertEquals("[/t/test/jcr:primaryType:4:x, /t/test:1:x]", eventList.toString());
+        assertEquals("[/t/test:1:x, /t/test/jcr:primaryType:4:x]", eventList.toString());
     }
 
     /**

Modified: jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestSimple.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestSimple.java?rev=935321&r1=935320&r2=935321&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestSimple.java
(original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestSimple.java
Sun Apr 18 09:52:27 2010
@@ -74,6 +74,7 @@ public class TestSimple extends TestBase
         assertEquals("test", nit.nextNode().getName());
         assertTrue(nit.hasNext());
         assertEquals("test2", nit.nextNode().getName());
+
         assertFalse(nit.hasNext());
 
         createReadNodes();

Added: jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/slow/TestLargeTransaction.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/slow/TestLargeTransaction.java?rev=935321&view=auto
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/slow/TestLargeTransaction.java
(added)
+++ jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/slow/TestLargeTransaction.java
Sun Apr 18 09:52:27 2010
@@ -0,0 +1,55 @@
+/*
+ * 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.j3.slow;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import org.apache.jackrabbit.j3.TestBase;
+
+/**
+ * Tests a large transaction.
+ */
+public class TestLargeTransaction extends TestBase {
+
+    public void test() throws Exception {
+        Node n = session.getRootNode().addNode("testLarge");
+        // transiently create about 1 million nodes
+        int count = add(0, n, 10, 5);
+        System.out.println(count);
+        long time = System.currentTimeMillis();
+        System.out.println("saving...");
+        // saving takes about 100 seconds
+        session.save();
+        System.out.println("saved in " + (System.currentTimeMillis() - time));
+    }
+
+    int add(int count, Node root, int size, int level) throws RepositoryException {
+        for (int i = 0; i < size; i++) {
+            Node n = root.addNode("test" + i);
+            count++;
+            if (count % 10000 == 0) {
+                System.out.println(count);
+            }
+            if (level > 0) {
+                count = add(count, n, size, level - 1);
+            }
+        }
+        return count;
+    }
+
+}
+



Mime
View raw message