Java Code Examples for org.apache.jmeter.samplers.SampleResult#sampleStart()
The following examples show how to use
org.apache.jmeter.samplers.SampleResult#sampleStart() .
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: FlexibleFileWriterTest.java From jmeter-plugins with Apache License 2.0 | 7 votes |
@Test public void testSampleOccurred_phout() throws IOException { System.out.println("sampleOccurred_phout"); SampleResult res = new SampleResult(); res.sampleStart(); res.setResponseData("test".getBytes()); res.setResponseCode("200"); res.setLatency(4); res.setSuccessful(true); res.sampleEnd(); SampleEvent e = new SampleEvent(res, "Test"); FlexibleFileWriter instance = new FlexibleFileWriter(); instance.setFilename(File.createTempFile("ffw_test_", ".txt").getAbsolutePath()); instance.setColumns("endTimeMillis|\\t\\t|responseTimeMicros|\\t|latencyMicros|\\t|sentBytes|\\t|receivedBytes|\\t|isSuccsessful|\\t|responseCode|\\t|connectTime|\\r\\n"); instance.testStarted(); instance.sampleOccurred(e); //String written = JMeterPluginsUtils.byteBufferToString(instance.fileEmul.getWrittenBytes()); //System.out.println(written); //assertEquals(8, written.split("\t").length); instance.testEnded(); }
Example 2
Source File: FlexibleFileWriterTest.java From jmeter-plugins with Apache License 2.0 | 6 votes |
@Test public void testSampleOccurred_null() throws IOException { System.out.println("sampleOccurred null"); SampleResult res = new SampleResult(); //res.setResponseData("test".getBytes()); SampleEvent e = new SampleEvent(res, "Test"); FlexibleFileWriter instance = new FlexibleFileWriter(); instance.setColumns(FlexibleFileWriter.AVAILABLE_FIELDS.replace(' ', '|')); String tmpFile = File.createTempFile("ffw_test_", ".txt").getAbsolutePath(); instance.setFilename(tmpFile); instance.testStarted(); for (int n = 0; n < 10; n++) { res.sampleStart(); res.sampleEnd(); instance.sampleOccurred(e); } instance.testEnded(); assertTrue(tmpFile.length() > 0); }
Example 3
Source File: FlowerSyncClient.java From flower with Apache License 2.0 | 6 votes |
@Override public SampleResult runTest(JavaSamplerContext arg0) { SampleResult result = new SampleResult(); result.sampleStart(); try { long begin = System.currentTimeMillis(); String ret = (String) flowRouter.syncCallService(message); long cost = (System.currentTimeMillis() - begin); logger.info("ret : {}, cost:[{}ms]", ret, cost); if (message.equals(ret)) { result.setSuccessful(true); } } catch (Exception e) { result.setSuccessful(false); logger.error("", e); } finally { result.sampleEnd(); } return result; }
Example 4
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 5
Source File: LoadosophiaUploaderTest.java From jmeter-bzm-plugins with Apache License 2.0 | 6 votes |
@Test public void testTestEnded() throws IOException { System.out.println("testEnded"); LoadosophiaUploader instance = new LoadosophiaUploaderEmul(); instance.resetTest(); instance.setStoreDir(TestJMeterUtils.getTempDir()); instance.setTitle("UnitTest"); instance.setColorFlag("gray"); instance.setProject("DEFAULT"); instance.setUploadToken("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"); instance.testStarted(); SampleResult res = new SampleResult(); res.sampleStart(); res.sampleEnd(); SampleEvent event = new SampleEvent(res, "test"); instance.sampleOccurred(event); instance.testEnded(); }
Example 6
Source File: TransactionsPerSecondGuiTest.java From jmeter-plugins with Apache License 2.0 | 6 votes |
/** * Test of add method, of class TransactionsPerSecondGui. */ @Test public void testAdd() { System.out.println("add"); SampleResult res = new SampleResult(); res.setAllThreads(1); res.setThreadName("test 1-2"); TransactionsPerSecondGui instance = new TransactionsPerSecondGui(); instance.add(res); res.sampleStart(); try { Thread.sleep(10); } catch (InterruptedException ex) { } res.sampleEnd(); instance.add(res); }
Example 7
Source File: HTTPRawSamplerTest.java From jmeter-plugins with Apache License 2.0 | 6 votes |
@Test public void testProcessIO_long_Limited() throws Exception { JMeterUtils.setProperty(AbstractIPSampler.RECV_BUFFER_LEN_PROPERTY, Integer.toString(1024)); JMeterUtils.setProperty(AbstractIPSampler.RESULT_DATA_LIMIT, Integer.toString(1024)); instance = new HTTPRawSamplerEmul(); instance.setHostName("169.254.250.25"); instance.setPort("80"); instance.setTimeout("0"); System.out.println("processIOlim"); SampleResult res = new SampleResult(); res.sampleStart(); String resp = TestJMeterUtils.getTestData(12048); instance.sockEmul.setBytesToRead(ByteBuffer.wrap(resp.getBytes())); byte[] result = instance.processIO(res); System.out.println(result.length); assertEquals(4096, result.length); }
Example 8
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 9
Source File: TopicMessageGeneratorClient.java From hedera-mirror-node with Apache License 2.0 | 5 votes |
/** * Runs test by calling sampler to manage topic message table. Reports success based on successful db operations * * @return Sample result */ @Override public SampleResult runTest(JavaSamplerContext context) { SampleResult result = new SampleResult(); try { // establish db connection in test to ensure failures are reported connectionHandler = new ConnectionHandler(host, port, dbName, dbUser, dbPassword); sampler = new TopicMessageGeneratorSampler(connectionHandler); MessageGenerator messageGen = MessageGenerator.builder() .topicNum(context.getLongParameter("topicID", 0)) .historicMessagesCount(context.getIntParameter("historicMessagesCount", 0)) .futureMessagesCount(context.getIntParameter("newTopicsMessageCount", 0)) .topicMessageEmitCycles(context.getIntParameter("topicMessageEmitCycles", 0)) .newTopicsMessageDelay(context.getLongParameter("newTopicsMessageDelay", 0L)) .deleteFromSequence(context.getLongParameter("delSeqFrom", -1L)) .build(); result.sampleStart(); sampler.populateTopicMessages(messageGen); result.sampleEnd(); result.setResponseMessage("Successfully performed populateTopicMessages"); result.setResponseCodeOK(); result.setSuccessful(true); } catch (Exception ex) { log.error("Error populating topic messages", 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; }
Example 10
Source File: HbaseJMeter.java From learning-hadoop with Apache License 2.0 | 5 votes |
public SampleResult runTest(JavaSamplerContext context) { SampleResult sampleResult = new SampleResult(); sampleResult.sampleStart(); String key = null; if (keyRondom) { key = String.valueOf(String.valueOf(new Random().nextInt(keyNumLength)).hashCode()); } else { key = SequenceKey.getsequenceKey(); } try { if (methedType.equals("put")) { put = new Put(Bytes.toBytes(key)); put.setWriteToWAL(writeToWAL); for (int j = 0; j < cfs.length; j++) { for (int n = 0; n < qualifiers.length; n++) { put.add(Bytes.toBytes(cfs[j]), Bytes.toBytes(qualifiers[n]), Bytes.toBytes(values)); } } table.put(put); } else if (methedType.equals("get")) { get = new Get((key).getBytes()); table.get(get); } sampleResult.setSuccessful(true); } catch (Throwable e) { sampleResult.setSuccessful(false); } finally { sampleResult.sampleEnd(); } return sampleResult; }
Example 11
Source File: LicenseActivateCheckDeactivate.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
@Override public SampleResult runTest(JavaSamplerContext context) { results = new SampleResult(); results.sampleStart(); licenseID = context.getParameter("LicenseID"); hardwareCode = context.getParameter("HardwareCode"); installCode = context.getParameter("InstallCode"); waitTimeMillis = Integer.valueOf(context.getParameter("WaitSeconds")) * 1000; intervalTimeMillis = Integer.valueOf(context .getParameter("IntervalSeconds")) * 1000; strResult = licenseID + ":\n"; startTime = System.currentTimeMillis(); // 检查许可证状态,应为未激活,然后激活 check(NextAction.ACTIVATE, "不通过"); // 等待两次测试之间的间隔时间 wait(intervalTimeMillis); pastTime = System.currentTimeMillis() - startTime - waitTimeMillis * waitCount - intervalTimeMillis; results.setResponseMessage(strResult + "\n实际耗时(毫秒):" + pastTime); results.sampleEnd(); return results; }
Example 12
Source File: AbstractDynamicThreadGroupModel.java From jmeter-plugins with Apache License 2.0 | 5 votes |
protected void saveLogRecord(String marker, String threadName, String arrivalID) { SampleResult res = new SampleResult(); res.sampleStart(); res.setSampleLabel(arrivalID); res.setResponseMessage(marker); res.setThreadName(threadName); res.sampleEnd(); SampleEvent evt = new SampleEvent(res, getName()); logFile.sampleOccurred(evt); }
Example 13
Source File: LicenseActivateCheckDeactivate.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
@Override public SampleResult runTest(JavaSamplerContext context) { results = new SampleResult(); results.sampleStart(); licenseID = context.getParameter("LicenseID"); hardwareCode = context.getParameter("HardwareCode"); installCode = context.getParameter("InstallCode"); waitTimeMillis = Integer.valueOf(context.getParameter("WaitSeconds")) * 1000; intervalTimeMillis = Integer.valueOf(context .getParameter("IntervalSeconds")) * 1000; strResult = licenseID + ":\n"; startTime = System.currentTimeMillis(); // 检查许可证状态,应为未激活,然后激活 check(NextAction.ACTIVATE, "不通过"); // 等待两次测试之间的间隔时间 wait(intervalTimeMillis); pastTime = System.currentTimeMillis() - startTime - waitTimeMillis * waitCount - intervalTimeMillis; results.setResponseMessage(strResult + "\n实际耗时(毫秒):" + pastTime); results.sampleEnd(); return results; }
Example 14
Source File: AccelCreateSession.java From directory-fortress-core with Apache License 2.0 | 5 votes |
/** * Description of the Method * * @param samplerContext Description of the Parameter * @return Description of the Return Value */ public SampleResult runTest( JavaSamplerContext samplerContext ) { SampleResult sampleResult = new SampleResult(); try { sampleResult.sampleStart(); //String message = "FT CreateSession TID: " + getThreadId() + " UID:" + userId + " CTR:" + ctr++; //LOG.info( message ); //System.out.println( message ); assertNotNull( accelMgr ); Session session; User user = new User(); // positive test case: user.setUserId( userId ); user.setPassword( "secret" ); session = accelMgr.createSession( user, false ); assertNotNull( session ); assertTrue( session.isAuthenticated() ); sampleResult.sampleEnd(); sampleResult.setBytes(1); sampleResult.setResponseMessage("AC test completed TID: " + getThreadId() + " UID: " + userId); sampleResult.setSuccessful(true); } catch ( org.apache.directory.fortress.core.SecurityException se ) { System.out.println( "ThreadId:" + getThreadId() + "Error running test: " + se ); se.printStackTrace(); sampleResult.setSuccessful( false ); } return sampleResult; }
Example 15
Source File: LicenseCheck.java From translationstudio8 with GNU General Public License v2.0 | 4 votes |
@Override public SampleResult runTest(JavaSamplerContext context) { SampleResult results = new SampleResult(); results.sampleStart(); String licenseID = context.getParameter("LicenseID"); String hardwareCode = context.getParameter("HardwareCode"); String installCode = context.getParameter("InstallCode"); int intervalTime = Integer.valueOf(context .getParameter("IntervalSeconds")) * 1000; String strResult = licenseID + ":\n"; long startTime = System.currentTimeMillis(); // 验证许可证的激活状态 try { String result = ServiceUtilTest.check(licenseID, hardwareCode, installCode); if (result.equals("Check Success")) { results.setSuccessful(true); results.setResponseCodeOK(); strResult += "验证通过!\n"; } else { results.setSuccessful(true); results.setResponseCodeOK(); strResult += "验证未通过,返回结果为:" + result + "\n"; } } catch (Exception e) { results.setSuccessful(false); strResult += "验证失败,异常信息:\n" + e.getMessage() + "\n"; } // 等待两次测试之间的间隔 if (intervalTime != 0) { try { Thread.sleep(intervalTime); } catch (InterruptedException e1) { e1.printStackTrace(); } } long pastTime = System.currentTimeMillis() - startTime - intervalTime; results.setResponseMessage(strResult + "\n实际耗时(毫秒):" + pastTime); results.sampleEnd(); return results; }
Example 16
Source File: CheckAccess.java From directory-fortress-core with Apache License 2.0 | 4 votes |
/**224 * Description of the Method * * @param samplerContext Description of the Parameter * @return Description of the Return Value */ public SampleResult runTest( JavaSamplerContext samplerContext ) { SampleResult sampleResult = new SampleResult(); try { int opCount = ++ctr % 10; if( opCount == 0 ) opCount = 10; int objCount = (ctr / 10) + 1; if(objCount > 10) { objCount = objCount % 10; } if(objCount == 0) { objCount = 1; } //int objCount = ((ctr / 10) + 1) % 10; String opName = "oper" + opCount; String objName = "loadtestobject" + objCount; sampleResult.sampleStart(); String message; if(isFortress) { message = "FT "; } else { message = "AC "; } message += "CheckAccess isFortress: " + isFortress + ", userId: " + userId + ", objName:" + objName + ", opName: " + opName; /* LOG.info( message ); System.out.println( message ); */ assertNotNull( session ); assertTrue( session.isAuthenticated() ); Permission perm = new Permission(); perm.setObjName( objName ); perm.setOpName( opName ); boolean result; if(isFortress) { assertNotNull( accessMgr ); result = accessMgr.checkAccess( session, perm ); } else { assertNotNull( accelMgr ); result = accelMgr.checkAccess( session, perm ); } // positive test case: assertTrue( message, result ); sampleResult.sampleEnd(); sampleResult.setBytes(1); sampleResult.setResponseMessage("test checkAccess completed"); sampleResult.setSuccessful(true); } catch ( org.apache.directory.fortress.core.SecurityException se ) { String error = "ThreadId:" + getThreadId() + "Error running test: " + se; LOG.error( error ); System.out.println( error ); se.printStackTrace(); fail( error ); sampleResult.setSuccessful( false ); } return sampleResult; }
Example 17
Source File: SessionPermissions.java From directory-fortress-core with Apache License 2.0 | 4 votes |
/**224 * Description of the Method * * @param samplerContext Description of the Parameter * @return Description of the Return Value */ public SampleResult runTest( JavaSamplerContext samplerContext ) { SampleResult sampleResult = new SampleResult(); try { sampleResult.sampleStart(); String message; if(isFortress) { message = "FT "; } else { message = "AC "; } message += "SessionPermissions isFortress: " + isFortress + ", userId: " + userId; /* LOG.info( message ); System.out.println( message ); */ assertNotNull( session ); assertTrue( session.isAuthenticated() ); List<Permission> result; if(isFortress) { assertNotNull( accessMgr ); result = accessMgr.sessionPermissions( session ); } else { assertNotNull( accelMgr ); result = accelMgr.sessionPermissions( session ); } // positive test case: assertNotNull( message, result ); assertTrue( message, result.size() > 0 ); sampleResult.sampleEnd(); sampleResult.setBytes(1); sampleResult.setResponseMessage("test sessionPermissions completed, message=" + message); sampleResult.setSuccessful(true); } catch ( org.apache.directory.fortress.core.SecurityException se ) { String error = "ThreadId:" + getThreadId() + "Error running test: " + se; LOG.error( error ); System.out.println( error ); se.printStackTrace(); fail( error ); sampleResult.setSuccessful( false ); } return sampleResult; }
Example 18
Source File: SubscriberSampler.java From mqtt-jmeter with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public SampleResult sample(Entry entry) { SampleResult result = new SampleResult(); result.setSampleLabel(getNameLabel()); result.sampleStart(); if (null != exceptionOccurred) { result.setSuccessful(false); result.setResponseMessage("Client is not connected." + lineSeparator + exceptionOccurred.toString()); result.setResponseData(exceptionOccurred.toString().getBytes()); result.sampleEnd(); result.setResponseCode("FAILED"); return result; } Message receivedMessage; while (!interrupted && null != client.getReceivedMessages() && null != client.getReceivedMessageCounter()) { receivedMessage = client.getReceivedMessages().poll(); if (receivedMessage != null) { client.getReceivedMessageCounter().incrementAndGet(); result.sampleEnd(); result.setSuccessful(true); result.setResponseMessage(lineSeparator + "Received " + client.getReceivedMessageCounter().get() + " " + "messages." + lineSeparator + "Current message QOS : " + receivedMessage.getQos() + lineSeparator + "Is current message a duplicate : " + receivedMessage.isDup() + lineSeparator + "Received timestamp of current message : " + receivedMessage.getCurrentTimestamp() + lineSeparator + "Is current message" + " a retained message : " + receivedMessage.isRetained()); result.setBytes(receivedMessage.getPayload().length); result.setResponseData(receivedMessage.getPayload()); result.setResponseCodeOK(); return result; } } result.setSuccessful(false); result.setResponseMessage("Client has been stopped or an error occurred while receiving messages. Received " + " valid messages."); result.sampleEnd(); result.setResponseCode("FAILED"); return result; }
Example 19
Source File: DisConnectSampler.java From mqtt-jmeter with Apache License 2.0 | 4 votes |
@Override public SampleResult sample(Entry entry) { SampleResult result = new SampleResult(); result.setSampleLabel(getName()); JMeterVariables vars = JMeterContextService.getContext().getVariables(); connection = (MQTTConnection) vars.getObject("conn"); String clientId = (String) vars.getObject("clientId"); if (connection == null) { result.sampleStart(); result.setSuccessful(false); result.setResponseMessage("Connection not found."); result.setResponseData("Failed. Connection not found.".getBytes()); result.setResponseCode("500"); result.sampleEnd(); // avoid endtime=0 exposed in trace log return result; } try { result.sampleStart(); if (connection != null) { logger.info(MessageFormat.format("Disconnect connection {0}.", connection)); connection.disconnect(); vars.remove("conn"); // clean up thread local var as well topicSubscribed.remove(clientId); } result.sampleEnd(); result.setSuccessful(true); result.setResponseData("Successful.".getBytes()); result.setResponseMessage(MessageFormat.format("Connection {0} disconnected.", connection)); result.setResponseCodeOK(); } catch (Exception e) { logger.log(Level.SEVERE, "Failed to disconnect Connection" + connection, e); if (result.getEndTime() == 0) result.sampleEnd(); //avoid re-enter sampleEnd() result.setSuccessful(false); result.setResponseMessage(MessageFormat.format("Failed to disconnect Connection {0}.", connection)); result.setResponseData(MessageFormat.format("Client [{0}] failed. Couldn't disconnect connection.", (clientId == null ? "null" : clientId)).getBytes()); result.setResponseCode("501"); } return result; }
Example 20
Source File: KafkaProducerSampler.java From kafkameter with Apache License 2.0 | 2 votes |
/** * Start the sample request and set the {@code samplerData} to {@code data}. * * @param result * the sample result to update * @param data * the request to set as {@code samplerData} */ private void sampleResultStart(SampleResult result, String data) { result.setSamplerData(data); result.sampleStart(); }