jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r816237 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/cluster/ main/java/org/apache/jackrabbit/core/config/ main/java/org/apache/jackrabbit/core/journal/ test/java/org/apache/jackrabbit/core/cluster/ test/...
Date Thu, 17 Sep 2009 15:31:46 GMT
Author: jukka
Date: Thu Sep 17 15:31:45 2009
New Revision: 816237

URL: http://svn.apache.org/viewvc?rev=816237&view=rev
Log:
JCR-1438: Replace Config classes with factories

Replace JournalConfig with a JournalFactory.

Added:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/JournalFactory.java
  (with props)
Removed:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/JournalConfig.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/ClusterTest.java
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/BeanConfig.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/ClusterConfig.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfigurationParser.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/ClusterRecordTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/TestAll.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/config/RepositoryConfigTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/journal/FileJournalTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/cluster/repository.xml

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java?rev=816237&r1=816236&r2=816237&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
Thu Sep 17 15:31:45 2009
@@ -16,23 +16,16 @@
  */
 package org.apache.jackrabbit.core.cluster;
 
-import java.io.File;
-import java.io.IOException;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.UUID;
 
 import javax.jcr.RepositoryException;
 
-import org.apache.commons.io.FileUtils;
-import org.apache.jackrabbit.core.id.NodeId;
 import org.apache.jackrabbit.core.cluster.WorkspaceRecord.CreateWorkspaceAction;
 import org.apache.jackrabbit.core.config.ClusterConfig;
-import org.apache.jackrabbit.core.config.ConfigurationException;
-import org.apache.jackrabbit.core.config.JournalConfig;
-import org.apache.jackrabbit.core.journal.AbstractJournal;
+import org.apache.jackrabbit.core.id.NodeId;
 import org.apache.jackrabbit.core.journal.InstanceRevision;
 import org.apache.jackrabbit.core.journal.Journal;
 import org.apache.jackrabbit.core.journal.JournalException;
@@ -63,11 +56,6 @@
     public static final String SYSTEM_PROPERTY_NODE_ID = "org.apache.jackrabbit.core.cluster.node_id";
 
     /**
-     * Cluster node id file.
-     */
-    private static final String CLUSTER_NODE_ID_FILE = "cluster_node.id";
-
-    /**
      * Producer identifier.
      */
     private static final String PRODUCER_ID = "JR";
@@ -209,35 +197,20 @@
      */
     protected void init() throws ClusterException {
         ClusterConfig cc = clusterContext.getClusterConfig();
-        clusterNodeId = getClusterNodeId(cc.getId());
+        clusterNodeId = cc.getId();
         syncDelay = cc.getSyncDelay();
 
         try {
-            JournalConfig jc = cc.getJournalConfig();
-            journal = (Journal) jc.newInstance();
-            setRepositoryHome(journal, clusterContext.getRepositoryHome());
-            journal.init(clusterNodeId, clusterContext.getNamespaceResolver());
+            journal = cc.getJournal(clusterContext.getNamespaceResolver());
             instanceRevision = journal.getInstanceRevision();
             journal.register(this);
             producer = journal.getProducer(PRODUCER_ID);
-        } catch (ConfigurationException e) {
-            throw new ClusterException(e.getMessage(), e.getCause());
+        } catch (RepositoryException e) {
+            throw new ClusterException(
+                    "Cluster initialization failed: " + this, e);
         } catch (JournalException e) {
-            throw new ClusterException(e.getMessage(), e.getCause());
-        }
-    }
-
-    /**
-     * Set a journal's repository home, if possible, i.e. if it is an
-     * <code>AbstractJournal</code>
-     *
-     * @param journal journal instance
-     * @param repHome repository home
-     */
-    private void setRepositoryHome(Journal journal, File repHome) {
-        if (journal instanceof AbstractJournal) {
-            AbstractJournal aj = (AbstractJournal) journal;
-            aj.setRepositoryHome(repHome);
+            throw new ClusterException(
+                    "Journal initialization failed: " + this, e);
         }
     }
 
@@ -394,44 +367,6 @@
         return journal;
     }
 
-    /**
-     * Return the instance id to be used for this node in the cluster.
-     * @param id configured id, <code>null</code> to generate a unique id
-     */
-    private String getClusterNodeId(String id) throws ClusterException {
-        if (id == null) {
-            id = System.getProperty(SYSTEM_PROPERTY_NODE_ID);
-            if (id == null) {
-                try {
-                    id = getClusterNodeIdFromFile();
-                } catch (IOException e) {
-                    throw new ClusterException(e.getMessage(), e.getCause());
-                }
-            }
-        }
-        return id;
-    }
-
-    /**
-     * Return a cluster node from a file, creating it if necessary.
-     *
-     * @return stored or generated cluster id
-     * @throws IOException if an I/O error occurs
-     */
-    protected String getClusterNodeIdFromFile() throws IOException {
-        String filename = clusterContext.getRepositoryHome() + File.separator + CLUSTER_NODE_ID_FILE;
-        File f = new File(filename);
-
-        if (f.exists() && f.canRead()) {
-            return FileUtils.readFileToString(f);
-        }
-
-        String id = UUID.randomUUID().toString();
-        FileUtils.writeStringToFile(f, id);
-        return id;
-
-    }
-
     //-----------------------------------------------< NamespaceEventListener >
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/BeanConfig.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/BeanConfig.java?rev=816237&r1=816236&r2=816237&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/BeanConfig.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/BeanConfig.java
Thu Sep 17 15:31:45 2009
@@ -20,7 +20,6 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.Iterator;
 import java.util.Properties;
 import java.util.Map;
 import java.util.HashMap;
@@ -33,7 +32,7 @@
  * and property information required to instantiate a class that conforms
  * with the JavaBean conventions.
  */
-public class BeanConfig {
+public class BeanConfig<T> {
 
     private static Logger log = LoggerFactory.getLogger(BeanConfig.class);
 
@@ -155,27 +154,24 @@
     public Object newInstance() throws ConfigurationException {
         try {
             // Instantiate the object using the default constructor
-            Class objectClass =
+            Class<?> objectClass =
                 Class.forName(getClassName(), true, getClassLoader());
             Object object = objectClass.newInstance();
 
             // Set all configured bean properties
             BeanMap map = new BeanMap(object);
-            Iterator iterator = map.keyIterator();
-            while (iterator.hasNext()) {
-                String name = (String) iterator.next();
-                String value = properties.getProperty(name);
+            for (Object key : map.keySet()) {
+                String value = properties.getProperty(key.toString());
                 if (value != null) {
-                    map.put(name, properties.getProperty(name));
+                    map.put(key, value);
                 }
             }
 
             if (validate) {
                 // Check that no invalid property names were configured
-                Iterator it = properties.keySet().iterator();
-                while (it.hasNext()) {
-                    String key = (String) it.next();
-                    if (!map.containsKey(key) && properties.getProperty(key) != null)
{
+                for (Object key : properties.keySet()) {
+                    if (!map.containsKey(key)
+                            && properties.getProperty(key.toString()) != null) {
                         String msg =
                             "Configured class " + object.getClass().getName()
                             + " does not contain the property " + key
@@ -186,7 +182,7 @@
                 }
             }
 
-            return object;
+            return (T) object;
         } catch (ClassNotFoundException e) {
             throw new ConfigurationException(
                     "Configured bean implementation class " + getClassName()

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/ClusterConfig.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/ClusterConfig.java?rev=816237&r1=816236&r2=816237&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/ClusterConfig.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/ClusterConfig.java
Thu Sep 17 15:31:45 2009
@@ -16,11 +16,16 @@
  */
 package org.apache.jackrabbit.core.config;
 
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.core.journal.Journal;
+import org.apache.jackrabbit.core.journal.JournalFactory;
+import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver;
+
 /**
- * Cluster configuration. This includes the journal configuration
- * {@link JournalConfig}.
+ * Cluster configuration.
  */
-public class ClusterConfig {
+public class ClusterConfig implements JournalFactory {
 
     /**
      * Identifier.
@@ -33,9 +38,9 @@
     private final long syncDelay;
 
     /**
-     * Journal configuration.
+     * Journal factory.
      */
-    private final JournalConfig jc;
+    private final JournalFactory jf;
 
     /**
      * Creates a new cluster configuration.
@@ -44,10 +49,10 @@
      * @param syncDelay syncDelay, in milliseconds
      * @param jc journal configuration
      */
-    public ClusterConfig(String id, long syncDelay, JournalConfig jc) {
+    public ClusterConfig(String id, long syncDelay, JournalFactory jf) {
         this.id = id;
         this.syncDelay = syncDelay;
-        this.jc = jc;
+        this.jf = jf;
     }
 
     /**
@@ -69,11 +74,16 @@
     }
 
     /**
-     * Returns the journal configuration.
+     * Returns an initialized journal instance.
      *
-     * @return journal configuration
-     */
-    public JournalConfig getJournalConfig() {
-        return jc;
+     * @param resolver namespace resolver
+     * @return initialized journal
+     * @throws RepositoryException 
+     * @throws RepositoryException if the journal can not be created
+     */
+    public Journal getJournal(NamespaceResolver resolver)
+            throws RepositoryException {
+        return jf.getJournal(resolver);
     }
+
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfigurationParser.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfigurationParser.java?rev=816237&r1=816236&r2=816237&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfigurationParser.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfigurationParser.java
Thu Sep 17 15:31:45 2009
@@ -16,24 +16,33 @@
  */
 package org.apache.jackrabbit.core.config;
 
+import org.apache.commons.io.FileUtils;
+import org.apache.jackrabbit.core.cluster.ClusterNode;
 import org.apache.jackrabbit.core.data.DataStore;
 import org.apache.jackrabbit.core.data.DataStoreFactory;
 import org.apache.jackrabbit.core.fs.FileSystem;
 import org.apache.jackrabbit.core.fs.FileSystemException;
 import org.apache.jackrabbit.core.fs.FileSystemFactory;
+import org.apache.jackrabbit.core.journal.AbstractJournal;
+import org.apache.jackrabbit.core.journal.Journal;
+import org.apache.jackrabbit.core.journal.JournalException;
+import org.apache.jackrabbit.core.journal.JournalFactory;
 import org.apache.jackrabbit.core.state.DefaultISMLocking;
 import org.apache.jackrabbit.core.state.ISMLocking;
 import org.apache.jackrabbit.core.state.ISMLockingFactory;
 import org.apache.jackrabbit.core.util.RepositoryLock;
 import org.apache.jackrabbit.core.util.RepositoryLockMechanism;
 import org.apache.jackrabbit.core.util.RepositoryLockMechanismFactory;
+import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 import org.xml.sax.InputSource;
 
 import java.io.File;
+import java.io.IOException;
 import java.util.Properties;
+import java.util.UUID;
 
 import javax.jcr.RepositoryException;
 
@@ -169,6 +178,11 @@
     private static final String AC_PROVIDER_ELEMENT = "AccessControlProvider";
 
     /**
+     * Name of the cluster node id file.
+     */
+    private static final String CLUSTER_NODE_ID_FILE = "cluster_node.id";
+
+    /**
      * Creates a new configuration parser with the given parser variables.
      *
      * @param variables parser variables
@@ -265,7 +279,7 @@
         SearchConfig sc = parseSearchConfig(root);
 
         // Optional journal configuration
-        ClusterConfig cc = parseClusterConfig(root);
+        ClusterConfig cc = parseClusterConfig(root, new File(home));
 
         // Optional data store factory
         DataStoreFactory dsf = getDataStoreFactory(root, home);
@@ -666,10 +680,11 @@
      * method returns <code>null</code>.
      *
      * @param parent parent of the <code>Journal</code> element
+     * @param home repository home directory
      * @return cluster configuration, or <code>null</code>
      * @throws ConfigurationException if the configuration is broken
      */
-    protected ClusterConfig parseClusterConfig(Element parent)
+    protected ClusterConfig parseClusterConfig(Element parent, File home)
             throws ConfigurationException {
 
         NodeList children = parent.getChildNodes();
@@ -679,17 +694,32 @@
                     && CLUSTER_ELEMENT.equals(child.getNodeName())) {
                 Element element = (Element) child;
 
-                String id = null;
-
+                // Find the cluster node id
+                String id =
+                    System.getProperty(ClusterNode.SYSTEM_PROPERTY_NODE_ID);
                 String value = getAttribute(element, ID_ATTRIBUTE, null);
                 if (value != null) {
                     id = replaceVariables(value);
+                } else if (id == null) {
+                    File file = new File(home, CLUSTER_NODE_ID_FILE);
+                    try {
+                        if (file.exists() && file.canRead()) {
+                            id = FileUtils.readFileToString(file);
+                        } else {
+                            id = UUID.randomUUID().toString();
+                            FileUtils.writeStringToFile(file, id);
+                        }
+                    } catch (IOException e) {
+                        throw new ConfigurationException(
+                                "Failed to access cluster node id: " + file, e);
+                    }
                 }
-                value = getAttribute(element, SYNC_DELAY_ATTRIBUTE, DEFAULT_SYNC_DELAY);
-                long syncDelay = Long.parseLong(replaceVariables(value));
 
-                JournalConfig jc = parseJournalConfig(element);
-                return new ClusterConfig(id, syncDelay, jc);
+                long syncDelay = Long.parseLong(replaceVariables(getAttribute(
+                        element, SYNC_DELAY_ATTRIBUTE, DEFAULT_SYNC_DELAY)));
+
+                JournalFactory jf = getJournalFactory(element, home, id);
+                return new ClusterConfig(id, syncDelay, jf);
             }
         }
         return null;
@@ -708,14 +738,39 @@
      * element.
      *
      * @param cluster parent cluster element
-     * @return journal configuration, or <code>null</code>
-     * @throws ConfigurationException if the configuration is broken
-     */
-    protected JournalConfig parseJournalConfig(Element cluster)
-            throws ConfigurationException {
-
-        return new JournalConfig(
-                parseBeanConfig(cluster, JOURNAL_ELEMENT));
+     * @param home repository home directory
+     * @param id cluster node id
+     * @return journal factory
+     * @throws ConfigurationException if the configuration is broken
+     */
+    protected JournalFactory getJournalFactory(
+            final Element cluster, final File home, final String id)
+            throws ConfigurationException {
+        return new JournalFactory() {
+            public Journal getJournal(NamespaceResolver resolver)
+                    throws RepositoryException {
+                BeanConfig config = parseBeanConfig(cluster, JOURNAL_ELEMENT);
+                Object object = config.newInstance();
+                if (object instanceof Journal) {
+                    Journal journal = (Journal) object;
+                    if (journal instanceof AbstractJournal) {
+                        ((AbstractJournal) journal).setRepositoryHome(home);
+                    }
+                    try {
+                        journal.init(id, resolver);
+                    } catch (JournalException e) {
+                        // TODO: Should JournalException extend RepositoryException?
+                        throw new RepositoryException(
+                                "Journal initialization failed: " + journal, e);
+                    }
+                    return journal;
+                } else {
+                    throw new RepositoryException(
+                            "Invalid Journal implementation class: "
+                            + config.getClassName());
+                }
+            }
+        };
     }
 
     /**

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/JournalFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/JournalFactory.java?rev=816237&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/JournalFactory.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/JournalFactory.java
Thu Sep 17 15:31:45 2009
@@ -0,0 +1,40 @@
+/*
+ * 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.core.journal;
+
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver;
+
+/**
+ * Factory interface for creating {@link Journal} instances. Used
+ * to decouple the repository internals from the repository configuration
+ * mechanism.
+ */
+public interface JournalFactory {
+
+    /**
+     * Creates, initializes, and returns a {@link Journal} instance
+     * for use by the repository.
+     *
+     * @param resolver namespace resolver
+     * @return initialized journal
+     * @throws RepositoryException if the journal can not be created
+     */
+    Journal getJournal(NamespaceResolver resolver) throws RepositoryException;
+
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/JournalFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/ClusterRecordTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/ClusterRecordTest.java?rev=816237&r1=816236&r2=816237&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/ClusterRecordTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/ClusterRecordTest.java
Thu Sep 17 15:31:45 2009
@@ -17,22 +17,25 @@
 package org.apache.jackrabbit.core.cluster;
 
 import java.util.ArrayList;
-import java.util.Properties;
 
-import org.apache.jackrabbit.core.id.NodeId;
+import javax.jcr.RepositoryException;
+
 import org.apache.jackrabbit.core.cluster.SimpleEventListener.LockEvent;
 import org.apache.jackrabbit.core.cluster.SimpleEventListener.NamespaceEvent;
 import org.apache.jackrabbit.core.cluster.SimpleEventListener.NodeTypeEvent;
 import org.apache.jackrabbit.core.cluster.SimpleEventListener.UnlockEvent;
 import org.apache.jackrabbit.core.cluster.SimpleEventListener.UpdateEvent;
-import org.apache.jackrabbit.core.config.BeanConfig;
 import org.apache.jackrabbit.core.config.ClusterConfig;
-import org.apache.jackrabbit.core.config.JournalConfig;
+import org.apache.jackrabbit.core.id.NodeId;
+import org.apache.jackrabbit.core.journal.Journal;
+import org.apache.jackrabbit.core.journal.JournalFactory;
 import org.apache.jackrabbit.core.journal.MemoryJournal;
+import org.apache.jackrabbit.core.journal.MemoryJournal.MemoryRecord;
 import org.apache.jackrabbit.core.nodetype.NodeTypeDef;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
 import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
+import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver;
 import org.apache.jackrabbit.test.JUnitTest;
 
 /**
@@ -59,7 +62,7 @@
     /**
      * Records shared among multiple memory journals.
      */
-    private ArrayList records = new ArrayList();
+    private ArrayList<MemoryRecord> records = new ArrayList<MemoryRecord>();
 
     /**
      * Master.
@@ -179,7 +182,7 @@
         ntd.setName(NameFactoryImpl.getInstance().create("", "test"));
         ntd.setSupertypes(new Name[]{NameConstants.NT_BASE});
 
-        ArrayList list = new ArrayList();
+        ArrayList<NodeTypeDef> list = new ArrayList<NodeTypeDef>();
         list.add(ntd);
 
         NodeTypeEvent event = new NodeTypeEvent(NodeTypeEvent.REGISTER, list);
@@ -202,7 +205,7 @@
         ntd.setName(NameFactoryImpl.getInstance().create("", "test"));
         ntd.setSupertypes(new Name[]{NameConstants.NT_BASE});
 
-        ArrayList list = new ArrayList();
+        ArrayList<NodeTypeDef> list = new ArrayList<NodeTypeDef>();
         list.add(ntd);
 
         NodeTypeEvent event = new NodeTypeEvent(NodeTypeEvent.REREGISTER, list);
@@ -223,7 +226,7 @@
     public void testNodeTypeUnregistration() throws Exception {
         Name name = NameFactoryImpl.getInstance().create("", "test");
 
-        ArrayList list = new ArrayList();
+        ArrayList<Name> list = new ArrayList<Name>();
         list.add(name);
 
         NodeTypeEvent event = new NodeTypeEvent(NodeTypeEvent.UNREGISTER, list);
@@ -277,19 +280,26 @@
      * @param id cluster node id
      * @param records memory journal's list of records
      */
-    private ClusterNode createClusterNode(String id, ArrayList records)
-            throws ClusterException {
-
-        BeanConfig bc = new BeanConfig(MemoryJournal.class.getName(), new Properties());
-        JournalConfig jc = new JournalConfig(bc);
-        ClusterConfig cc = new ClusterConfig(id, SYNC_DELAY, jc);
+    private ClusterNode createClusterNode(
+            String id, ArrayList<MemoryRecord> records) throws Exception {
+        final MemoryJournal journal = new MemoryJournal();
+        JournalFactory jf = new JournalFactory() {
+            public Journal getJournal(NamespaceResolver resolver)
+                    throws RepositoryException {
+                return journal;
+            }
+        };
+        ClusterConfig cc = new ClusterConfig(id, SYNC_DELAY, jf);
         SimpleClusterContext context = new SimpleClusterContext(cc);
 
-        ClusterNode clusterNode = new ClusterNode();
-        clusterNode.init(context);
+        journal.setRepositoryHome(context.getRepositoryHome());
+        journal.init(id, context.getNamespaceResolver());
         if (records != null) {
-            ((MemoryJournal) clusterNode.getJournal()).setRecords(records);
+            journal.setRecords(records);
         }
+
+        ClusterNode clusterNode = new ClusterNode();
+        clusterNode.init(context);
         return clusterNode;
     }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/TestAll.java?rev=816237&r1=816236&r2=816237&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/TestAll.java
Thu Sep 17 15:31:45 2009
@@ -38,7 +38,6 @@
         TestSuite suite = new TestSuite();
 
         suite.addTestSuite(ClusterRecordTest.class);
-        suite.addTestSuite(ClusterTest.class);
 
         return suite;
     }

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/config/RepositoryConfigTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/config/RepositoryConfigTest.java?rev=816237&r1=816236&r2=816237&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/config/RepositoryConfigTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/config/RepositoryConfigTest.java
Thu Sep 17 15:31:45 2009
@@ -20,6 +20,7 @@
 import org.xml.sax.InputSource;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.input.ClosedInputStream;
+import org.apache.jackrabbit.core.cluster.ClusterNode;
 import org.apache.jackrabbit.core.security.authorization.WorkspaceAccessManager;
 
 import java.io.File;
@@ -259,16 +260,56 @@
         final String id = "testvalue";
         final long syncDelay = 11;
 
-        System.setProperty("cluster.id", id);
+        System.setProperty(ClusterNode.SYSTEM_PROPERTY_NODE_ID, id);
         System.setProperty("cluster.syncDelay", Long.toString(syncDelay));
+        try {
+            InputStream in = getClass().getResourceAsStream(
+                    "/org/apache/jackrabbit/core/cluster/repository.xml");
+            RepositoryConfig config = RepositoryConfig.create(in, DIR.getPath());
+
+            ClusterConfig clusterConfig = config.getClusterConfig();
+            assertEquals(id, clusterConfig.getId());
+            assertEquals(syncDelay, clusterConfig.getSyncDelay());
+        } finally {
+            System.clearProperty(ClusterNode.SYSTEM_PROPERTY_NODE_ID);
+            System.clearProperty("cluster.syncDelay");
+        }
+    }
+
+    public void testAutomaticClusterNodeIdCreation() throws Exception {
+        final long syncDelay = 12;
 
-        InputStream in = getClass().getResourceAsStream(
-                "/org/apache/jackrabbit/core/cluster/repository.xml");
-        RepositoryConfig config = RepositoryConfig.create(in, DIR.getPath());
-
-        ClusterConfig clusterConfig = config.getClusterConfig();
-        assertEquals(id, clusterConfig.getId());
-        assertEquals(syncDelay, clusterConfig.getSyncDelay());
+        System.setProperty("cluster.syncDelay", Long.toString(syncDelay));
+        try {
+            File file = new File(DIR, "cluster_node.id");
+            assertFalse(file.exists());
+
+            // Check that a new cluster node id is automatically persisted
+            InputStream in = getClass().getResourceAsStream(
+                    "/org/apache/jackrabbit/core/cluster/repository.xml");
+            RepositoryConfig config = RepositoryConfig.create(in, DIR.getPath());
+
+            assertTrue(file.exists());
+            String id = FileUtils.readFileToString(file);
+
+            ClusterConfig clusterConfig = config.getClusterConfig();
+            assertEquals(id, clusterConfig.getId());
+            assertEquals(syncDelay, clusterConfig.getSyncDelay());
+
+            // Check that the persisted cluster node id is used when it exists
+            in = getClass().getResourceAsStream(
+                    "/org/apache/jackrabbit/core/cluster/repository.xml");
+            config = RepositoryConfig.create(in, DIR.getPath());
+
+            assertTrue(file.exists());
+            assertEquals(id, FileUtils.readFileToString(file));
+
+            clusterConfig = config.getClusterConfig();
+            assertEquals(id, clusterConfig.getId());
+            assertEquals(syncDelay, clusterConfig.getSyncDelay());
+        } finally {
+            System.clearProperty("cluster.syncDelay");
+        }
     }
 
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/journal/FileJournalTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/journal/FileJournalTest.java?rev=816237&r1=816236&r2=816237&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/journal/FileJournalTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/journal/FileJournalTest.java
Thu Sep 17 15:31:45 2009
@@ -17,14 +17,14 @@
 package org.apache.jackrabbit.core.journal;
 
 import java.io.File;
-import java.util.Properties;
+
+import javax.jcr.RepositoryException;
 
 import org.apache.commons.io.FileUtils;
 import org.apache.jackrabbit.core.cluster.ClusterNode;
 import org.apache.jackrabbit.core.cluster.SimpleClusterContext;
-import org.apache.jackrabbit.core.config.BeanConfig;
 import org.apache.jackrabbit.core.config.ClusterConfig;
-import org.apache.jackrabbit.core.config.JournalConfig;
+import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver;
 import org.apache.jackrabbit.test.JUnitTest;
 
 /**
@@ -87,20 +87,25 @@
      * @see <a href="http://issues.apache.org/jira/browse/JCR-904">JCR-904</a>
      */
     public void testRevisionIsOptional() throws Exception {
-        Properties params = new Properties();
-        params.setProperty("directory", journalDirectory.getPath());
-
-        BeanConfig bc = new BeanConfig(FileJournal.class.getName(), params);
-        JournalConfig jc = new JournalConfig(bc);
-
-        ClusterConfig cc = new ClusterConfig(CLUSTER_NODE_ID, SYNC_DELAY, jc);
+        final FileJournal journal = new FileJournal();
+        journal.setDirectory(journalDirectory.getPath());
+        JournalFactory jf = new JournalFactory() {
+            public Journal getJournal(NamespaceResolver resolver) {
+                return journal;
+            }
+        };
+        ClusterConfig cc = new ClusterConfig(CLUSTER_NODE_ID, SYNC_DELAY, jf);
         SimpleClusterContext context = new SimpleClusterContext(cc, repositoryHome);
 
+        journal.setRepositoryHome(repositoryHome);
+        journal.init(CLUSTER_NODE_ID, context.getNamespaceResolver());
+
         ClusterNode clusterNode = new ClusterNode();
         clusterNode.init(context);
 
         try {
-            File revisionFile = new File(repositoryHome, FileJournal.DEFAULT_INSTANCE_FILE_NAME);
+            File revisionFile =
+                new File(repositoryHome, FileJournal.DEFAULT_INSTANCE_FILE_NAME);
             assertTrue(revisionFile.exists());
         } finally {
             clusterNode.stop();
@@ -114,12 +119,13 @@
      * @throws Exception
      */
     public void testClusterInitIncompleteBadJournalClass() throws Exception {
-        Properties params = new Properties();
-
-        BeanConfig bc = new BeanConfig(Object.class.getName(), params);
-        JournalConfig jc = new JournalConfig(bc);
-
-        ClusterConfig cc = new ClusterConfig(CLUSTER_NODE_ID, SYNC_DELAY, jc);
+        JournalFactory jf = new JournalFactory() {
+            public Journal getJournal(NamespaceResolver resolver)
+                    throws RepositoryException {
+                throw new RepositoryException("Journal not available");
+            }
+        };
+        ClusterConfig cc = new ClusterConfig(CLUSTER_NODE_ID, SYNC_DELAY, jf);
         SimpleClusterContext context = new SimpleClusterContext(cc);
 
         ClusterNode clusterNode = new ClusterNode();
@@ -142,16 +148,23 @@
      * @throws Exception
      */
     public void testClusterInitIncompleteMissingParam() throws Exception {
-        Properties params = new Properties();
-
-        BeanConfig bc = new BeanConfig(FileJournal.class.getName(), params);
-        JournalConfig jc = new JournalConfig(bc);
-
-        ClusterConfig cc = new ClusterConfig(CLUSTER_NODE_ID, SYNC_DELAY, jc);
+        JournalFactory jf = new JournalFactory() {
+            public Journal getJournal(NamespaceResolver resolver)
+                    throws RepositoryException {
+                try {
+                    FileJournal journal = new FileJournal();
+                    // no setDirectory() call here
+                    journal.init(CLUSTER_NODE_ID, resolver);
+                    return journal;
+                } catch (JournalException e) {
+                    throw new RepositoryException("Expected failure", e);
+                }
+            }
+        };
+        ClusterConfig cc = new ClusterConfig(CLUSTER_NODE_ID, SYNC_DELAY, jf);
         SimpleClusterContext context = new SimpleClusterContext(cc);
 
         ClusterNode clusterNode = new ClusterNode();
-
         try {
             clusterNode.init(context);
             fail("Bad cluster configuration.");

Modified: jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/cluster/repository.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/cluster/repository.xml?rev=816237&r1=816236&r2=816237&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/cluster/repository.xml
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/cluster/repository.xml
Thu Sep 17 15:31:45 2009
@@ -142,7 +142,7 @@
     <!--
         Cluster configuration with system variables.
     -->
-    <Cluster id="${cluster.id}" syncDelay="${cluster.syncDelay}">
+    <Cluster syncDelay="${cluster.syncDelay}">
         <Journal class="org.apache.jackrabbit.core.journal.JNDIDatabaseJournal">
             <param name="schema" value="oracle" />
         </Journal>



Mime
View raw message