Skip to content

Commit

Permalink
Add connect time to dummy sampler
Browse files Browse the repository at this point in the history
  • Loading branch information
undera committed Oct 7, 2015
1 parent dbe0cb1 commit 03b9d81
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 26 deletions.
1 change: 1 addition & 0 deletions site/dat/wiki/Changelog.wiki
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* bump up Selenium dependency to 2.47.0
* add basic PhantomJS (GhostDriver) capability to Remote WebDriver
* fix UTG broken by PR #80
* add Connect Time field to dummy sampler
== 1.3.0 <i><font color=gray size="1">June 30, 2015</font></i>==
* Java 7 or higher required
Expand Down
15 changes: 15 additions & 0 deletions standard/src/kg/apc/jmeter/samplers/DummySampler.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class DummySampler
public static final String REQUEST_DATA = "REQUEST_DATA";
public static final String RESPONSE_TIME = "RESPONSE_TIME";
public static final String LATENCY = "LATENCY";
public static final String CONNECT = "CONNECT";
public static final String IS_WAITING = "WAITING";

@Override
Expand Down Expand Up @@ -48,6 +49,7 @@ public SampleResult sample(Entry e) {
res.setResponseData(getResponseData().getBytes());

res.setLatency(getLatency());
res.setConnectTime(getConnectTime());

return res;
}
Expand Down Expand Up @@ -138,8 +140,21 @@ public void setLatency(String time) {
setProperty(LATENCY, time);
}

public void setConnectTime(String time) {
setProperty(CONNECT, time);
}

public boolean interrupt() {
Thread.currentThread().interrupt();
return true;
}

public int getConnectTime() {
int time = 0;
try {
time = Integer.valueOf(getPropertyAsString(CONNECT));
} catch (NumberFormatException ignored) {
}
return time;
}
}
50 changes: 24 additions & 26 deletions standard/src/kg/apc/jmeter/samplers/DummySamplerGui.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
// TODO: resolve scrolling issue here and in all other samplers
// TODO: resolve scrolling issue here and in all other samplers
package kg.apc.jmeter.samplers;

import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import kg.apc.jmeter.JMeterPluginsUtils;
import kg.apc.jmeter.gui.GuiBuilderHelper;
import org.apache.jmeter.samplers.gui.AbstractSamplerGui;
import org.apache.jmeter.testelement.TestElement;

import javax.swing.*;
import java.awt.*;

public class DummySamplerGui
extends AbstractSamplerGui {

Expand All @@ -27,10 +21,9 @@ public class DummySamplerGui
private JTextArea requestData;
private JCheckBox isWaiting;
private JTextField latency;
private JTextField connect;


/**
*
*/
public DummySamplerGui() {
init();
}
Expand All @@ -52,6 +45,7 @@ public void configure(TestElement element) {
responseData.setText(element.getPropertyAsString(DummySampler.RESPONSE_DATA));
responseTime.setText(element.getPropertyAsString(DummySampler.RESPONSE_TIME));
latency.setText(element.getPropertyAsString(DummySampler.LATENCY));
connect.setText(element.getPropertyAsString(DummySampler.CONNECT));
}

@Override
Expand All @@ -65,7 +59,7 @@ public TestElement createTestElement() {
/**
* Modifies a given TestElement to mirror the data in the gui components.
*
* @param sampler
* @param sampler Sampler
* @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
*/
@Override
Expand All @@ -82,6 +76,7 @@ public void modifyTestElement(TestElement sampler) {
dummySampler.setResponseData(responseData.getText());
dummySampler.setResponseTime(responseTime.getText());
dummySampler.setLatency(latency.getText());
dummySampler.setConnectTime(connect.getText());
}
}

Expand All @@ -98,8 +93,9 @@ private void initFields() {
responseMessage.setText("OK");
requestData.setText("Dummy Sampler used to simulate requests and responses\nwithout actual network activity. This helps debugging tests.");
responseData.setText("Dummy Sampler used to simulate requests and responses\nwithout actual network activity. This helps debugging tests.");
responseTime.setText("${__Random(100,1000)}");
latency.setText("${__Random(1,100)}");
responseTime.setText("${__Random(50,500)}");
latency.setText("${__Random(1,50)}");
connect.setText("${__Random(1,5)}");
}

@Override
Expand Down Expand Up @@ -133,26 +129,28 @@ private void init() {

addToPanel(mainPanel, labelConstraints, 0, 2, new JLabel("Response Message (eg OK): ", JLabel.RIGHT));
addToPanel(mainPanel, editConstraints, 1, 2, responseMessage = new JTextField(20));
addToPanel(mainPanel, labelConstraints, 0, 3, new JLabel("Latency (milliseconds): ", JLabel.RIGHT));
addToPanel(mainPanel, editConstraints, 1, 3, latency = new JTextField(20));
addToPanel(mainPanel, labelConstraints, 0, 4, new JLabel("Response Time (milliseconds): ", JLabel.RIGHT));
addToPanel(mainPanel, editConstraints, 1, 4, responseTime = new JTextField(20));
addToPanel(mainPanel, labelConstraints, 0, 5, new JLabel("Simulate Response Time (sleep): ", JLabel.RIGHT));
addToPanel(mainPanel, editConstraints, 1, 5, isWaiting = new JCheckBox());
addToPanel(mainPanel, labelConstraints, 0, 3, new JLabel("Connect Time (milliseconds): ", JLabel.RIGHT));
addToPanel(mainPanel, editConstraints, 1, 3, connect = new JTextField(20));
addToPanel(mainPanel, labelConstraints, 0, 4, new JLabel("Latency (milliseconds): ", JLabel.RIGHT));
addToPanel(mainPanel, editConstraints, 1, 4, latency = new JTextField(20));
addToPanel(mainPanel, labelConstraints, 0, 5, new JLabel("Response Time (milliseconds): ", JLabel.RIGHT));
addToPanel(mainPanel, editConstraints, 1, 5, responseTime = new JTextField(20));
addToPanel(mainPanel, labelConstraints, 0, 6, new JLabel("Simulate Response Time (sleep): ", JLabel.RIGHT));
addToPanel(mainPanel, editConstraints, 1, 6, isWaiting = new JCheckBox());

editConstraints.insets = new java.awt.Insets(4, 0, 0, 0);
labelConstraints.insets = new java.awt.Insets(4, 0, 0, 0);

addToPanel(mainPanel, labelConstraints, 0, 6, new JLabel("Request Data: ", JLabel.RIGHT));
addToPanel(mainPanel, labelConstraints, 0, 7, new JLabel("Request Data: ", JLabel.RIGHT));
editConstraints.fill = GridBagConstraints.BOTH;
requestData = new JTextArea();
addToPanel(mainPanel, editConstraints, 1, 6, GuiBuilderHelper.getTextAreaScrollPaneContainer(requestData, 10));
addToPanel(mainPanel, editConstraints, 1, 7, GuiBuilderHelper.getTextAreaScrollPaneContainer(requestData, 10));

addToPanel(mainPanel, labelConstraints, 0, 7, new JLabel("Response Data: ", JLabel.RIGHT));
addToPanel(mainPanel, labelConstraints, 0, 8, new JLabel("Response Data: ", JLabel.RIGHT));
editConstraints.fill = GridBagConstraints.BOTH;

responseData = new JTextArea();
addToPanel(mainPanel, editConstraints, 1, 7, GuiBuilderHelper.getTextAreaScrollPaneContainer(responseData, 10));
addToPanel(mainPanel, editConstraints, 1, 8, GuiBuilderHelper.getTextAreaScrollPaneContainer(responseData, 10));

JPanel container = new JPanel(new BorderLayout());
container.add(mainPanel, BorderLayout.NORTH);
Expand Down

0 comments on commit 03b9d81

Please sign in to comment.