jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edgarp...@apache.org
Subject svn commit: r208988 [3/3] - in /incubator/jackrabbit/trunk/contrib/jcr-commands: ./ applications/ applications/test/ benchmarking/ jmeter-chain/ jmeter-chain/src/ jmeter-chain/src/java/ jmeter-chain/src/java/org/ jmeter-chain/src/java/org/apache/ jmete...
Date Sun, 03 Jul 2005 22:00:15 GMT
Added: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/StartOrGetJackrabbitSingleton.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/StartOrGetJackrabbitSingleton.java?rev=208988&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/StartOrGetJackrabbitSingleton.java
(added)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/StartOrGetJackrabbitSingleton.java
Sun Jul  3 15:00:10 2005
@@ -0,0 +1,119 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.chain.command;
+
+import javax.jcr.Repository;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jackrabbit.chain.ContextHelper;
+import org.apache.jackrabbit.chain.RepositoryPool;
+import org.apache.jackrabbit.core.RepositoryImpl;
+import org.apache.jackrabbit.core.config.RepositoryConfig;
+
+/**
+ * <p>
+ * Gets a Jackrabbit instance from the RepositoryPool and put in the Commons
+ * Chain Context. If there's no Repository for the given config then it will
+ * create a new instance and will add it to the pool.
+ * </p>
+ * <p>
+ * This is the recommended implementation to use in JMeter. It will create only
+ * one Jackrabbit instance on the first call and will reuse it in all the JMeter
+ * app lifecycle.
+ * </p>
+ */
+public class StartOrGetJackrabbitSingleton implements Command
+{
+    /** logger */
+    private static Log log = LogFactory.getLog(StartOrGetJackrabbitSingleton.class);
+
+    /** config file */
+    private String config;
+
+    /** home folder */
+    private String home;
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.commons.chain.Command#execute(org.apache.commons.chain.Context)
+     */
+    public boolean execute(Context ctx) throws Exception
+    {
+        try
+        {
+            RepositoryPool pool = RepositoryPool.getInstance();
+            synchronized (pool)
+            {
+                Repository repo = pool.get(config, home);
+                if (repo == null)
+                {
+                    String msg = "Starting Jakrabbit instance";
+                    System.out.println(msg);
+                    log.info(msg);
+                    RepositoryConfig conf = RepositoryConfig.create(config, home);
+                    repo = RepositoryImpl.create(conf);
+                    pool.put(config, home, repo);
+                }
+                ContextHelper.setRepository(ctx, repo);
+            }
+        } catch (Exception e)
+        {
+            e.printStackTrace();
+            throw e;
+        }
+        return false;
+    }
+
+    /**
+     * @return Returns the config.
+     */
+    public String getConfig()
+    {
+        return config;
+    }
+
+    /**
+     * @param config
+     *            The config to set.
+     */
+    public void setConfig(String config)
+    {
+        this.config = config;
+    }
+
+    /**
+     * @return Returns the home.
+     */
+    public String getHome()
+    {
+        return home;
+    }
+
+    /**
+     * @param home
+     *            The home to set.
+     */
+    public void setHome(String home)
+    {
+        this.home = home;
+    }
+
+}

Propchange: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/StartOrGetJackrabbitSingleton.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/StopJackrabbit.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/StopJackrabbit.java?rev=208988&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/StopJackrabbit.java
(added)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/StopJackrabbit.java
Sun Jul  3 15:00:10 2005
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.chain.command;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.apache.jackrabbit.chain.ContextHelper;
+import org.apache.jackrabbit.core.RepositoryImpl;
+
+/**
+ * Stops Jackrabbit  
+ */
+public class StopJackrabbit implements Command {
+
+	/* (non-Javadoc)
+	 * @see org.apache.commons.chain.Command#execute(org.apache.commons.chain.Context)
+	 */
+	public boolean execute(Context ctx) throws Exception {
+		RepositoryImpl repo = (RepositoryImpl) ContextHelper.getRepository(ctx) ;
+		repo.shutdown() ;
+		return false;
+	}
+}

Propchange: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/StopJackrabbit.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-commands/src/test/org/apache/jackrabbit/chain/test/JcrChainTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/test/org/apache/jackrabbit/chain/test/JcrChainTest.java?rev=208988&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/test/org/apache/jackrabbit/chain/test/JcrChainTest.java
(added)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/test/org/apache/jackrabbit/chain/test/JcrChainTest.java
Sun Jul  3 15:00:10 2005
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.chain.test;
+
+import javax.jcr.Repository;
+
+import org.apache.commons.chain.Context;
+import org.apache.commons.chain.impl.ContextBase;
+import org.apache.jackrabbit.chain.ContextHelper;
+import org.apache.jackrabbit.chain.command.AddNode;
+import org.apache.jackrabbit.chain.command.CurrentNode;
+import org.apache.jackrabbit.chain.command.Login;
+import org.apache.jackrabbit.chain.command.Logout;
+import org.apache.jackrabbit.chain.command.RemoveNode;
+import org.apache.jackrabbit.chain.command.Save;
+import org.apache.jackrabbit.chain.command.StopJackrabbit;
+import org.apache.jackrabbit.chain.command.StartOrGetJackrabbitSingleton;
+
+import junit.framework.TestCase;
+
+/**
+ * Chain testing
+ */
+public class JcrChainTest extends TestCase
+{
+    private static String CONFIG = "applications/test/repository.xml";
+
+    private static String HOME = "applications/test";
+
+    public void testChain() throws Exception
+    {
+        Context ctx = new ContextBase();
+
+        // Start
+        StartOrGetJackrabbitSingleton startCmd = new StartOrGetJackrabbitSingleton();
+        startCmd.setConfig(CONFIG);
+        startCmd.setHome(HOME);
+        startCmd.execute(ctx);
+        assertTrue(ContextHelper.getRepository(ctx) instanceof Repository);
+
+        // Login
+        Login loginCmd = new Login();
+        loginCmd.setUser("user");
+        loginCmd.setPassword("password");
+        loginCmd.execute(ctx);
+        assertTrue(ContextHelper.getSession(ctx) != null);
+        assertTrue(ContextHelper.getCurrentNode(ctx).getPath().equals("/"));
+
+        String testNodeStr = "test";
+
+        // Add node
+        AddNode addNodeCmd = new AddNode();
+        addNodeCmd.setName(testNodeStr);
+        addNodeCmd.execute(ctx);
+        assertTrue(ContextHelper.getCurrentNode(ctx).hasNode(testNodeStr));
+
+        // Current node
+        CurrentNode cnCmd = new CurrentNode();
+        cnCmd.setPath("/" + testNodeStr);
+        cnCmd.execute(ctx);
+        assertTrue(ContextHelper.getCurrentNode(ctx).getPath().equals(
+            "/" + testNodeStr));
+
+        // Save changes
+        Save saveCmd = new Save() ;
+        saveCmd.execute(ctx);
+        
+        // Logout
+        Logout logoutCmd = new Logout() ;
+        logoutCmd.execute(ctx);
+        
+        // See persisted changes
+        loginCmd = new Login();
+        loginCmd.setUser("user2");
+        loginCmd.setPassword("password");
+        loginCmd.execute(ctx);
+        assertTrue(ContextHelper.getCurrentNode(ctx).hasNode(testNodeStr));
+
+        // Change current node 
+        cnCmd.execute(ctx);
+        
+        // Remove node
+        RemoveNode removeNodeCmd = new RemoveNode();
+        removeNodeCmd.execute(ctx);
+        assertFalse(ContextHelper.getCurrentNode(ctx).hasNode(testNodeStr));
+        
+        logoutCmd = new Logout() ;
+        logoutCmd.execute(ctx);
+
+        // Stop
+        StopJackrabbit stopCmd = new StopJackrabbit();
+        stopCmd.execute(ctx);
+    }
+
+}

Propchange: incubator/jackrabbit/trunk/contrib/jcr-commands/src/test/org/apache/jackrabbit/chain/test/JcrChainTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message