You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by se...@apache.org on 2006/03/13 03:29:56 UTC

svn commit: r385413 - in /jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/timers: BeanShellTimer.java BeanShellTimerBeanInfo.java BeanShellTimerResources.properties

Author: sebb
Date: Sun Mar 12 18:29:54 2006
New Revision: 385413

URL: http://svn.apache.org/viewcvs?rev=385413&view=rev
Log:
Initial implementation of BeanShell Timer

Added:
    jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/timers/BeanShellTimer.java   (with props)
    jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/timers/BeanShellTimerBeanInfo.java   (with props)
    jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/timers/BeanShellTimerResources.properties   (with props)

Added: jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/timers/BeanShellTimer.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/timers/BeanShellTimer.java?rev=385413&view=auto
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/timers/BeanShellTimer.java (added)
+++ jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/timers/BeanShellTimer.java Sun Mar 12 18:29:54 2006
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2006 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.timers;
+
+import java.io.Serializable;
+
+import org.apache.jmeter.testbeans.TestBean;
+import org.apache.jmeter.testelement.AbstractTestElement;
+import org.apache.jmeter.threads.JMeterContext;
+import org.apache.jmeter.threads.JMeterContextService;
+import org.apache.jmeter.threads.JMeterVariables;
+import org.apache.jmeter.util.BeanShellInterpreter;
+import org.apache.jmeter.util.JMeterUtils;
+import org.apache.jorphan.logging.LoggingManager;
+import org.apache.jorphan.util.JMeterException;
+import org.apache.log.Logger;
+
+public class BeanShellTimer extends AbstractTestElement implements Timer, Serializable, TestBean {
+    private static final Logger log = LoggingManager.getLoggerForClass();
+    
+    private static final long serialVersionUID = 2;
+
+    private String script;
+    
+    transient private BeanShellInterpreter bshInterpreter = null;
+
+    // can be specified in jmeter.properties
+    private static final String INIT_FILE = "beanshell.timer.init"; //$NON-NLS-1$
+
+    public BeanShellTimer() throws ClassNotFoundException {
+        super();
+        bshInterpreter = new BeanShellInterpreter(JMeterUtils.getProperty(INIT_FILE),log);
+    }
+
+    /*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.jmeter.timers.Timer#delay()
+	 */
+	public long delay() {
+        String ret="";
+        try {
+            // Add variables for access to context and variables
+            JMeterContext jmctx = JMeterContextService.getContext();
+            JMeterVariables vars = jmctx.getVariables();
+            bshInterpreter.set("ctx", jmctx);//$NON-NLS-1$
+            bshInterpreter.set("vars", vars);//$NON-NLS-1$
+            ret = bshInterpreter.eval(script).toString();
+        } catch (JMeterException e) {
+            log.warn("Problem in BeanShell script "+e);
+        }
+		return Long.decode(ret).longValue();
+	}
+
+	public Object clone() {
+        BeanShellTimer o = (BeanShellTimer) super.clone();
+        o.script = script;
+		return o;
+	}
+    
+    public String getScript(){
+        return script;
+    }
+
+    public void setScript(String s){
+        script=s;
+    }
+}

Propchange: jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/timers/BeanShellTimer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/timers/BeanShellTimer.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision

Propchange: jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/timers/BeanShellTimer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/timers/BeanShellTimerBeanInfo.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/timers/BeanShellTimerBeanInfo.java?rev=385413&view=auto
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/timers/BeanShellTimerBeanInfo.java (added)
+++ jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/timers/BeanShellTimerBeanInfo.java Sun Mar 12 18:29:54 2006
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2006 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.timers;
+
+import java.beans.PropertyDescriptor;
+
+import org.apache.jmeter.testbeans.BeanInfoSupport;
+
+public class BeanShellTimerBeanInfo extends BeanInfoSupport {
+
+	/**
+	 * @param beanClass
+	 */
+	public BeanShellTimerBeanInfo() {
+		super(BeanShellTimer.class);
+
+        createPropertyGroup("scripting", new String[] { "script" });
+
+		PropertyDescriptor p = property("script");
+		p.setValue(NOT_UNDEFINED, Boolean.TRUE);
+		p.setValue(DEFAULT, "");
+	}
+
+}

Propchange: jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/timers/BeanShellTimerBeanInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/timers/BeanShellTimerBeanInfo.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision

Propchange: jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/timers/BeanShellTimerBeanInfo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/timers/BeanShellTimerResources.properties
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/timers/BeanShellTimerResources.properties?rev=385413&view=auto
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/timers/BeanShellTimerResources.properties (added)
+++ jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/timers/BeanShellTimerResources.properties Sun Mar 12 18:29:54 2006
@@ -0,0 +1,4 @@
+displayName=BeanShell Timer
+scripting.displayName=BeanShell
+script.displayName=Script
+script.shortDescription=Beanshell script to generate delay
\ No newline at end of file

Propchange: jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/timers/BeanShellTimerResources.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/timers/BeanShellTimerResources.properties
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision

Propchange: jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/timers/BeanShellTimerResources.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain



---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org