jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r388559 - in /jackrabbit/trunk/jackrabbit/src: main/java/org/apache/jackrabbit/core/query/lucene/ test/java/org/apache/jackrabbit/core/observation/ test/java/org/apache/jackrabbit/core/query/
Date Fri, 24 Mar 2006 15:17:23 GMT
Author: mreutegg
Date: Fri Mar 24 07:17:20 2006
New Revision: 388559

URL: http://svn.apache.org/viewcvs?rev=388559&view=rev
Log:
JCR-257: Use separate index for jcr:system tree
- use common namespace mapping if there is a system index
- Added some test cases

Added:
    jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/observation/VersionEventsTest.java
  (with props)
    jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/query/VersionStoreQueryTest.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
    jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/observation/TestAll.java
    jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/query/TestAll.java

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
URL: http://svn.apache.org/viewcvs/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java?rev=388559&r1=388558&r2=388559&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
Fri Mar 24 07:17:20 2006
@@ -77,11 +77,6 @@
     private static final Logger log = LoggerFactory.getLogger(MultiIndex.class);
 
     /**
-     * Name of the file to persist search internal namespace mappings
-     */
-    private static final String NS_MAPPING_FILE = "ns_mappings.properties";
-
-    /**
      * Default name of the redo log file
      */
     private static final String REDO_LOG = "redo.log";
@@ -201,19 +196,22 @@
      * @param rootId id of the root node
      * @param excludedIDs   Set<NodeId> that contains uuids that should not
      *                      be indexed nor further traversed.
+     * @param mapping the namespace mapping to use
      * @throws IOException if an error occurs
      */
     MultiIndex(File indexDir,
                SearchIndex handler,
                ItemStateManager stateMgr,
                NodeId rootId,
-               Set excludedIDs) throws IOException {
+               Set excludedIDs,
+               NamespaceMappings mapping) throws IOException {
 
         this.indexDir = indexDir;
         this.handler = handler;
         this.cache = new DocNumberCache(handler.getCacheSize());
         this.redoLog = new RedoLog(new File(indexDir, REDO_LOG));
         this.excludedIDs = new HashSet(excludedIDs);
+        this.nsMappings = mapping;
 
         if (indexNames.exists(indexDir)) {
             indexNames.read(indexDir);
@@ -224,10 +222,6 @@
 
         // try to remove deletable files if there are any
         attemptDelete();
-
-        // read namespace mappings
-        File mapFile = new File(indexDir, NS_MAPPING_FILE);
-        nsMappings = new NamespaceMappings(mapFile);
 
         // initialize IndexMerger
         merger = new IndexMerger(this);

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
URL: http://svn.apache.org/viewcvs/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java?rev=388559&r1=388558&r2=388559&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
Fri Mar 24 07:17:20 2006
@@ -65,6 +65,11 @@
     private static final Logger log = LoggerFactory.getLogger(SearchIndex.class);
 
     /**
+     * Name of the file to persist search internal namespace mappings
+     */
+    private static final String NS_MAPPING_FILE = "ns_mappings.properties";
+
+    /**
      * The default value for property {@link #minMergeDocs}.
      */
     public static final int DEFAULT_MIN_MERGE_DOCS = 100;
@@ -197,8 +202,21 @@
             excludedIDs.add(context.getExcludedNodeId());
         }
 
-        index = new MultiIndex(new File(path), this,
-                context.getItemStateManager(), context.getRootId(), excludedIDs);
+        File indexDir = new File(path);
+
+        NamespaceMappings nsMappings;
+        if (context.getParentHandler() instanceof SearchIndex) {
+            // use system namespace mappings
+            SearchIndex sysIndex = (SearchIndex) context.getParentHandler();
+            nsMappings = sysIndex.getNamespaceMappings();
+        } else {
+            // read local namespace mappings
+            File mapFile = new File(indexDir, NS_MAPPING_FILE);
+             nsMappings = new NamespaceMappings(mapFile);
+        }
+
+        index = new MultiIndex(indexDir, this, context.getItemStateManager(),
+                context.getRootId(), excludedIDs, nsMappings);
         if (index.getRedoLogApplied() || forceConsistencyCheck) {
             log.info("Running consistency check...");
             try {

Modified: jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/observation/TestAll.java
URL: http://svn.apache.org/viewcvs/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/observation/TestAll.java?rev=388559&r1=388558&r2=388559&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/observation/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/observation/TestAll.java
Fri Mar 24 07:17:20 2006
@@ -37,6 +37,7 @@
 
         suite.addTestSuite(ReorderTest.class);
         suite.addTestSuite(MixinTest.class);
+        suite.addTestSuite(VersionEventsTest.class);
 
         return suite;
     }

Added: jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/observation/VersionEventsTest.java
URL: http://svn.apache.org/viewcvs/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/observation/VersionEventsTest.java?rev=388559&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/observation/VersionEventsTest.java
(added)
+++ jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/observation/VersionEventsTest.java
Fri Mar 24 07:17:20 2006
@@ -0,0 +1,202 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  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.core.observation;
+
+import org.apache.jackrabbit.test.api.observation.AbstractObservationTest;
+import org.apache.jackrabbit.test.api.observation.EventResult;
+import org.apache.jackrabbit.core.UserTransactionImpl;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Node;
+import javax.jcr.Session;
+import javax.jcr.observation.Event;
+import javax.jcr.observation.ObservationManager;
+import javax.jcr.version.Version;
+import javax.transaction.UserTransaction;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * <code>VersionEventsTest</code> checks if the correct events are triggered
+ * for version operations.
+ */
+public class VersionEventsTest extends AbstractObservationTest {
+
+    /**
+     * Test if checkin of a node creates two add node events: one for the
+     * version and one for the frozen node.
+     */
+    public void testCheckin() throws RepositoryException {
+        // create versionable node
+        Node n1 = testRootNode.addNode(nodeName1);
+        n1.addMixin(mixVersionable);
+        testRootNode.save();
+
+        EventResult listener = new EventResult(log);
+        addEventListener(listener, Event.NODE_ADDED);
+        Version v = n1.checkin();
+        removeEventListener(listener);
+
+        Event[] events = listener.getEvents(1000);
+        Set paths = new HashSet();
+        for (int i = 0; i < events.length; i++) {
+            paths.add(events[i].getPath());
+        }
+
+        assertTrue("missing 'node added' event: " + v.getPath(), paths.contains(v.getPath()));
+        String frozenPath = v.getPath() + "/" + jcrFrozenNode;
+        assertTrue("missing 'node added' event: " + frozenPath, paths.contains(frozenPath));
+    }
+
+    /**
+     * Test if checkin of a node in an XA transaction creates two add node
+     * events: one for the version and one for the frozen node.
+     */
+    public void testXACheckin() throws Exception {
+        // create versionable node
+        Node n1 = testRootNode.addNode(nodeName1);
+        n1.addMixin(mixVersionable);
+        testRootNode.save();
+
+        EventResult listener = new EventResult(log);
+        addEventListener(listener, Event.NODE_ADDED);
+
+        // use a transaction
+        UserTransaction utx = new UserTransactionImpl(superuser);
+        // start transaction
+        utx.begin();
+        Version v = n1.checkin();
+        // commit transaction
+        utx.commit();
+
+        removeEventListener(listener);
+
+        Event[] events = listener.getEvents(1000);
+        Set paths = new HashSet();
+        for (int i = 0; i < events.length; i++) {
+            paths.add(events[i].getPath());
+        }
+
+        assertTrue("missing 'node added' event: " + v.getPath(), paths.contains(v.getPath()));
+        String frozenPath = v.getPath() + "/" + jcrFrozenNode;
+        assertTrue("missing 'node added' event: " + frozenPath, paths.contains(frozenPath));
+    }
+
+    /**
+     * Test if removing a version triggers two node removed events: one for the
+     * version and one for the frozen node.
+     */
+    public void testRemoveVersion() throws RepositoryException {
+        // create versionable node
+        Node n1 = testRootNode.addNode(nodeName1);
+        n1.addMixin(mixVersionable);
+        testRootNode.save();
+
+        Version v = n1.checkin();
+        String versionPath = v.getPath();
+
+        n1.remove();
+        testRootNode.save();
+
+        EventResult listener = new EventResult(log);
+        addEventListener(listener, Event.NODE_REMOVED);
+        v.getContainingHistory().removeVersion(v.getName());
+        removeEventListener(listener);
+
+        Event[] events = listener.getEvents(1000);
+        Set paths = new HashSet();
+        for (int i = 0; i < events.length; i++) {
+            paths.add(events[i].getPath());
+        }
+
+        assertTrue("missing 'node removed' event: " + versionPath, paths.contains(versionPath));
+        String frozenPath = versionPath + "/" + jcrFrozenNode;
+        assertTrue("missing 'node removed' event: " + frozenPath, paths.contains(frozenPath));
+    }
+
+    /**
+     * Test if removing a version in an XA transaction triggers two node removed
+     * events: one for the version and one for the frozen node.
+     */
+    public void testXARemoveVersion() throws Exception {
+        // create versionable node
+        Node n1 = testRootNode.addNode(nodeName1);
+        n1.addMixin(mixVersionable);
+        testRootNode.save();
+
+        Version v = n1.checkin();
+        String versionPath = v.getPath();
+
+        n1.remove();
+        testRootNode.save();
+
+        EventResult listener = new EventResult(log);
+        addEventListener(listener, Event.NODE_REMOVED);
+
+        // use a transaction
+        UserTransaction utx = new UserTransactionImpl(superuser);
+        // start transaction
+        utx.begin();
+        v.getContainingHistory().removeVersion(v.getName());
+        // commit transaction
+        utx.commit();
+
+        removeEventListener(listener);
+
+        Event[] events = listener.getEvents(1000);
+        Set paths = new HashSet();
+        for (int i = 0; i < events.length; i++) {
+            paths.add(events[i].getPath());
+        }
+
+        assertTrue("missing 'node removed' event: " + versionPath, paths.contains(versionPath));
+        String frozenPath = versionPath + "/" + jcrFrozenNode;
+        assertTrue("missing 'node removed' event: " + frozenPath, paths.contains(frozenPath));
+    }
+
+    /**
+     * Test if checkin creates events also on a different workspace than the one
+     * where the checkin was executed.
+     */
+    public void testCheckinOtherWorkspace() throws RepositoryException {
+        // create versionable node
+        Node n1 = testRootNode.addNode(nodeName1);
+        n1.addMixin(mixVersionable);
+        testRootNode.save();
+
+        Session s = helper.getReadOnlySession(workspaceName);
+        try {
+            EventResult listener = new EventResult(log);
+            ObservationManager obsMgr = s.getWorkspace().getObservationManager();
+            obsMgr.addEventListener(listener, Event.NODE_ADDED, "/", true,
+                    null, null, false);
+            Version v = n1.checkin();
+            obsMgr.removeEventListener(listener);
+
+            Event[] events = listener.getEvents(1000);
+            Set paths = new HashSet();
+            for (int i = 0; i < events.length; i++) {
+                paths.add(events[i].getPath());
+            }
+
+            assertTrue("missing 'node removed': " + v.getPath(), paths.contains(v.getPath()));
+            String frozenPath = v.getPath() + "/" + jcrFrozenNode;
+            assertTrue("missing 'node removed': " + frozenPath, paths.contains(frozenPath));
+        } finally {
+            s.logout();
+        }
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/observation/VersionEventsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/query/TestAll.java
URL: http://svn.apache.org/viewcvs/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/query/TestAll.java?rev=388559&r1=388558&r2=388559&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/query/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/query/TestAll.java
Fri Mar 24 07:17:20 2006
@@ -43,6 +43,7 @@
         suite.addTestSuite(SkipDeletedNodesTest.class);
         suite.addTestSuite(MixinTest.class);
         suite.addTestSuite(DerefTest.class);
+        suite.addTestSuite(VersionStoreQueryTest.class);
 
         // exclude long running tests per default
         //suite.addTestSuite(MassiveRangeTest.class);

Added: jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/query/VersionStoreQueryTest.java
URL: http://svn.apache.org/viewcvs/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/query/VersionStoreQueryTest.java?rev=388559&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/query/VersionStoreQueryTest.java
(added)
+++ jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/query/VersionStoreQueryTest.java
Fri Mar 24 07:17:20 2006
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  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.core.query;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Node;
+import java.util.Calendar;
+
+/**
+ * <code>VersionStoreQueryTest</code> tests queries against the version store.
+ */
+public class VersionStoreQueryTest extends AbstractQueryTest {
+
+    /**
+     * Tests if after each checkin an additional node is returned in a result
+     * of a query.
+     */
+    public void testCheckin() throws RepositoryException {
+        // current time
+        Calendar c = Calendar.getInstance();
+        Node n1 = testRootNode.addNode(nodeName1);
+        n1.setProperty(propertyName1, c);
+        n1.addMixin(mixVersionable);
+        testRootNode.save();
+
+        String statement = "//*[@" + propertyName1 + "=xs:dateTime('" +
+                n1.getProperty(propertyName1).getString() + "')]";
+
+        Node v1 = n1.checkin().getNode(jcrFrozenNode);
+
+        executeXPathQuery(statement, new Node[]{n1,v1});
+
+        n1.checkout();
+        Node v2 = n1.checkin().getNode(jcrFrozenNode);
+
+        executeXPathQuery(statement, new Node[]{n1,v1,v2});
+
+        n1.checkout();
+        Node v3 = n1.checkin().getNode(jcrFrozenNode);
+
+        executeXPathQuery(statement, new Node[]{n1,v1,v2,v3});
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/query/VersionStoreQueryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message