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/05/22 02:05:00 UTC

svn commit: r408534 - /jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/sampler/TestAction.java

Author: sebb
Date: Sun May 21 17:05:00 2006
New Revision: 408534

URL: http://svn.apache.org/viewvc?rev=408534&view=rev
Log:
Rework to make pause independent of the target - how (and does it make sense) to pause other threads?

Modified:
    jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/sampler/TestAction.java

Modified: jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/sampler/TestAction.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/sampler/TestAction.java?rev=408534&r1=408533&r2=408534&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/sampler/TestAction.java (original)
+++ jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/sampler/TestAction.java Sun May 21 17:05:00 2006
@@ -22,7 +22,6 @@
 import org.apache.jmeter.testelement.property.IntegerProperty;
 import org.apache.jmeter.threads.JMeterContext;
 import org.apache.jmeter.threads.JMeterContextService;
-import org.apache.jmeter.threads.JMeterThread;
 
 /**
  * Dummy Sampler used to pause or stop a thread or the test;
@@ -32,21 +31,17 @@
 public class TestAction extends AbstractSampler {
 	// Actions
 	public final static int STOP = 0;
-
 	public final static int PAUSE = 1;
 
-	// Action target
+	// Action targets
 	public final static int THREAD = 0;
-
 	// public final static int THREAD_GROUP = 1;
 	public final static int TEST = 2;
 
 	// Identifiers
-	private final static String TARGET = "ActionProcessor.target";
-
-	private final static String ACTION = "ActionProcessor.action";
-
-	private final static String DURATION = "ActionProcessor.duration";
+	private final static String TARGET = "ActionProcessor.target"; //$NON-NLS-1$
+	private final static String ACTION = "ActionProcessor.action"; //$NON-NLS-1$
+	private final static String DURATION = "ActionProcessor.duration"; //$NON-NLS-1$
 
 	public TestAction() {
 		super();
@@ -61,59 +56,35 @@
 	 * @see org.apache.jmeter.samplers.Sampler#sample(org.apache.jmeter.samplers.Entry)
 	 */
 	public SampleResult sample(Entry e) {
-		// SampleResult res = new SampleResult();
 		JMeterContext context = JMeterContextService.getContext();
-		// StringBuffer response = new StringBuffer();
-		//				
-		// res.setSampleLabel(getTitle());
-		// res.setSuccessful(true);
-		// res.setResponseMessage("OK");
-		// res.sampleStart();
 
 		int target = getTarget();
 		int action = getAction();
-		if (target == THREAD) {
-			JMeterThread thread = context.getThread();
-			if (action == PAUSE) {
-				// res.setSamplerData("Pause Thread "+thread.getThreadNum());
-				thread.pauseThread(getDuration());
-				// response.append("Thread ");
-				// response.append(thread.getThreadNum());
-				// response.append(" paused for ");
-				// response.append(getDuration());
-				// response.append(" miliseconds");
-			} else if (action == STOP) {
-				// res.setSamplerData("Stop Thread"+thread.getThreadNum());
-				context.getThread().stop();
-				// response.append("Thread ");
-				// response.append(thread.getThreadNum());
-				// response.append(" stopped");
-			}
-		}
-		// Not yet implemented
-		// else if (target==THREAD_GROUP)
-		// {
-		// if (action==PAUSE)
-		// {
-		// }
-		// else if (action==STOP)
-		// {
-		// }
-		// }
-		else if (target == TEST) {
-			if (action == PAUSE) {
-				context.getEngine().pauseTest(getDuration());
-			} else if (action == STOP) {
-				context.getEngine().askThreadsToStop();
-			}
-		}
-
-		// res.setResponseData(response.toString().getBytes());
-		// res.sampleEnd();
-		// return res;
+        if (action == PAUSE) {
+            pause(getDuration());
+        } else if (action == STOP) {
+    		if (target == THREAD) {
+                context.getThread().stop();
+    		}
+    		// Not yet implemented
+    		// else if (target==THREAD_GROUP)
+    		// {
+    		// }
+    		else if (target == TEST) {
+   				context.getEngine().askThreadsToStop();
+    		}
+        }
+
 		return null; // This means no sample is saved
 	}
 
+    private void pause(int milis) {
+        try {
+            Thread.sleep(milis);
+        } catch (InterruptedException e) {
+        }
+    }
+
 	public void setTarget(int target) {
 		setProperty(new IntegerProperty(TARGET, target));
 	}
@@ -137,4 +108,4 @@
 	public int getDuration() {
 		return getPropertyAsInt(DURATION);
 	}
-}
+}
\ No newline at end of file



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