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 ms...@apache.org on 2003/06/06 16:44:02 UTC
cvs commit: jakarta-jmeter/src/core/org/apache/jmeter/threads/gui ThreadGroupGui.java
mstover1 2003/06/06 07:44:02
Modified: src/core/org/apache/jmeter/engine StandardJMeterEngine.java
src/core/org/apache/jmeter/threads JMeterThread.java
ThreadGroup.java
src/core/org/apache/jmeter/threads/gui ThreadGroupGui.java
Log:
New scheduling capability for running tests
Revision Changes Path
1.24 +25 -4 jakarta-jmeter/src/core/org/apache/jmeter/engine/StandardJMeterEngine.java
Index: StandardJMeterEngine.java
===================================================================
RCS file: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/engine/StandardJMeterEngine.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- StandardJMeterEngine.java 14 May 2003 12:49:42 -0000 1.23
+++ StandardJMeterEngine.java 6 Jun 2003 14:44:01 -0000 1.24
@@ -95,6 +95,7 @@
Map allThreads;
boolean running = false;
boolean serialized = false;
+ boolean schcdule_run = false;
HashTree test;
SearchByClass testListeners;
String host = null;
@@ -233,7 +234,7 @@
public synchronized void threadFinished(JMeterThread thread)
{
allThreads.remove(thread);
- if (!serialized && allThreads.size() == 0)
+ if (!serialized && allThreads.size() == 0 && !schcdule_run )
{
stopTest();
}
@@ -297,6 +298,8 @@
notifyTestListenersOfStart();
}
notifier = new ListenerNotifier();
+ schcdule_run = true;
+
while (iter.hasNext())
{
ThreadGroup group = (ThreadGroup) iter.next();
@@ -310,6 +313,9 @@
threads[i].setInitialContext(JMeterContextService.getContext());
threads[i].setInitialDelay((int) (((float) (group.getRampUp() * 1000) / (float) group.getNumThreads()) * (float) i));
threads[i].setThreadName(group.getName() + "-" + (i + 1));
+
+ scheduleThread(threads[i], group);
+
Thread newThread = new Thread(threads[i]);
newThread.setName(group.getName() + "-" + (i + 1));
allThreads.put(threads[i], newThread);
@@ -319,6 +325,7 @@
}
newThread.start();
}
+ schcdule_run = false;
if (serialized)
{
while (running && allThreads.size() > 0)
@@ -331,6 +338,20 @@
{}
}
}
+ }
+ }
+
+ /**
+ * This will schedule the time for the JMeterThread
+ * @param thread
+ * @param group
+ */
+ private void scheduleThread(JMeterThread thread, ThreadGroup group)
+ {
+ if (group.getScheduler()) { //if true the Scheduler is enabled
+ thread.setStartTime(group.getStartTime());//set the starttime for the Thread
+ thread.setEndTime(group.getEndTime()); //set the endtime for the Thread
+ thread.setScheduled(true); //Enables the scheduler
}
}
1.30 +110 -2 jakarta-jmeter/src/core/org/apache/jmeter/threads/JMeterThread.java
Index: JMeterThread.java
===================================================================
RCS file: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/threads/JMeterThread.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- JMeterThread.java 29 May 2003 13:33:57 -0000 1.29
+++ JMeterThread.java 6 Jun 2003 14:44:01 -0000 1.30
@@ -100,6 +100,10 @@
Collection testListeners;
ListenerNotifier notifier;
int threadNum = 0;
+ long startTime = 0;
+ long endTime = 0;
+ private boolean scheduler = false;
+ //based on this scheduler is enabled or disabled
/****************************************
* !ToDo (Constructor description)
@@ -124,6 +128,99 @@
threadVars.putAll(context.getVariables());
}
+
+ /*************************************
+ * Checks whether the JMeterThread is Scheduled
+ * @Author T.Elanjchezhiyan(chezhiyan@siptech.co.in)
+ *************************************/
+ public boolean isScheduled() {
+ return this.scheduler;
+ }
+
+ /*************************************
+ *Enable the scheduler for this JMeterThread
+ *groups from the JMeterThreads.
+ * @Author T.Elanjchezhiyan(chezhiyan@siptech.co.in)
+ *************************************/
+ public void setScheduled(boolean sche) {
+ this.scheduler = sche;
+ }
+
+
+ /**
+ * Set the StartTime for this Thread.
+ *
+ * @param StartTime the StartTime value.
+ * @Author T.Elanjchezhiyan(chezhiyan@siptech.co.in)
+ */
+ public void setStartTime(long stime)
+ {
+ startTime = stime;
+ }
+
+ /**
+ * Get the start time value.
+ *
+ * @return the start time value.
+ * @Author T.Elanjchezhiyan(chezhiyan@siptech.co.in)
+ */
+ public long getStartTime()
+ {
+ return startTime;
+ }
+
+ /**
+ * Set the EndTime for this Thread.
+ *
+ * @param EndTime the EndTime value.
+ * @Author T.Elanjchezhiyan(chezhiyan@siptech.co.in)
+ */
+ public void setEndTime(long etime)
+ {
+ endTime = etime;
+ }
+ /**
+ * Get the end time value.
+ *
+ * @return the end time value.
+ * @Author T.Elanjchezhiyan(chezhiyan@siptech.co.in)
+ */
+ public long getEndTime()
+ {
+ return endTime;
+ }
+
+
+ /**
+ * Check the scheduled time is completed.
+ *
+ * @Author T.Elanjchezhiyan(chezhiyan@siptech.co.in)
+ */
+ public void stopScheduler() {
+ long delay = System.currentTimeMillis() - endTime;
+ if ((delay >= 0 )) {
+ running = false;
+ }
+ }
+
+ /**
+ * Start the scheduler with the specified time
+ *
+ * @Author T.Elanjchezhiyan(chezhiyan@siptech.co.in)
+ */
+ public void startScheduler() {
+ long delay =(startTime - System.currentTimeMillis());
+ if(delay > 0) {
+ try {
+ running = true;
+ Thread.sleep(delay);
+ }catch(Exception e){}
+ }else {
+ running = false;
+ }
+
+ }
+
public void setThreadName(String threadName)
{
this.threadName = threadName;
@@ -143,6 +240,12 @@
//listeners = controller.getListeners();
Sampler entry = null;
rampUpDelay();
+
+ if (scheduler) {
+ //set the scheduler to start
+ startScheduler();
+ }
+
log.info("Thread " + Thread.currentThread().getName() + " started");
controller.initialize();
controller.addIterationListener(new IterationListener());
@@ -165,6 +268,11 @@
checkAssertions(pack.getAssertions(), result);
notifyListeners(pack.getSampleListeners(), result);
compiler.done(pack);
+ if (scheduler) {
+ //checks the scheduler to stop the iteration
+ stopScheduler();
+ }
+
}
catch (Exception e)
{
1.13 +71 -2 jakarta-jmeter/src/core/org/apache/jmeter/threads/ThreadGroup.java
Index: ThreadGroup.java
===================================================================
RCS file: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/threads/ThreadGroup.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- ThreadGroup.java 8 May 2003 21:14:10 -0000 1.12
+++ ThreadGroup.java 6 Jun 2003 14:44:01 -0000 1.13
@@ -71,6 +71,8 @@
import org.apache.jmeter.testelement.AbstractTestElement;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.testelement.property.IntegerProperty;
+import org.apache.jmeter.testelement.property.LongProperty;
+import org.apache.jmeter.testelement.property.BooleanProperty;
import org.apache.jmeter.testelement.property.TestElementProperty;
import org.apache.log.Hierarchy;
import org.apache.log.Logger;
@@ -92,6 +94,11 @@
public final static String RAMP_TIME = "ThreadGroup.ramp_time";
public final static String MAIN_CONTROLLER = "ThreadGroup.main_controller";
+ public final static String SCHEDULER = "ThreadGroup.scheduler";
+ public final static String START_TIME= "ThreadGroup.start_time";
+ public final static String END_TIME= "ThreadGroup.end_time";
+
+
private final int DEFAULT_NUM_THREADS = 1;
private final int DEFAULT_RAMP_UP = 0;
private SampleQueue queue = null;
@@ -124,6 +131,68 @@
public Sampler next()
{
return getSamplerController().next();
+ }
+
+
+
+ /**
+ * Set the Scheduler value.
+ *
+ * @param Scheduler the Scheduler value.
+ */
+ public void setScheduler(boolean Scheduler)
+ {
+ setProperty(new BooleanProperty(SCHEDULER,Scheduler));
+ }
+
+ /**
+ * Get the Scheduler value.
+ *
+ * @return the Scheduler value.
+ */
+ public boolean getScheduler()
+ {
+ return getPropertyAsBoolean(SCHEDULER);
+ }
+
+ /**
+ * Set the StartTime value.
+ *
+ * @param StartTime the StartTime value.
+ */
+ public void setStartTime(long stime)
+ {
+ setProperty(new LongProperty(START_TIME,stime));
+ }
+
+ /**
+ * Get the start time value.
+ *
+ * @return the start time value.
+ */
+ public long getStartTime()
+ {
+ return getPropertyAsLong(START_TIME);
+ }
+
+ /**
+ * Set the EndTime value.
+ *
+ * @param EndTime the EndTime value.
+ */
+ public void setEndTime(long etime)
+ {
+ setProperty(new LongProperty(END_TIME, etime));
+ }
+
+ /**
+ * Get the end time value.
+ *
+ * @return the end time value.
+ */
+ public long getEndTime()
+ {
+ return getPropertyAsLong(END_TIME);
}
/**
1.15 +114 -5 jakarta-jmeter/src/core/org/apache/jmeter/threads/gui/ThreadGroupGui.java
Index: ThreadGroupGui.java
===================================================================
RCS file: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/threads/gui/ThreadGroupGui.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- ThreadGroupGui.java 8 May 2003 22:04:15 -0000 1.14
+++ ThreadGroupGui.java 6 Jun 2003 14:44:01 -0000 1.15
@@ -63,6 +63,16 @@
import javax.swing.JPopupMenu;
import javax.swing.JTextField;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+
+import java.util.Calendar;
+import java.util.Date;
+import javax.swing.JCheckBox;
+import javax.swing.JSpinner.DateEditor;
+import javax.swing.JSpinner;
+import javax.swing.SpinnerDateModel;
+
import org.apache.jmeter.control.LoopController;
import org.apache.jmeter.control.gui.LoopControlPanel;
import org.apache.jmeter.gui.AbstractJMeterGuiComponent;
@@ -72,6 +82,8 @@
import org.apache.jmeter.gui.util.VerticalPanel;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.threads.ThreadGroup;
+import org.apache.jmeter.testelement.property.BooleanProperty;
+import org.apache.jmeter.testelement.property.LongProperty;
import org.apache.jmeter.util.JMeterUtils;
/****************************************
@@ -82,9 +94,11 @@
*@version 1.0
***************************************/
-public class ThreadGroupGui extends AbstractJMeterGuiComponent
+public class ThreadGroupGui extends AbstractJMeterGuiComponent implements ItemListener
{
LoopControlPanel loopPanel;
+ private VerticalPanel mainPanel;
+
private final static String THREAD_NAME = "Thread Field";
private final static String RAMP_NAME = "Ramp Up Field";
@@ -92,6 +106,16 @@
private JTextField threadInput;
private JTextField rampInput;
+ private final static String SCHEDULER = "scheduler";
+ private final static String START_TIME= "start_time";
+ private final static String END_TIME= "end_time";
+
+ private DateEditor starttime;
+ private DateEditor endtime;
+ private JSpinner start;
+ private JSpinner end;
+ private JCheckBox scheduler;
+
/****************************************
* !ToDo (Constructor description)
***************************************/
@@ -136,6 +160,9 @@
}
tg.setProperty(ThreadGroup.NUM_THREADS, threadInput.getText());
tg.setProperty(ThreadGroup.RAMP_TIME, rampInput.getText());
+ tg.setProperty(new LongProperty(ThreadGroup.START_TIME,((Date)start.getValue()).getTime()));
+ tg.setProperty(new LongProperty(ThreadGroup.END_TIME,((Date)end.getValue()).getTime()));
+ tg.setProperty(new BooleanProperty(ThreadGroup.SCHEDULER,scheduler.isSelected()));
}
/****************************************
@@ -149,6 +176,24 @@
threadInput.setText(tg.getPropertyAsString(ThreadGroup.NUM_THREADS));
rampInput.setText(tg.getPropertyAsString(ThreadGroup.RAMP_TIME));
loopPanel.configure((TestElement) tg.getProperty(ThreadGroup.MAIN_CONTROLLER).getObjectValue());
+ scheduler.setSelected(tg.getPropertyAsBoolean(ThreadGroup.SCHEDULER));
+ if (scheduler.isSelected()) {
+ mainPanel.setVisible(true);
+ }else {
+ mainPanel.setVisible(false);
+ }
+ start.setValue(new Date(tg.getPropertyAsLong(ThreadGroup.START_TIME)));
+ end.setValue(new Date(tg.getPropertyAsLong(ThreadGroup.END_TIME)));
+ }
+
+ public void itemStateChanged(ItemEvent ie){
+ if (ie.getItem().equals(scheduler)){
+ if(scheduler.isSelected()) {
+ mainPanel.setVisible(true);
+ } else {
+ mainPanel.setVisible(false);
+ }
+ }
}
/****************************************
@@ -185,6 +230,54 @@
return loopPanel;
}
+
+ /**
+ * Create a panel containing the StartTime field and corresponding label.
+ *
+ * @return a GUI panel containing the StartTime field
+ */
+ private JPanel createStartTimePanel()
+ {
+ JPanel panel = new JPanel(new BorderLayout(5, 0));
+ JLabel label = new JLabel("starttime"); //JMeterUtils.getResString("starttime"));
+ label.setLabelFor(starttime);
+ panel.add(label, BorderLayout.WEST);
+
+ Date today = new Date();
+ // Start the spinner today, but don't set a min or max date
+ // The increment should be a month
+ start = new JSpinner(new SpinnerDateModel(today,
+ null, null, Calendar.MONTH));
+ starttime = new DateEditor(start, "dd/MM/yy HH:mm:ss");
+ start.setEditor(starttime);
+ panel.add(start, BorderLayout.CENTER);
+ return panel;
+ }
+
+ /**
+ * Create a panel containing the EndTime field and corresponding label.
+ *
+ * @return a GUI panel containing the EndTime field
+ */
+ private JPanel createEndTimePanel()
+ {
+ JPanel panel = new JPanel(new BorderLayout(5, 0));
+ JLabel label = new JLabel("endtime");//JMeterUtils.getResString("endtime"));
+ label.setLabelFor(endtime);
+ panel.add(label, BorderLayout.WEST);
+
+ Date today = new Date();
+ // Start the spinner today, but don't set a min or max date
+ // The increment should be a month
+ end = new JSpinner(new SpinnerDateModel(today,
+ null, null, Calendar.MONTH));
+ endtime = new DateEditor(end, "dd/MM/yy HH:mm:ss");
+ end.setEditor(endtime);
+
+ panel.add(end, BorderLayout.CENTER);
+ return panel;
+ }
+
/****************************************
* !ToDoo (Method description)
*
@@ -202,7 +295,7 @@
add(makeTitlePanel(), BorderLayout.NORTH);
- JPanel mainPanel = new JPanel(new BorderLayout());
+ //JPanel mainPanel = new JPanel(new BorderLayout());
// THREAD PROPERTIES
VerticalPanel threadPropsPanel = new VerticalPanel();
@@ -240,8 +333,24 @@
// LOOP COUNT
threadPropsPanel.add(createControllerPanel());
- mainPanel.add(threadPropsPanel, BorderLayout.NORTH);
- add(mainPanel, BorderLayout.CENTER);
+ // mainPanel.add(threadPropsPanel, BorderLayout.NORTH);
+ //add(mainPanel, BorderLayout.CENTER);
+
+ scheduler = new JCheckBox("Scheduler");
+ scheduler.addItemListener(this);
+ threadPropsPanel.add(scheduler);
+ mainPanel = new VerticalPanel();
+ mainPanel.setBorder(
+ BorderFactory.createTitledBorder(
+ BorderFactory.createEtchedBorder(),"Scheduler Cofiguration"));
+ mainPanel.add(createStartTimePanel());
+ mainPanel.add(createEndTimePanel());
+ mainPanel.setVisible(false);
+ VerticalPanel intgrationPanel = new VerticalPanel();
+ intgrationPanel.add(threadPropsPanel);
+ intgrationPanel.add(mainPanel);
+ add(intgrationPanel, BorderLayout.CENTER);
+
}
public void setNode(JMeterTreeNode node)
---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org