You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ed...@apache.org on 2005/07/18 01:18:48 UTC

svn commit: r219423 [3/3] - in /incubator/jackrabbit/trunk/contrib/jcr-commands: ./ applications/test/ benchmarking/ src/java/org/apache/jackrabbit/chain/ src/java/org/apache/jackrabbit/chain/command/ src/java/org/apache/jmeter/ src/java/org/apache/jme...

Added: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jmeter/functions/HasNode.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jmeter/functions/HasNode.java?rev=219423&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jmeter/functions/HasNode.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jmeter/functions/HasNode.java Sun Jul 17 16:18:40 2005
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * 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.jmeter.functions;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.jcr.RepositoryException;
+
+import org.apache.commons.chain.Context;
+import org.apache.jackrabbit.chain.ContextHelper;
+import org.apache.jmeter.engine.util.CompoundVariable;
+import org.apache.jmeter.protocol.java.sampler.ChainSampler;
+import org.apache.jmeter.samplers.SampleResult;
+import org.apache.jmeter.samplers.Sampler;
+import org.apache.jmeter.threads.JMeterContext;
+import org.apache.jmeter.threads.JMeterContextService;
+
+/**
+ * Returns true if a node exists at the given path
+ */
+public class HasNode extends AbstractFunction implements Serializable
+{
+    private static final String KEY = "__hasNode";
+
+    private static final List desc = new LinkedList();
+
+    static
+    {
+        desc.add("path");
+    }
+
+    private Object[] values;
+
+    /**
+     * Comment for <code>serialVersionUID</code>
+     */
+    private static final long serialVersionUID = 3256437010633013045L;
+
+    public String execute(SampleResult arg0, Sampler arg1)
+            throws InvalidVariableException
+    {
+        JMeterContext ctx = JMeterContextService.getContext();
+        Context chainCtx = (Context) ctx.getVariables().getObject(
+            ChainSampler.CHAINS_CONTEXT);
+        CompoundVariable var = (CompoundVariable) values[0] ; 
+        String path = var.getRawParameters();
+        try
+        {
+            return new Boolean(ContextHelper.hasNode(chainCtx, path))
+                .toString();
+        } catch (RepositoryException e)
+        {
+            throw new InvalidVariableException(e.getMessage());
+        }
+    }
+
+    public List getArgumentDesc()
+    {
+        return desc;
+    }
+
+    public String getReferenceKey()
+    {
+        return KEY;
+    }
+
+    public void setParameters(Collection parameters)
+            throws InvalidVariableException
+    {
+        values = parameters.toArray();
+        if (values.length != 1)
+        {
+            throw new InvalidVariableException("it only accepts on parameter");
+        }
+    }
+
+}

Propchange: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jmeter/functions/HasNode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jmeter/functions/NextNode.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jmeter/functions/NextNode.java?rev=219423&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jmeter/functions/NextNode.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jmeter/functions/NextNode.java Sun Jul 17 16:18:40 2005
@@ -0,0 +1,107 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * 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.jmeter.functions;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.apache.commons.chain.Context;
+import org.apache.jmeter.engine.util.CompoundVariable;
+import org.apache.jmeter.protocol.java.sampler.ChainSampler;
+import org.apache.jmeter.samplers.SampleResult;
+import org.apache.jmeter.samplers.Sampler;
+import org.apache.jmeter.threads.JMeterContext;
+import org.apache.jmeter.threads.JMeterContextService;
+import org.apache.jmeter.threads.JMeterVariables;
+
+/**
+ * delegates the call to the iterator stored 
+ * under the given target variable
+ */
+public class NextNode extends AbstractFunction implements Serializable
+{
+    /**
+     * Comment for <code>serialVersionUID</code>
+     */
+    private static final long serialVersionUID = 3834589898497012021L;
+
+    private static final String KEY = "__nextNode";
+
+    private static final List desc = new LinkedList();
+
+    static
+    {
+        desc.add("variable");
+    }
+
+    transient private Object[] values;
+
+    /**
+     * 
+     */
+    public NextNode()
+    {
+        super();
+    }
+
+    public String execute(SampleResult arg0, Sampler arg1)
+            throws InvalidVariableException
+    {
+        JMeterContext ctx = JMeterContextService.getContext();
+        JMeterVariables vars = ctx.getVariables();
+        Context chainCtx = (Context) vars.getObject(ChainSampler.CHAINS_CONTEXT);
+        CompoundVariable compVar = (CompoundVariable) values[0];
+        String var = compVar.execute();
+        Iterator iter = (Iterator) chainCtx.get(var);
+        Node node = (Node) iter.next();
+        try
+        {
+            return node.getPath();
+        } catch (RepositoryException e)
+        {
+            throw new InvalidVariableException("Unable to get next node. "
+                    + e.getMessage());
+        }
+    }
+
+    public List getArgumentDesc()
+    {
+        return desc;
+    }
+
+    public String getReferenceKey()
+    {
+        return KEY;
+    }
+
+    public void setParameters(Collection parameters)
+            throws InvalidVariableException
+    {
+        values = parameters.toArray();
+        if (values.length != 1)
+        {
+            throw new InvalidVariableException("it only accepts on parameter");
+        }
+    }
+
+}

Propchange: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jmeter/functions/NextNode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jmeter/functions/package.html
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jmeter/functions/package.html?rev=219423&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jmeter/functions/package.html (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jmeter/functions/package.html Sun Jul 17 16:18:40 2005
@@ -0,0 +1,4 @@
+<p>
+	This package contains jmeter functions that facilitate 
+	jcr benchmarking
+</p>
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jmeter/functions/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 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=219423&r1=219422&r2=219423&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/test/org/apache/jackrabbit/chain/test/JcrChainTest.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/test/org/apache/jackrabbit/chain/test/JcrChainTest.java Sun Jul 17 16:18:40 2005
@@ -16,49 +16,39 @@
  */
 package org.apache.jackrabbit.chain.test;
 
+import java.util.Iterator;
+
+import javax.jcr.Node;
 import javax.jcr.Repository;
 
+import junit.framework.TestCase;
+
 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.ClearWorkspace;
+import org.apache.jackrabbit.chain.command.CollectChildren;
 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.SaveSession;
 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 CONFIG = "/temp/repository/repository.xml";
+
+    private static String HOME = "/temp/repository";
 
-    private static String HOME = "applications/test";
+    Context ctx = new ContextBase();
 
     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";
 
@@ -76,7 +66,7 @@
             "/" + testNodeStr));
 
         // Save changes
-        Save saveCmd = new Save() ;
+        SaveSession saveCmd = new SaveSession() ;
         saveCmd.execute(ctx);
         
         // Logout
@@ -84,7 +74,7 @@
         logoutCmd.execute(ctx);
         
         // See persisted changes
-        loginCmd = new Login();
+        Login loginCmd = new Login();
         loginCmd.setUser("user2");
         loginCmd.setPassword("password");
         loginCmd.execute(ctx);
@@ -98,12 +88,67 @@
         removeNodeCmd.execute(ctx);
         assertFalse(ContextHelper.getCurrentNode(ctx).hasNode(testNodeStr));
         
-        logoutCmd = new Logout() ;
-        logoutCmd.execute(ctx);
-
-        // Stop
-        StopJackrabbit stopCmd = new StopJackrabbit();
-        stopCmd.execute(ctx);
+        saveCmd.execute(ctx);
     }
 
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+        // 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("/"));
+        
+    }
+    
+    protected void tearDown() throws Exception
+    {
+        super.tearDown();
+        ClearWorkspace cw = new ClearWorkspace() ;
+        cw.execute(ctx) ;
+        
+        // Logout
+        Logout logoutCmd = new Logout() ;
+        logoutCmd.execute(ctx);
+        
+    }
+    
+    public void testTraverse() throws Exception
+    {
+        String target = "iterator" ;
+        
+        CollectChildren traverse = new CollectChildren() ;
+        traverse.setDepth(-1) ;
+        traverse.setTarget(target);
+        traverse.execute(ctx) ;
+        
+        Iterator iter = (Iterator) ctx.get(target) ;
+        while(iter.hasNext()) {
+            Node node = (Node) iter.next() ;
+            System.out.println(node.getPath()) ;
+        }
+        System.out.println("------------------ ") ;
+        traverse = new CollectChildren() ;
+        traverse.setDepth(2) ;
+        traverse.setTarget(target);
+        traverse.execute(ctx) ;
+        
+        iter = (Iterator) ctx.get(target) ;
+        while(iter.hasNext()) {
+            Node node = (Node) iter.next() ;
+            System.out.println(node.getPath()) ;
+        }
+        
+    }
+    
 }