Java Code Examples for org.apache.jmeter.samplers.SampleResult#setResponseData()
The following examples show how to use
org.apache.jmeter.samplers.SampleResult#setResponseData() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JSONPathAssertionTest.java From jmeter-plugins with Apache License 2.0 | 6 votes |
@Test public void testGetResult_positive_invert() { System.out.println("getResult simple"); SampleResult samplerResult = new SampleResult(); samplerResult.setResponseData("{\"myval\": 123}".getBytes()); JSONPathAssertion instance = new JSONPathAssertion(); instance.setJsonPath("$.myval"); instance.setJsonValidationBool(true); instance.setExpectedValue("123"); instance.setInvert(true); AssertionResult expResult = new AssertionResult(""); AssertionResult result = instance.getResult(samplerResult); assertTrue(result.isFailure()); assertEquals(expResult.getName(), result.getName()); }
Example 2
Source File: SubSampler.java From mqtt-jmeter with Apache License 2.0 | 6 votes |
private SampleResult fillFailedResult(SampleResult result, String code, String message) { result.sampleStart(); result.setResponseCode(code); // 5xx means various failures result.setSuccessful(false); result.setResponseMessage(message); if (clientId != null) { result.setResponseData(MessageFormat.format("Client [{0}]: {1}", clientId, message).getBytes()); } else { result.setResponseData(message.getBytes()); } result.sampleEnd(); // avoid massive repeated "early stage" failures in a short period of time // which probably overloads JMeter CPU and distorts test metrics such as TPS, avg response time try { TimeUnit.MILLISECONDS.sleep(SUB_FAIL_PENALTY); } catch (InterruptedException e) { logger.log(Level.INFO, "Received exception when waiting for notification signal", e); } return result; }
Example 3
Source File: JSONPathExtractorTest.java From jmeter-plugins with Apache License 2.0 | 6 votes |
@Test public void testReported1_3() { System.out.println("process reported"); JMeterContext context = JMeterContextService.getContext(); SampleResult res = new SampleResult(); res.setResponseData(json2.getBytes()); context.setPreviousResult(res); JSONPathExtractor instance = new JSONPathExtractor(); instance.setVar("GroupID"); instance.setJsonPath("$.data.groups[?(@.name==Avtovaz)].id"); instance.setDefaultValue("NOTFOUND"); instance.process(); JMeterVariables vars = context.getVariables(); assertEquals("NOTFOUND", vars.get("GroupID")); }
Example 4
Source File: SendMessage.java From jmeter-bzm-plugins with Apache License 2.0 | 6 votes |
private SampleResult waitResponse(SampleResult res, String recipient) throws InterruptedException, SmackException { long time = 0; do { Iterator<Message> packets = responseMessages.iterator(); Thread.sleep(conn.getPacketReplyTimeout() / 100); // optimistic while (packets.hasNext()) { Packet packet = packets.next(); Message response = (Message) packet; if (XmppStringUtils.parseBareAddress(response.getFrom()).equals(recipient)) { packets.remove(); res.setResponseData(response.toXML().toString().getBytes()); if (response.getError() != null) { res.setSuccessful(false); res.setResponseCode("500"); res.setResponseMessage(response.getError().toString()); } return res; } } time += conn.getPacketReplyTimeout() / 10; Thread.sleep(conn.getPacketReplyTimeout() / 10); } while (time < conn.getPacketReplyTimeout()); throw new SmackException.NoResponseException(); }
Example 5
Source File: JSONPathExtractorTest.java From jmeter-plugins with Apache License 2.0 | 6 votes |
@Test public void testProcess_chinese() { JMeterContext context = JMeterContextService.getContext(); SampleResult res = new SampleResult(); String chinese = "{\"carBrandName\":\"大众\"}"; res.setResponseData(chinese.getBytes()); context.setPreviousResult(res); JSONPathExtractor instance = new JSONPathExtractor(); instance.setDefaultValue("DEFAULT"); instance.setVar("test"); instance.setJsonPath("$.carBrandName"); instance.process(); JMeterVariables vars = context.getVariables(); // freaking "static final" DEFAULT_ENCODING field in SampleResult does not allow us to assert this // assertEquals("大众", vars.get("test")); }
Example 6
Source File: HttpTestBean.java From BotServiceStressToolkit with MIT License | 6 votes |
@Override public SampleResult sample(Entry entry) { SampleResult res = new SampleResult(); res.setSampleLabel(getName()); res.sampleStart(); res.setDataType(SampleResult.TEXT); try { JMeterContext context = getThreadContext(); JMeterVariables vars = context.getVariables(); String body = Unirest.get("http://www.uol.com.br").asString().getBody(); res.setResponseData(body, null); res.sampleEnd(); res.setSuccessful(true); } catch (UnirestException e) { res.setResponseData(e.toString(), null); res.sampleEnd(); res.setSuccessful(false); } return res; }
Example 7
Source File: JSONPathExtractorTest.java From jmeter-plugins with Apache License 2.0 | 6 votes |
@Test public void testProcess() { System.out.println("process"); JMeterContext context = JMeterContextService.getContext(); SampleResult res = new SampleResult(); res.setResponseData(json.getBytes()); context.setPreviousResult(res); JSONPathExtractor instance = new JSONPathExtractor(); instance.setDefaultValue("DEFAULT"); instance.setVar("test"); instance.setJsonPath("$.store.book[*].author"); instance.process(); JMeterVariables vars = context.getVariables(); assertEquals("[\"Nigel Rees\",\"Evelyn Waugh\",\"Herman Melville\",\"J. R. R. Tolkien\"]", vars.get("test")); }
Example 8
Source File: JSONPathExtractorTest.java From jmeter-plugins with Apache License 2.0 | 6 votes |
@Test public void testProcess_from_var_2() { System.out.println("process fromvar"); JMeterContext context = JMeterContextService.getContext(); JMeterVariables vars = context.getVariables(); SampleResult res = new SampleResult(); res.setResponseData("".getBytes()); context.setPreviousResult(res); vars.put("SVAR", json); JSONPathExtractor instance = new JSONPathExtractor(); instance.setDefaultValue("DEFAULT"); instance.setVar("test"); instance.setJsonPath("$.store.bicycle"); instance.setSubject(JSONPathExtractor.SUBJECT_VARIABLE); instance.setSrcVariableName("SVAR"); instance.process(); String test = vars.get("test"); boolean thiis = "{\"color\":\"red\",\"price\":19.95}".equals(test); boolean thaat = "{\"price\":19.95,\"color\":\"red\"}".equals(test); assertTrue(thiis || thaat); }
Example 9
Source File: JSONPathAssertionTest.java From jmeter-plugins with Apache License 2.0 | 5 votes |
@Test public void testGetResult_list_val() { System.out.println("getResult list-val"); SampleResult samplerResult = new SampleResult(); samplerResult.setResponseData("{\"myval\": [{\"test\":1},{\"test\":2},{\"test\":3}]}".getBytes()); JSONPathAssertion instance = new JSONPathAssertion(); instance.setJsonPath("$.myval[*].test"); instance.setJsonValidationBool(true); instance.setExpectedValue("2"); AssertionResult expResult = new AssertionResult(""); AssertionResult result = instance.getResult(samplerResult); assertEquals(expResult.getName(), result.getName()); assertFalse(result.isFailure()); }
Example 10
Source File: NoOp.java From jmeter-bzm-plugins with Apache License 2.0 | 5 votes |
@Override public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception { long counter = 0; for (Packet packet : incomingPackets) { incomingPackets.remove(packet); SampleResult subRes = new SampleResult(); subRes.setSuccessful(true); subRes.setResponseCode("200"); subRes.setResponseMessage("OK"); subRes.setSampleLabel(packet.getClass().getSimpleName().isEmpty() ? packet.getClass().getName() : packet.getClass().getSimpleName()); subRes.setResponseData(packet.toXML().toString().getBytes()); if ((packet instanceof Presence) && (((Presence) packet).getType() == Presence.Type.error)) { subRes.setSuccessful(false); subRes.setResponseCode("500"); subRes.setResponseMessage(packet.getError().toString()); } else if ((packet instanceof Message) && (((Message) packet).getType() == Message.Type.error)) { subRes.setSuccessful(false); subRes.setResponseCode("500"); subRes.setResponseMessage(packet.getError().toString()); } else if ((packet instanceof IQ) && (((IQ) packet).getType() == IQ.Type.error)) { subRes.setSuccessful(false); subRes.setResponseCode("500"); subRes.setResponseMessage(packet.getError().toString()); } res.addSubResult(subRes); counter++; } res.setResponseData(("Received packets: " + counter).getBytes()); return counter > 0 ? res : null; }
Example 11
Source File: JSONPathAssertionTest.java From jmeter-plugins with Apache License 2.0 | 5 votes |
@Test public void testGetResult_dict() { System.out.println("getResult notexist"); SampleResult samplerResult = new SampleResult(); samplerResult.setResponseData("{\"myval\": {\"key\": \"val\"}}".getBytes()); JSONPathAssertion instance = new JSONPathAssertion(); instance.setJsonPath("$.myval"); instance.setJsonValidationBool(true); instance.setExpectedValue("{\"key\":\"val\"}"); AssertionResult expResult = new AssertionResult(""); AssertionResult result = instance.getResult(samplerResult); assertEquals(expResult.getName(), result.getName()); assertFalse(result.isFailure()); }
Example 12
Source File: JSONPathAssertionTest.java From jmeter-plugins with Apache License 2.0 | 5 votes |
@Test public void testGetResult_null() { System.out.println("getResult null"); SampleResult samplerResult = new SampleResult(); samplerResult.setResponseData("{\"myval\": null}".getBytes()); JSONPathAssertion instance = new JSONPathAssertion(); instance.setJsonPath("$.myval"); instance.setExpectNull(true); instance.setJsonValidationBool(true); AssertionResult expResult = new AssertionResult(""); AssertionResult result = instance.getResult(samplerResult); assertEquals(expResult.getName(), result.getName()); assertFalse(result.isFailure()); }
Example 13
Source File: JSONFormatterTest.java From jmeter-plugins with Apache License 2.0 | 5 votes |
@Test public void testProcess_string() { System.out.println("process str"); JSONFormatter instance = new JSONFormatter(); JMeterContext threadContext = JMeterContextService.getContext(); SampleResult res = new SampleResult(); res.setResponseData("\"str\"", "UTF8"); threadContext.setPreviousResult(res); instance.process(); }
Example 14
Source File: KafkaProducerSampler.java From kafkameter with Apache License 2.0 | 5 votes |
/** * Mark the sample result as {@code end}ed and {@code successful} with an "OK" {@code responseCode}, * and if the response is not {@code null} then set the {@code responseData} to {@code response}, * otherwise it is marked as not requiring a response. * * @param result sample result to change * @param response the successful result message, may be null. */ private void sampleResultSuccess(SampleResult result, /* @Nullable */ String response) { result.sampleEnd(); result.setSuccessful(true); result.setResponseCodeOK(); if (response != null) { result.setResponseData(response, ENCODING); } else { result.setResponseData("No response required", ENCODING); } }
Example 15
Source File: JSONPathAssertionTest.java From jmeter-plugins with Apache License 2.0 | 5 votes |
@Test public void testGetResult_list_empty_validate() { System.out.println("getResult list-empty"); SampleResult samplerResult = new SampleResult(); samplerResult.setResponseData("{\"myval\": []}".getBytes()); JSONPathAssertion instance = new JSONPathAssertion(); instance.setJsonPath("$.myval"); instance.setJsonValidationBool(true); instance.setExpectedValue("[]"); AssertionResult expResult = new AssertionResult(""); AssertionResult result = instance.getResult(samplerResult); assertEquals(expResult.getName(), result.getName()); assertFalse(result.isFailure()); }
Example 16
Source File: JSONFormatterTest.java From jmeter-plugins with Apache License 2.0 | 5 votes |
@Test public void testProcess_float() { System.out.println("process float"); JSONFormatter instance = new JSONFormatter(); JMeterContext threadContext = JMeterContextService.getContext(); SampleResult res = new SampleResult(); res.setResponseData("3.14", "UTF8"); threadContext.setPreviousResult(res); instance.process(); }
Example 17
Source File: JSONPathAssertionTest.java From jmeter-plugins with Apache License 2.0 | 5 votes |
@Test public void testGetResult_list_empty_novalidate() { System.out.println("getResult list-empty"); SampleResult samplerResult = new SampleResult(); samplerResult.setResponseData("{\"myval\": []}".getBytes()); JSONPathAssertion instance = new JSONPathAssertion(); instance.setJsonPath("$.myval[*]"); instance.setJsonValidationBool(false); AssertionResult expResult = new AssertionResult(""); AssertionResult result = instance.getResult(samplerResult); assertEquals(expResult.getName(), result.getName()); assertFalse(result.isFailure()); }
Example 18
Source File: CaseFormatTest.java From jmeter-plugins with Apache License 2.0 | 5 votes |
@Before public void setUp() { changeCase = new CaseFormat(); result = new SampleResult(); JMeterContext jmctx = JMeterContextService.getContext(); String data = "dummy data"; result.setResponseData(data, null); JMeterVariables vars = new JMeterVariables(); jmctx.setVariables(vars); jmctx.setPreviousResult(result); params = new LinkedList<>(); }
Example 19
Source File: JMeterXMPPSampler.java From jmeter-bzm-plugins with Apache License 2.0 | 4 votes |
@Override public SampleResult sample(Entry entry) { SampleResult res = new SampleResult(); res.setSampleLabel(getName()); res.setDataType(SampleResult.TEXT); res.setSuccessful(true); res.setResponseCode("200"); res.setResponseMessage("OK"); res.sampleStart(); try { if (connConfig == null) { throw new RuntimeException("Cannot sample XMPP without XMPP Connection component"); } XMPPConnection conn = getXMPPConnection(); if (conn == null) { throw new RuntimeException("No XMPP Connection available"); } String headers = "Connection ID: " + conn.getConnectionID() + "\r\n"; String action = getAction(); if (!conn.isConnected() && !action.equals(Connect.class.getCanonicalName())) { log.error("Please call Connect before calling other actions"); throw new SmackException.NotConnectedException(); } headers += "User: " + conn.getUser() + "\r\n"; res.setRequestHeaders(headers); AbstractXMPPAction actObject = connConfig.getActions().get(action); if (actObject.perform(this, res) == null) { return null; } } catch (Exception e) { log.error("Error in XMPP Sampler: ", e); res.setSuccessful(false); res.setResponseCode("500"); res.setResponseMessage((e.getMessage() == null || e.getMessage().isEmpty()) ? e.toString() : e.getMessage()); res.setResponseData(ExceptionUtils.getStackTrace(e).getBytes()); } res.sampleEnd(); return res; }
Example 20
Source File: SingleTopicHCSClient.java From hedera-mirror-node with Apache License 2.0 | 4 votes |
/** * Runs test by calling sampler subscribeTopic. Reports success based on call response from sampler */ @Override public SampleResult runTest(JavaSamplerContext context) { SampleResult result = new SampleResult(); HCSSamplerResult response = null; result.sampleStart(); try { MessageListener listener = MessageListener.builder() .historicMessagesCount(propHandler.getIntClientTestParam("HistoricMessagesCount", 0, "0")) .futureMessagesCount(propHandler.getIntClientTestParam("IncomingMessageCount", 0, "0")) .messagesLatchWaitSeconds(propHandler.getIntClientTestParam("SubscribeTimeoutSeconds", 0, "60")) .build(); response = hcsTopicSampler.subscribeTopic(listener); result.sampleEnd(); result.setResponseData(response.toString().getBytes()); result.setSuccessful(response.isSuccess()); if (!response.isSuccess()) { result.setResponseMessage("Failure in subscribe topic test"); result.setResponseCode("500"); } else { result.setResponseMessage("Successfully performed subscribe topic test"); result.setResponseCodeOK(); } } catch (Exception ex) { log.error("Error subscribing to topic", ex); StringWriter stringWriter = new StringWriter(); ex.printStackTrace(new PrintWriter(stringWriter)); result.sampleEnd(); result.setResponseMessage("Exception: " + ex); result.setResponseData(stringWriter.toString().getBytes()); result.setDataType(SampleResult.TEXT); result.setResponseCode("500"); } return result; }