jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edgarp...@apache.org
Subject svn commit: r231491 - in /incubator/jackrabbit/trunk/contrib/jcr-commands/jmeter-chain: ./ src/java/org/apache/jmeter/functions/ src/java/org/apache/jmeter/protocol/java/sampler/
Date Thu, 11 Aug 2005 17:51:41 GMT
Author: edgarpoce
Date: Thu Aug 11 10:51:16 2005
New Revision: 231491

URL: http://svn.apache.org/viewcvs?rev=231491&view=rev
Log:
- Modified. the jmeter thread context is passed to the commands as the Chain Context.
- Added. Jmeter Jexl Function.

Added:
    incubator/jackrabbit/trunk/contrib/jcr-commands/jmeter-chain/src/java/org/apache/jmeter/functions/
    incubator/jackrabbit/trunk/contrib/jcr-commands/jmeter-chain/src/java/org/apache/jmeter/functions/Jexl.java
  (with props)
    incubator/jackrabbit/trunk/contrib/jcr-commands/jmeter-chain/src/java/org/apache/jmeter/protocol/java/sampler/JMeterContextAdapter.java
  (with props)
Removed:
    incubator/jackrabbit/trunk/contrib/jcr-commands/jmeter-chain/NOTICE.txt
Modified:
    incubator/jackrabbit/trunk/contrib/jcr-commands/jmeter-chain/README.txt
    incubator/jackrabbit/trunk/contrib/jcr-commands/jmeter-chain/project.xml
    incubator/jackrabbit/trunk/contrib/jcr-commands/jmeter-chain/src/java/org/apache/jmeter/protocol/java/sampler/ChainSampler.java

Modified: incubator/jackrabbit/trunk/contrib/jcr-commands/jmeter-chain/README.txt
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/jmeter-chain/README.txt?rev=231491&r1=231490&r2=231491&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/jmeter-chain/README.txt (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/jmeter-chain/README.txt Thu Aug 11 10:51:16
2005
@@ -1,16 +1,21 @@
 Overview
 -----------------
-JMeter plugin for running Commons Chain commands.
-It includes the following classes:
- - org.apache.jmeter.protocol.java.config.gui.ChainConfigGui
- - org.apache.jmeter.protocol.java.control.gui.ChainTestSamplerGui
- - org.apache.jmeter.protocol.java.sampler.ChainSampler
- - org.apache.jmeter.protocol.java.test.SleepChainTest
+
+This project contains:
+
+1. JMeter plugin for running Commons Chain commands.
+2. JMeter function backed by Commons Jexl. See javadocs. 
 
 Dependencies not included in JMeter
 -----------------
+Add the following libraries to /lib
+
 - commons-chain 
 - commons-beanutils
+- commons-jexl
+- commons-collections. Jackrabbit uses a newer version of commons Collections.
+  Replace the jar included in JMeter with collections 3.1
+
  
 Installation
 -----------------

Modified: incubator/jackrabbit/trunk/contrib/jcr-commands/jmeter-chain/project.xml
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/jmeter-chain/project.xml?rev=231491&r1=231490&r2=231491&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/jmeter-chain/project.xml (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/jmeter-chain/project.xml Thu Aug 11 10:51:16
2005
@@ -68,6 +68,12 @@
       <type>jar</type>
       <url>http://avalon.apache.org</url>
     </dependency>
+    <dependency>
+      <groupId>commons-jexl</groupId>
+      <artifactId>commons-jexl</artifactId>
+      <version>1.0</version>
+      <type>jar</type>
+    </dependency>
   </dependencies>
   <build>
     <sourceDirectory>src/java</sourceDirectory>

Added: incubator/jackrabbit/trunk/contrib/jcr-commands/jmeter-chain/src/java/org/apache/jmeter/functions/Jexl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/jmeter-chain/src/java/org/apache/jmeter/functions/Jexl.java?rev=231491&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/jmeter-chain/src/java/org/apache/jmeter/functions/Jexl.java
(added)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/jmeter-chain/src/java/org/apache/jmeter/functions/Jexl.java
Thu Aug 11 10:51:16 2005
@@ -0,0 +1,118 @@
+/*
+ * 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.jmeter.functions;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.commons.jexl.Expression;
+import org.apache.commons.jexl.ExpressionFactory;
+import org.apache.commons.jexl.JexlContext;
+import org.apache.commons.jexl.JexlHelper;
+import org.apache.jmeter.engine.util.CompoundVariable;
+import org.apache.jmeter.samplers.SampleResult;
+import org.apache.jmeter.samplers.Sampler;
+import org.apache.jorphan.logging.LoggingManager;
+import org.apache.log.Logger;
+
+/**
+ * A function which understands Commons JEXL. <br>
+ * 
+ * The following variables are set before the script is executed: <br>
+ * <ul>
+ * <li>ctx - the current JMeter context variable</li>
+ * <li>vars - the current JMeter variables</li>
+ * <li>threadName - the threadName</li>
+ * <li>sampler - the current Sampler, if any</li>
+ * <li>sampleResult - the current SampleResult, if any</li>
+ * </ul>
+ */
+public class Jexl extends AbstractFunction implements Serializable
+{
+    /**
+     * <code>serialVersionUID</code>
+     */
+    private static final long serialVersionUID = 3546359539474968625L;
+
+    private static Logger log = LoggingManager.getLoggerForClass();
+
+    private static final String KEY = "__jexl";
+
+    private static final List desc = new LinkedList();
+
+    static
+    {
+        desc.add("expression");
+    }
+
+    private Object[] values;
+
+    public String execute(SampleResult result, Sampler sampler)
+            throws InvalidVariableException
+    {
+        String str = "";
+
+        CompoundVariable var = (CompoundVariable) values[0];
+        String exp = var.getRawParameters();
+
+        try
+        {
+            Expression e = ExpressionFactory.createExpression(exp);
+            JexlContext jc = JexlHelper.createContext();
+            jc.getVars().put("ctx", sampler.getThreadContext());
+            jc.getVars().put("vars", getVariables());
+            jc.getVars().put("threadName", sampler.getThreadName());
+            jc.getVars().put("sampler", sampler);
+            jc.getVars().put("sampleResult", result);
+
+            // Now evaluate the expression, getting the result
+            Object o = e.evaluate(jc);
+            if (o != null)
+            {
+                str = o.toString();
+            }
+        } catch (Exception e)
+        {
+            log.error("An error occurred while evaluating the expression \""
+                    + exp + "\"");
+        }
+        return str;
+    }
+
+    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 one parameter");
+        }
+    }
+
+}

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

Modified: incubator/jackrabbit/trunk/contrib/jcr-commands/jmeter-chain/src/java/org/apache/jmeter/protocol/java/sampler/ChainSampler.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/jmeter-chain/src/java/org/apache/jmeter/protocol/java/sampler/ChainSampler.java?rev=231491&r1=231490&r2=231491&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/jmeter-chain/src/java/org/apache/jmeter/protocol/java/sampler/ChainSampler.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/jmeter-chain/src/java/org/apache/jmeter/protocol/java/sampler/ChainSampler.java
Thu Aug 11 10:51:16 2005
@@ -24,7 +24,6 @@
 import org.apache.commons.beanutils.BeanUtils;
 import org.apache.commons.chain.Command;
 import org.apache.commons.chain.Context;
-import org.apache.commons.chain.impl.ContextBase;
 import org.apache.jmeter.config.Arguments;
 import org.apache.jmeter.engine.event.LoopIterationEvent;
 import org.apache.jmeter.samplers.AbstractSampler;
@@ -136,7 +135,7 @@
      * Performs a test sample.
      * 
      * The <code>sample()</code> method retrieves the reference to the command
-     * and calls its <code>runTest()</code> method.
+     * and calls its <code>execute()</code> method.
      * 
      * @param entry
      *            the Entry for this sample
@@ -151,13 +150,13 @@
             {
                 log.debug(whoAmI() + "Creating Command");
                 createCommand();
-            } 
-            
-            updateCommand() ;
-            results.setSampleLabel("Chain Test = "
-                    + command.getClass().getName());
+            }
+
+            updateCommand();
+            results.setSampleLabel(this.getName());
+            Context ctx = new JMeterContextAdapter(getThreadContext());
             results.sampleStart();
-            command.execute(getContext());
+            command.execute(ctx);
             results.sampleEnd();
             results.setSuccessful(true);
         } catch (Exception e)
@@ -168,18 +167,6 @@
         return results;
     }
 
-    private Context getContext()
-    {
-        Context ctx = (Context) getThreadContext().getVariables().getObject(
-            CHAINS_CONTEXT);
-        if (ctx == null)
-        {
-            ctx = new ContextBase();
-            getThreadContext().getVariables().putObject(CHAINS_CONTEXT, ctx);
-        }
-        return ctx;
-    }
-
     /**
      * Returns reference to <code>Command</code>.
      * 
@@ -200,12 +187,14 @@
 
         return command;
     }
-    
+
     /**
-     * Updates the command attributes 
+     * Updates the command attributes
+     * 
      * @throws Exception
      */
-    private void updateCommand() throws Exception {
+    private void updateCommand() throws Exception
+    {
         Map descrip = BeanUtils.describe(command);
         Iterator iter = descrip.keySet().iterator();
         while (iter.hasNext())
@@ -258,10 +247,10 @@
 
     /**
      * Method called at the end of the test. This is called only on one instance
-     * of ChainSampler. This method will loop through all of the other
-     * samplers which have been registered (automatically in the
-     * constructor) and notify them that the test has ended, allowing the
-     * ChainSamplerClients to cleanup.
+     * of ChainSampler. This method will loop through all of the other samplers
+     * which have been registered (automatically in the constructor) and notify
+     * them that the test has ended, allowing the ChainSamplerClients to
+     * cleanup.
      */
     public void testEnded()
     {
@@ -288,5 +277,4 @@
     public void testIterationStart(LoopIterationEvent event)
     {
     }
-
 }

Added: incubator/jackrabbit/trunk/contrib/jcr-commands/jmeter-chain/src/java/org/apache/jmeter/protocol/java/sampler/JMeterContextAdapter.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/jmeter-chain/src/java/org/apache/jmeter/protocol/java/sampler/JMeterContextAdapter.java?rev=231491&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/jmeter-chain/src/java/org/apache/jmeter/protocol/java/sampler/JMeterContextAdapter.java
(added)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/jmeter-chain/src/java/org/apache/jmeter/protocol/java/sampler/JMeterContextAdapter.java
Thu Aug 11 10:51:16 2005
@@ -0,0 +1,125 @@
+/*
+ * 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.jmeter.protocol.java.sampler;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.chain.Context;
+import org.apache.jmeter.threads.JMeterContext;
+
+/**
+ * <code>JMeterContext</code> to commons chain <code>Context</code>
adapter
+ */
+class JMeterContextAdapter implements Context
+{
+    private JMeterContext ctx;
+
+    /**
+     * private constructor
+     */
+    private JMeterContextAdapter()
+    {
+        super();
+    }
+
+    /**
+     * private constructor
+     */
+    public JMeterContextAdapter(JMeterContext ctx)
+    {
+        super();
+        this.ctx = ctx;
+    }
+
+    public void clear()
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    public boolean containsKey(Object key)
+    {
+        return get(key) != null;
+    }
+
+    public boolean containsValue(Object value)
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    public Set entrySet()
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    public Object get(Object key)
+    {
+        if (key == null || !(key instanceof String))
+        {
+            throw new IllegalArgumentException("Only String keys are supported");
+        }
+        return ctx.getVariables().getObject((String) key);
+    }
+
+    public boolean isEmpty()
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    public Set keySet()
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    public Object put(Object key, Object value)
+    {
+        if (key == null || !(key instanceof String))
+        {
+            throw new IllegalArgumentException("Only String keys are supported");
+        }
+        Object stale = ctx.getVariables().getObject((String) key);
+        ctx.getVariables().putObject((String) key, value);
+        return stale;
+    }
+
+    public void putAll(Map t)
+    {
+        ctx.getVariables().putAll(t);
+    }
+
+    public Object remove(Object key)
+    {
+        if (key == null || !(key instanceof String))
+        {
+            throw new IllegalArgumentException("Only String keys are supported");
+        }
+        Object stale = ctx.getVariables().getObject((String) key);
+        ctx.getVariables().remove((String) key);
+        return stale;
+    }
+
+    public int size()
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    public Collection values()
+    {
+        throw new UnsupportedOperationException();
+    }
+}

Propchange: incubator/jackrabbit/trunk/contrib/jcr-commands/jmeter-chain/src/java/org/apache/jmeter/protocol/java/sampler/JMeterContextAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message