| 1 | |
package kg.apc.jmeter.samplers; |
| 2 | |
|
| 3 | |
import org.apache.jmeter.samplers.AbstractSampler; |
| 4 | |
import org.apache.jmeter.samplers.Entry; |
| 5 | |
import org.apache.jmeter.samplers.Interruptible; |
| 6 | |
import org.apache.jmeter.samplers.SampleResult; |
| 7 | |
|
| 8 | 23 | public class DummySampler |
| 9 | |
extends AbstractSampler implements Interruptible { |
| 10 | |
|
| 11 | |
public static final String IS_SUCCESSFUL = "SUCCESFULL"; |
| 12 | |
public static final String RESPONSE_CODE = "RESPONSE_CODE"; |
| 13 | |
public static final String RESPONSE_MESSAGE = "RESPONSE_MESSAGE"; |
| 14 | |
public static final String RESPONSE_DATA = "RESPONSE_DATA"; |
| 15 | |
public static final String REQUEST_DATA = "REQUEST_DATA"; |
| 16 | |
public static final String RESPONSE_TIME = "RESPONSE_TIME"; |
| 17 | |
public static final String LATENCY = "LATENCY"; |
| 18 | |
public static final String CONNECT = "CONNECT"; |
| 19 | |
public static final String IS_WAITING = "WAITING"; |
| 20 | |
|
| 21 | |
@Override |
| 22 | |
public SampleResult sample(Entry e) { |
| 23 | |
|
| 24 | |
SampleResult res; |
| 25 | 1 | if (isSimulateWaiting()) { |
| 26 | 0 | res = new SampleResult(); |
| 27 | 0 | res.sampleStart(); |
| 28 | |
try { |
| 29 | 0 | Thread.sleep(getResponseTime()); |
| 30 | 0 | } catch (InterruptedException ignored) { |
| 31 | 0 | } |
| 32 | 0 | res.sampleEnd(); |
| 33 | |
} else { |
| 34 | 1 | res = new SampleResult(System.currentTimeMillis(), getResponseTime()); |
| 35 | |
} |
| 36 | |
|
| 37 | 1 | res.setSampleLabel(getName()); |
| 38 | |
|
| 39 | |
|
| 40 | 1 | res.setSamplerData(getRequestData()); |
| 41 | |
|
| 42 | |
|
| 43 | 1 | res.setResponseCode(getResponseCode()); |
| 44 | 1 | res.setResponseMessage(getResponseMessage()); |
| 45 | 1 | res.setSuccessful(isSuccessfull()); |
| 46 | |
|
| 47 | |
|
| 48 | 1 | res.setDataType(SampleResult.TEXT); |
| 49 | 1 | res.setResponseData(getResponseData().getBytes()); |
| 50 | |
|
| 51 | 1 | res.setLatency(getLatency()); |
| 52 | 1 | res.setConnectTime(getConnectTime()); |
| 53 | |
|
| 54 | 1 | return res; |
| 55 | |
} |
| 56 | |
|
| 57 | |
public void setSuccessful(boolean selected) { |
| 58 | 3 | setProperty(IS_SUCCESSFUL, selected); |
| 59 | 3 | } |
| 60 | |
|
| 61 | |
public void setSimulateWaiting(boolean selected) { |
| 62 | 3 | setProperty(IS_WAITING, selected); |
| 63 | 3 | } |
| 64 | |
|
| 65 | |
public void setResponseCode(String text) { |
| 66 | 3 | setProperty(RESPONSE_CODE, text); |
| 67 | 3 | } |
| 68 | |
|
| 69 | |
public void setResponseMessage(String text) { |
| 70 | 3 | setProperty(RESPONSE_MESSAGE, text); |
| 71 | 3 | } |
| 72 | |
|
| 73 | |
public void setResponseData(String text) { |
| 74 | 4 | setProperty(RESPONSE_DATA, text); |
| 75 | 4 | } |
| 76 | |
|
| 77 | |
public void setRequestData(String text) { |
| 78 | 3 | setProperty(REQUEST_DATA, text); |
| 79 | 3 | } |
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
public boolean isSuccessfull() { |
| 85 | 2 | return getPropertyAsBoolean(IS_SUCCESSFUL); |
| 86 | |
} |
| 87 | |
|
| 88 | |
public boolean isSimulateWaiting() { |
| 89 | 2 | return getPropertyAsBoolean(IS_WAITING); |
| 90 | |
} |
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
public String getResponseCode() { |
| 96 | 2 | return getPropertyAsString(RESPONSE_CODE); |
| 97 | |
} |
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
public String getResponseMessage() { |
| 103 | 2 | return getPropertyAsString(RESPONSE_MESSAGE); |
| 104 | |
} |
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
public String getResponseData() { |
| 110 | 2 | return getPropertyAsString(RESPONSE_DATA); |
| 111 | |
} |
| 112 | |
|
| 113 | |
public String getRequestData() { |
| 114 | 2 | return getPropertyAsString(REQUEST_DATA); |
| 115 | |
} |
| 116 | |
|
| 117 | |
public int getResponseTime() { |
| 118 | 2 | int time = 0; |
| 119 | |
try { |
| 120 | 2 | time = Integer.valueOf(getPropertyAsString(RESPONSE_TIME)); |
| 121 | 2 | } catch (NumberFormatException ignored) { |
| 122 | 0 | } |
| 123 | 2 | return time; |
| 124 | |
} |
| 125 | |
|
| 126 | |
public int getLatency() { |
| 127 | 2 | int time = 0; |
| 128 | |
try { |
| 129 | 2 | time = Integer.valueOf(getPropertyAsString(LATENCY)); |
| 130 | 2 | } catch (NumberFormatException ignored) { |
| 131 | 0 | } |
| 132 | 2 | return time; |
| 133 | |
} |
| 134 | |
|
| 135 | |
public void setResponseTime(String time) { |
| 136 | 3 | setProperty(RESPONSE_TIME, time); |
| 137 | 3 | } |
| 138 | |
|
| 139 | |
public void setLatency(String time) { |
| 140 | 3 | setProperty(LATENCY, time); |
| 141 | 3 | } |
| 142 | |
|
| 143 | |
public void setConnectTime(String time) { |
| 144 | 2 | setProperty(CONNECT, time); |
| 145 | 2 | } |
| 146 | |
|
| 147 | |
public boolean interrupt() { |
| 148 | 1 | Thread.currentThread().interrupt(); |
| 149 | 1 | return true; |
| 150 | |
} |
| 151 | |
|
| 152 | |
public int getConnectTime() { |
| 153 | 1 | int time = 0; |
| 154 | |
try { |
| 155 | 1 | time = Integer.valueOf(getPropertyAsString(CONNECT)); |
| 156 | 1 | } catch (NumberFormatException ignored) { |
| 157 | 0 | } |
| 158 | 1 | return time; |
| 159 | |
} |
| 160 | |
} |