Java Code Examples for org.apache.jmeter.samplers.SampleResult#setStampAndTime()
The following examples show how to use
org.apache.jmeter.samplers.SampleResult#setStampAndTime() .
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: AbstractVsThreadVisualizerTest.java From jmeter-plugins with Apache License 2.0 | 6 votes |
/** * Test of getCurrentThreadCount method, of class AbstractVsThreadVisualizer. */ @Test public void testGetCurrentThreadCount() { System.out.println("getCurrentThreadCount"); long now = System.currentTimeMillis(); SampleResult sample = new SampleResult(); sample.setGroupThreads(3); sample.setThreadName("test_tg"); sample.setStampAndTime(now, 300); AbstractVsThreadVisualizer instance = new AbstractVsThreadVisualizerImpl(); instance.add(sample); int expResult = 3; int result = instance.getCurrentThreadCount(sample); assertEquals(expResult, result); }
Example 2
Source File: DummyElement.java From jmeter-plugins with Apache License 2.0 | 6 votes |
private SampleResult createSample() throws ReflectiveOperationException { Class<SampleResult> cls; //noinspection unchecked cls = (Class<SampleResult>) Class.forName(getResultClass()); SampleResult res; res = cls.newInstance(); if (isSimulateWaiting()) { res.sampleStart(); try { Thread.sleep(getResponseTime()); } catch (InterruptedException ignored) { } res.sampleEnd(); } else { res.setStampAndTime(System.currentTimeMillis(), (long) getResponseTime()); } return res; }
Example 3
Source File: HonoCommander.java From hono with Eclipse Public License 2.0 | 5 votes |
private void setSampleStartAndEndTime(final SampleResult result) { if (sampleStart.get() == 0) { LOG.debug("SampleStart hasn't been set or no messages received"); result.setStampAndTime(System.currentTimeMillis(), 0); } else { final long startTime = sampleStart.getAndSet(0); result.setStampAndTime(startTime, System.currentTimeMillis() - startTime); } }
Example 4
Source File: ResponseTimesDistributionGuiTest.java From jmeter-plugins with Apache License 2.0 | 5 votes |
@Test public void testAdd() { System.out.println("add"); SampleResult res = new SampleResult(); res.setAllThreads(1); res.setThreadName("test 1-2"); res.setStampAndTime(System.currentTimeMillis(), 1000); ResponseTimesDistributionGui instance = new ResponseTimesDistributionGui(); instance.add(res); }
Example 5
Source File: AggregatedTypeUpdaterTest.java From jmeter-prometheus-plugin with Apache License 2.0 | 4 votes |
@Test public void testHistogramResponseTime() { BaseCollectorConfig base = TestUtilities.simpleHistogramCfg(); base.setLabels(labels); ListenerCollectorConfig cfg = new ListenerCollectorConfig(base); cfg.setMeasuring(Measurable.ResponseTime.toString()); cfg.setMetricName("ct_updater_test_hist_rt"); Histogram collector = (Histogram) reg.getOrCreateAndRegister(cfg); AggregatedTypeUpdater u = new AggregatedTypeUpdater(cfg); SampleResult res = new SampleResult(); res.setSampleLabel(name); int responseTime = 650; res.setStampAndTime(System.currentTimeMillis(), 650); res.setResponseCode(code); JMeterVariables vars = new JMeterVariables(); vars.put("foo_label", var_value); JMeterContextService.getContext().setVariables(vars); SampleEvent e = new SampleEvent(res,"tg1", vars); String[] actualLabels = u.labelValues(e); Assert.assertArrayEquals(expectedLabels, actualLabels); u.update(e); List<MetricFamilySamples> metrics = collector.collect(); assertEquals(1, metrics.size()); MetricFamilySamples family = metrics.get(0); assertEquals(7, family.samples.size()); // 4 buckets + Inf + count + sum for(Sample sample : family.samples) { List<String> values = sample.labelValues; List<String> names = sample.labelNames; //correct labels without 'le' (bin size) boolean correctLabels = names.get(0).equals(labels[0]) && names.get(1).equals(labels[1]) && names.get(2).equals(labels[2]) && values.get(0).equals(expectedLabels[0]) && values.get(1).equals(expectedLabels[1]) && values.get(2).equals(expectedLabels[2]); assertTrue(correctLabels); // _sum and _count don't have an 'le' label if(sample.name.endsWith("count") || sample.name.endsWith("sum")) { assertTrue(values.size() == 3 && names.size() == 3); if(sample.name.endsWith("count")) { Assert.assertEquals(1, sample.value, 0.1); }else { Assert.assertEquals(responseTime, sample.value, 0.1); } }else { assertTrue(values.size() == 4 && names.size() == 4); String leString = values.get(3); double le = (!leString.isEmpty() && !leString.equals("+Inf")) ? Double.parseDouble(leString) : Double.MAX_VALUE; if(le == Double.MAX_VALUE) { Assert.assertEquals(1, sample.value, 0.1); } else if(le < responseTime) { Assert.assertEquals(0, sample.value, 0.1); }else if(le > responseTime) { Assert.assertEquals(1, sample.value, 0.1); } } } }
Example 6
Source File: AggregatedTypeUpdaterTest.java From jmeter-prometheus-plugin with Apache License 2.0 | 4 votes |
@Test public void testSummaryResponseTime() { BaseCollectorConfig base = TestUtilities.simpleSummaryCfg(); base.setLabels(labels); ListenerCollectorConfig cfg = new ListenerCollectorConfig(base); cfg.setMeasuring(Measurable.ResponseTime.toString()); cfg.setMetricName("ct_updater_test_summary_rt"); Summary collector = (Summary) reg.getOrCreateAndRegister(cfg); AggregatedTypeUpdater u = new AggregatedTypeUpdater(cfg); SampleResult res = new SampleResult(); res.setSampleLabel(name); int responseTime = 650; res.setStampAndTime(System.currentTimeMillis(), 650); res.setResponseCode(code); JMeterVariables vars = new JMeterVariables(); vars.put("foo_label", var_value); JMeterContextService.getContext().setVariables(vars); SampleEvent e = new SampleEvent(res,"tg1", vars); String[] actualLabels = u.labelValues(e); Assert.assertArrayEquals(expectedLabels, actualLabels); u.update(e); List<MetricFamilySamples> metrics = collector.collect(); assertEquals(1, metrics.size()); MetricFamilySamples family = metrics.get(0); assertEquals(5, family.samples.size()); // 3 quantiles + count + sum for(Sample sample : family.samples) { List<String> values = sample.labelValues; List<String> names = sample.labelNames; //correct labels without quantile boolean correctLabels = names.get(0).equals(labels[0]) && names.get(1).equals(labels[1]) && names.get(2).equals(labels[2]) && values.get(0).equals(expectedLabels[0]) && values.get(1).equals(expectedLabels[1]) && values.get(2).equals(expectedLabels[2]); assertTrue(correctLabels); // _sum and _count don't have an 'le' label if(sample.name.endsWith("count") || sample.name.endsWith("sum")) { assertTrue(values.size() == 3 && names.size() == 3); if(sample.name.endsWith("count")) { Assert.assertEquals(1, sample.value, 0.1); }else { Assert.assertEquals(responseTime, sample.value, 0.1); } }else { assertTrue(values.size() == 4 && names.size() == 4); Assert.assertEquals(responseTime, sample.value, 0.1); } } }
Example 7
Source File: HonoReceiver.java From hono with Eclipse Public License 2.0 | 4 votes |
/** * Takes a sample. * * @param result The result to set the sampler's current statistics on. */ public void sample(final SampleResult result) { synchronized (lock) { long elapsed = 0; result.setResponseCodeOK(); result.setSuccessful(errorCount == 0 && !senderClockNotInSync); result.setSampleCount(messageCount); result.setErrorCount(errorCount); // NOTE: This method does nothing in JMeter 3.3/4.0 result.setBytes(bytesReceived); if (messageCount > 0) { if (sampler.isUseSenderTime() && sampleStart != 0 && errorCount == 0) { // errorCount has to be 0 here - otherwise totalSampleDeliveryTime doesn't have a correct value elapsed = senderClockNotInSync ? -1 : totalSampleDeliveryTime / messageCount; result.setStampAndTime(sampleStart, elapsed); } else if (sampleStart != 0) { elapsed = System.currentTimeMillis() - sampleStart; result.setStampAndTime(sampleStart, elapsed); result.setIdleTime(elapsed); } else { LOGGER.warn("sampleStart hasn't been set - setting elapsed time to 0"); result.setStampAndTime(System.currentTimeMillis(), 0); result.setIdleTime(0); } } else { // empty sample result.setStampAndTime(System.currentTimeMillis(), 0); result.setIdleTime(0); } String responseMessage = ""; if (errorCount == 0) { final String formatString = sampler.isUseSenderTime() ? "{}: received batch of {} messages; average delivery time: {}ms" : "{}: received batch of {} messages in {}ms"; LOGGER.info(formatString, sampler.getThreadName(), messageCount, elapsed); } else { LOGGER.info("{}: received batch of {} messages with {} errors in {}ms", sampler.getThreadName(), messageCount, errorCount, elapsed); responseMessage = "got " + errorCount + " invalid messages"; } if (senderClockNotInSync) { responseMessage = (responseMessage.isEmpty() ? "" : responseMessage + "; ") + "sender clock not in sync"; LOGGER.error("The sender time extracted from at least one of the received messages is newer than the receiver time" + " - sender and receiver clocks are not in sync. Consider deactivating usage of the sender time."); } result.setResponseMessage(responseMessage); // reset all fields totalSampleDeliveryTime = 0; senderClockNotInSync = false; bytesReceived = 0; messageCount = 0; errorCount = 0; sampleStart = 0; } }
Example 8
Source File: HonoSender.java From hono with Eclipse Public License 2.0 | 4 votes |
/** * Publishes multiple messages to Hono. * * @param sampleResult The result object representing the combined outcome of the samples. * @param messageCount The number of messages to send * @param deviceId The identifier if the device to send a message for. * @param waitForDeliveryResult A flag indicating whether to wait for the result of the send operation. */ public void send(final SampleResult sampleResult, final int messageCount, final String deviceId, final boolean waitForDeliveryResult) { final long sampleStart = System.currentTimeMillis(); long addedSendDurations = 0; boolean isSuccessful = true; String firstResponseErrorMessage = ""; String firstResponseErrorCode = ""; long sentBytes = 0; int errorCount = 0; for (int i = 0; i < messageCount; i++) { final SampleResult subResult = new SampleResult(); subResult.setDataType(SampleResult.TEXT); subResult.setResponseOK(); subResult.setResponseCodeOK(); subResult.setSampleLabel(sampleResult.getSampleLabel()); // send the message send(subResult, deviceId, waitForDeliveryResult); // can't call sampleResult.addSubResult(subResult) here - this would prevent a later invocation of sampleResult.setStampAndTime() sampleResult.addRawSubResult(subResult); if (!subResult.isSuccessful()) { isSuccessful = false; errorCount++; if (firstResponseErrorMessage.isEmpty()) { firstResponseErrorMessage = subResult.getResponseMessage(); firstResponseErrorCode = subResult.getResponseCode(); } } sentBytes += subResult.getSentBytes(); addedSendDurations += subResult.getTime(); } sampleResult.setSuccessful(isSuccessful); final String responseMessage = MessageFormat.format("BatchResult {0}/{1}/{2}", sampler.getEndpoint(), sampler.getTenant(), deviceId); if (isSuccessful) { sampleResult.setResponseMessage(responseMessage); } else { sampleResult.setResponseMessage(responseMessage + ": " + errorCount + " errors - first: " + firstResponseErrorMessage); sampleResult.setResponseCode(firstResponseErrorCode); } sampleResult.setSentBytes(sentBytes); sampleResult.setSampleCount(messageCount); sampleResult.setErrorCount(errorCount); // NOTE: This method does nothing in JMeter 3.3/4.0 final long averageElapsedTimePerMessage = addedSendDurations / messageCount; sampleResult.setStampAndTime(sampleStart, averageElapsedTimePerMessage); }