org.apache.jmeter.samplers.SampleEvent Java Examples

The following examples show how to use org.apache.jmeter.samplers.SampleEvent. 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 vote down vote up
@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: RotatingResultCollectorTest.java    From jmeter-bzm-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testFlowWithoutExtension() throws Exception {
    RotatingResultCollector te = new RotatingResultCollector();
    te.setMaxSamplesCount("ZXC");
    assertEquals(Integer.MAX_VALUE, te.getMaxSamplesCountAsInt());

    File f = File.createTempFile("rotating", "");
    f.deleteOnExit();
    te.setFilename(f.getAbsolutePath());
    te.setMaxSamplesCount("3");
    te.testStarted();

    for (int n = 0; n < 10; n++) {
        SampleResult result = new SampleResult();
        result.setSampleLabel("#" + n);
        te.sampleOccurred(new SampleEvent(result, ""));
    }

    te.testEnded();
    assertTrue(te.filename, te.filename.endsWith(".3"));
}
 
Example #3
Source File: AbstractGraphPanelVisualizerTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testIncludeExclude_exclude_only() {
    CorrectedResultCollector instance = new CorrectedResultCollector();
    instance.setProperty(CorrectedResultCollector.EXCLUDE_SAMPLE_LABELS, "boom1,test,boom2");
    instance.testStarted();
    DebugVisualizer vis = new DebugVisualizer();
    vis.configure(instance);
    instance.setListener(vis);

    vis.lastLabel = null;
    SampleResult res = new SampleResult();
    res.setSampleLabel("test");
    instance.sampleOccurred(new SampleEvent(res, "tg"));
    assertNull(vis.lastLabel);

    vis.lastLabel = null;
    SampleResult res2 = new SampleResult();
    res2.setSampleLabel("test1");
    instance.sampleOccurred(new SampleEvent(res2, "tg"));
    assertEquals("test1", vis.lastLabel);
}
 
Example #4
Source File: FlexibleFileWriterTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@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 #5
Source File: ConsoleStatusLoggerTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
/**
 * Test of sampleOccurred method, of class ConsoleStatusLogger.
 */
@Test
public void testSampleOccurred() throws InterruptedException {
    System.out.println("sampleOccurred");
    SampleResult res = new SampleResult();
    res.setResponseCode("200");
    SampleEvent se = new SampleEvent(res, "testTG");
    ConsoleStatusLogger instance = new ConsoleStatusLogger();
    instance.testStarted();
    instance.sampleOccurred(se);
    instance.sampleOccurred(se);
    Thread.sleep(1020);
    instance.sampleOccurred(se);
    instance.sampleOccurred(se);
    Thread.sleep(1020);
    instance.sampleOccurred(se);
    instance.sampleOccurred(se);
}
 
Example #6
Source File: LoadosophiaUploaderTest.java    From jmeter-bzm-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testOnlineProcessor() throws InterruptedException {
    System.out.println("onlineProcessor");
    LoadosophiaUploader instance = new LoadosophiaUploaderEmul();
    instance.resetTest();
    instance.setUseOnline(true);
    instance.setStoreDir(TestJMeterUtils.getTempDir());
    instance.testStarted("");
    for (int i = 0; i < 100; i++) {
        SampleResult res = new SampleResult();
        res.setThreadName("test " + i);
        SampleEvent event = new SampleEvent(res, "test " + i);
        instance.sampleOccurred(event);
    }
    Thread.sleep(10);
    instance.testEnded("");
}
 
Example #7
Source File: AbstractUpdaterTest.java    From jmeter-prometheus-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void testKeywords() {
	BaseCollectorConfig base = TestUtilities.simpleCounterCfg();
	base.setLabels(new String[] {"label","code"});
	ListenerCollectorConfig cfg = new ListenerCollectorConfig(base);
	
	TestUpdater u = new TestUpdater(cfg);
	
	SampleResult res = new SampleResult();
	res.setSampleLabel("test_label");
	res.setResponseCode("204");
	SampleEvent event = new SampleEvent(res,"test_tg", new JMeterVariables());
	
	String[] labels = u.labelValues(event);
	

	Assert.assertTrue(labels.length == 2);
	Assert.assertArrayEquals(new String[] {"test_label", "204"}, labels);
}
 
Example #8
Source File: LoadosophiaUploaderTest.java    From jmeter-bzm-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testTestEndedWithNoStoreDir() throws IOException {
    System.out.println("testEnded");
    JMeterUtils.setProperty("loadosophia.address", "http://localhost/");
    LoadosophiaUploader instance = new LoadosophiaUploaderEmul();
    instance.setStoreDir("");
    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 #9
Source File: LoadosophiaUploaderTest.java    From jmeter-bzm-plugins with Apache License 2.0 6 votes vote down vote up
@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 #10
Source File: AbstractGraphPanelVisualizerTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testIncludeExcludeRegex_exclude_only() {
    CorrectedResultCollector instance = new CorrectedResultCollector();
    instance.setProperty(CorrectedResultCollector.EXCLUDE_SAMPLE_LABELS,
            "P[0-9].*");
    instance.setProperty(
            CorrectedResultCollector.EXCLUDE_REGEX_CHECKBOX_STATE, true);
    instance.testStarted();
    DebugVisualizer vis = new DebugVisualizer();
    instance.setListener(vis);
    vis.configure(instance);

    vis.lastLabel = null;
    SampleResult res = new SampleResult();
    res.setSampleLabel("P1_TEST");
    instance.sampleOccurred(new SampleEvent(res, "tg"));
    assertNull(vis.lastLabel);

    vis.lastLabel = null;
    SampleResult res1 = new SampleResult();
    res1.setSampleLabel("T1_TEST");
    instance.sampleOccurred(new SampleEvent(res1, "tg"));
    assertEquals("T1_TEST", vis.lastLabel);
}
 
Example #11
Source File: RotatingResultCollectorTest.java    From jmeter-bzm-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testFlowWithNumberExtension() throws Exception {
    RotatingResultCollector te = new RotatingResultCollector();
    te.setMaxSamplesCount("ZXC");
    assertEquals(Integer.MAX_VALUE, te.getMaxSamplesCountAsInt());

    File f = File.createTempFile("rotating", ".9");
    f.deleteOnExit();
    te.setFilename(f.getAbsolutePath());
    te.setMaxSamplesCount("3");
    te.testStarted();

    for (int n = 0; n < 10; n++) {
        SampleResult result = new SampleResult();
        result.setSampleLabel("#" + n);
        te.sampleOccurred(new SampleEvent(result, ""));
    }

    te.testEnded();
    assertTrue(te.filename, te.filename.endsWith(".3.9"));
}
 
Example #12
Source File: RotatingResultCollectorTest.java    From jmeter-bzm-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void flowDefault() throws Exception {
    RotatingResultCollector te = new RotatingResultCollector();
    te.setMaxSamplesCount("ZXC");
    assertEquals(Integer.MAX_VALUE, te.getMaxSamplesCountAsInt());

    File f = File.createTempFile("rotating", ".jtl");
    f.deleteOnExit();
    te.setFilename(f.getAbsolutePath());
    te.setMaxSamplesCount("3");
    te.testStarted();

    for (int n = 0; n < 10; n++) {
        SampleResult result = new SampleResult();
        result.setSampleLabel("#" + n);
        te.sampleOccurred(new SampleEvent(result, ""));
    }

    te.testEnded();
    assertTrue(te.filename.endsWith(".3.jtl"));
}
 
Example #13
Source File: RotatingResultCollector.java    From jmeter-bzm-plugins with Apache License 2.0 6 votes vote down vote up
@Override
public void sampleOccurred(SampleEvent event) {
    isChanging = true;
    try {
        if (currentSamplesCount >= maxSamplesCount) {
            testEnded();
            nullifyPrintWriter();   // HACK for previous versions
            filename = getRotatedFilename(filename, originalFilename);
            LOGGER.info("Creating new log chunk: " + filename);
            currentSamplesCount = 0;
            testStarted();
        }

        super.sampleOccurred(event);
        if (this.isSampleWanted(event.getResult().isSuccessful())) {
            currentSamplesCount++;
        }
    } finally {
        isChanging = false;
    }
}
 
Example #14
Source File: AutoStopTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
/**
 * Test of sampleOccurred method, of class AutoStop.
 */
@Test
public void testSampleOccurred() throws InterruptedException {
    System.out.println("sampleOccurred");
    SampleResult res = new SampleResult();
    res.setLatency(500);
    SampleEvent se = new SampleEvent(res, "");
    AutoStop instance = new AutoStop();
    instance.setResponseTime("10");
    instance.setResponseTimeSecs("3");
    instance.setErrorRate("0");
    instance.sampleOccurred(se);
    for (int n = 0; n < 5; n++) {
        synchronized (this) {
            wait(1000);
        }
        instance.sampleOccurred(se);
    }
}
 
Example #15
Source File: AggregateReportGuiTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
/**
 * Test of add method, of class StatVisualizerAccessorGui.
 */
@Test
public void testAdd() throws IOException {
    System.out.println("add");
    AggregateReportGui instance = new AggregateReportGui();

    SampleResult res = new SampleResult();
    instance.add(res);

    SampleResult res2 = new SampleResult();
    instance.add(res2);

    ResultCollector rc = new ResultCollector();
    rc.setListener(instance);
    rc.sampleOccurred(new SampleEvent(res, ""));
    rc.sampleOccurred(new SampleEvent(res2, ""));

    File f = File.createTempFile("test", ".csv");
    instance.getGraphPanelChart().saveGraphToCSV(f);
}
 
Example #16
Source File: AbstractUpdaterTest.java    From jmeter-prometheus-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void testNulls() {
	BaseCollectorConfig base = TestUtilities.simpleCounterCfg();
	base.setLabels(new String[] {"be_null_one", "be_null_two", "code"});
	ListenerCollectorConfig cfg = new ListenerCollectorConfig(base);
	
	TestUpdater u = new TestUpdater(cfg);
	
	SampleResult res = new SampleResult();
	res.setResponseCode("304");
	SampleEvent event = new SampleEvent(res ,"tg1", new JMeterVariables());
	
	String[] labels = u.labelValues(event);
	
	Assert.assertTrue(labels.length == 3);
	Assert.assertArrayEquals(new String[] {"null", "null", "304"}, labels);
}
 
Example #17
Source File: FlexibleFileWriterTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testSampleOccurred_labels() throws IOException {
    System.out.println("sampleOccurred_labels");
    SampleResult res = new SampleResult();
    res.setResponseData("test".getBytes());
    FlexibleFileWriter instance = new FlexibleFileWriter();
    instance.setFilename(File.createTempFile("ffw_test_", ".txt").getAbsolutePath());
    instance.setColumns("threadName|\\t|sampleLabel");
    instance.testStarted();

    res.setSampleLabel("SAMPLELBL");
    res.setThreadName("THRDNAME");
    SampleEvent e = new SampleEvent(res, "Test");
    instance.sampleOccurred(e);
    //ByteBuffer written = instance.fileEmul.getWrittenBytes();
    //assertEquals(exp, JMeterPluginsUtils.byteBufferToString(written));

    instance.testEnded();
}
 
Example #18
Source File: AggregatedTypeUpdater.java    From jmeter-prometheus-plugin with Apache License 2.0 6 votes vote down vote up
protected long measure(SampleEvent event) {
	SampleResult result = event.getResult();
	switch(this.config.getMeasuringAsEnum()) {
	case ResponseSize:
		return result.getBodySizeAsLong();
	case ResponseTime:
		return result.getTime();
	case Latency:
		return result.getLatency();
	case IdleTime:
		return result.getIdleTime();
	case ConnectTime:
		return result.getConnectTime();
	default:
		return 0;
	}
}
 
Example #19
Source File: DebuggerDialogBase.java    From jmeter-debugger with Apache License 2.0 6 votes vote down vote up
public Component getLastSamplerResultTab() {
    lastSamplerResult = new ViewResultsFullVisualizer() {
        @Override
        public TestElement createTestElement() {
            this.collector = new ResultCollector() {
                @Override
                public void sampleOccurred(SampleEvent event) {
                    lastSamplerResult.clearData();
                    getVisualizer().add(event.getResult());
                }
            };
            this.modifyTestElement(this.collector);
            return collector;
        }
    };
    lastSamplerResult.setName("Last Sampler Result");
    try {
        Field mainSplitField = lastSamplerResult.getClass().getSuperclass().getDeclaredField("mainSplit");
        mainSplitField.setAccessible(true);
        return (Component) mainSplitField.get(lastSamplerResult);
    } catch (Throwable ex) {
        log.warn("Failed to find 'mainSplit' field in visualizer");
        return lastSamplerResult;
    }
}
 
Example #20
Source File: AbstractGraphPanelVisualizerTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testIncludeExcludeRegex_none() {
    CorrectedResultCollector instance = new CorrectedResultCollector();
    instance.setProperty(CorrectedResultCollector.INCLUDE_SAMPLE_LABELS,
            "P[0-9].*");
    instance.testStarted();
    DebugVisualizer vis = new DebugVisualizer();
    instance.setListener(vis);
    vis.configure(instance);

    vis.lastLabel = null;
    SampleResult res2 = new SampleResult();
    res2.setSampleLabel("P1_TEST");
    instance.sampleOccurred(new SampleEvent(res2, "tg"));
    assertNull(vis.lastLabel);
}
 
Example #21
Source File: AbstractDynamicThreadGroupModel.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
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 #22
Source File: DebuggerEngineTest.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
@Test
public void runVariablesInAssertions() throws Exception {
    TestProvider prov = new TestProvider("/com/blazemeter/jmeter/debugger/debug.jmx", "debug.jmx");

    Debugger sel = new Debugger(prov, new FrontendMock());
    AbstractThreadGroup tg = prov.getTG(0);
    sel.selectThreadGroup(tg);
    HashTree testTree = sel.getSelectedTree();

    TestSampleListener listener = new TestSampleListener();
    testTree.add(testTree.getArray()[0], listener);

    DebuggingThreadGroup tg2 = (DebuggingThreadGroup) getFirstTG(testTree);
    LoopController samplerController = (LoopController) tg2.getSamplerController();
    samplerController.setLoops(1);
    samplerController.setContinueForever(false);

    JMeter.convertSubTree(testTree);

    DebuggerEngine engine = new DebuggerEngine(JMeterContextService.getContext());
    StepTriggerCounter hook = new StepTriggerCounter();
    engine.setStepper(hook);
    engine.configure(testTree);
    engine.runTest();
    while (engine.isActive()) {
        Thread.sleep(1000);
    }
    assertEquals(4, hook.cnt);

    assertEquals(1, listener.events.size());
    SampleEvent event = listener.events.get(0);
    SampleResult result = event.getResult();
    AssertionResult[] assertionResults = result.getAssertionResults();
    assertEquals(1, assertionResults.length);

    AssertionResult assertionRes = assertionResults[0];
    assertNull(assertionRes.getFailureMessage());
}
 
Example #23
Source File: AutoStopTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
/**
 * Test of sampleStopped method, of class AutoStop.
 */
@Test
public void testSampleStopped() {
    System.out.println("sampleStopped");
    SampleEvent se = null;
    AutoStop instance = new AutoStop();
    instance.sampleStopped(se);
}
 
Example #24
Source File: MonitoringResultsCollector.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public void sampleOccurred(SampleEvent event) {
    // just dropping regular test samples
	
	// update JMeterContext for share with samplers thread in order to provide
	// updated variables
	this.ctx = JMeterContextService.getContext();
}
 
Example #25
Source File: ConsoleStatusLoggerTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
/**
 * Test of sampleStarted method, of class ConsoleStatusLogger.
 */
@Test
public void testSampleStarted() {
    System.out.println("sampleStarted");
    SampleEvent se = null;
    ConsoleStatusLogger instance = new ConsoleStatusLogger();
    instance.sampleStarted(se);
}
 
Example #26
Source File: CountTypeUpdaterTest.java    From jmeter-prometheus-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testTotalAssertions() {
	ListenerCollectorConfig cfg = TestUtilities.listenerCounterCfg(
			"count_assertion_total_test",
			Measurable.CountTotal,
			ListenerCollectorConfig.ASSERTIONS);
	
	Counter c = (Counter) reg.getOrCreateAndRegister(cfg);
	CountTypeUpdater u = new CountTypeUpdater(cfg);
	
	SampleResult result = newSampleResultWithAssertion(false);
	u.update(new SampleEvent(result,"tg1", vars()));	// #1
	double shouldBeOne = c.labels(TestUtilities.EXPECTED_ASSERTION_LABELS).get();
	Assert.assertEquals(1.0, shouldBeOne, 0.1);
	
	
	result = newSampleResultWithAssertion(true);
	u.update(new SampleEvent(result,"tg1", vars()));	// #2
	double shouldBeTwo = c.labels(TestUtilities.EXPECTED_ASSERTION_LABELS).get();
	Assert.assertEquals(2.0, shouldBeTwo, 0.1);
	
	// now update 2 assertions
	result = newSampleResultWithAssertion(false);
	result.addAssertionResult(altAssertion(false));
	u.update(new SampleEvent(result,"tg1", vars()));	// #3
	double shouldBeThree = c.labels(TestUtilities.EXPECTED_ASSERTION_LABELS).get();
	Assert.assertEquals(3.0, shouldBeThree, 0.1);
	shouldBeOne = c.labels(TestUtilities.EXPECTED_ASSERTION_LABELS_ALT).get();	//but alt is just 1
	Assert.assertEquals(1.0, shouldBeOne, 0.1);
}
 
Example #27
Source File: CountTypeUpdaterTest.java    From jmeter-prometheus-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testFailureAssertions() {
	ListenerCollectorConfig cfg = TestUtilities.listenerCounterCfg(
			"count_assertion_failure_test",
			Measurable.FailureTotal,
			ListenerCollectorConfig.ASSERTIONS);
	
	Counter c = (Counter) reg.getOrCreateAndRegister(cfg);
	CountTypeUpdater u = new CountTypeUpdater(cfg);
	
	SampleResult result = newSampleResultWithAssertion(false);
	u.update(new SampleEvent(result,"tg1", vars()));	// #1
	double shouldBeOne = c.labels(TestUtilities.EXPECTED_ASSERTION_LABELS).get();
	Assert.assertEquals(1.0, shouldBeOne, 0.1);
	
	
	result = newSampleResultWithAssertion(true);
	u.update(new SampleEvent(result,"tg1", vars()));	// #could be 2, but should be 1
	shouldBeOne = c.labels(TestUtilities.EXPECTED_ASSERTION_LABELS).get();
	Assert.assertEquals(1.0, shouldBeOne, 0.1);
	
	// now update 2 assertions
	result = newSampleResultWithAssertion(false);
	result.addAssertionResult(altAssertion(false));
	u.update(new SampleEvent(result,"tg1", vars()));	// #now should be 2
	double shouldBeTwo = c.labels(TestUtilities.EXPECTED_ASSERTION_LABELS).get();
	Assert.assertEquals(2.0, shouldBeTwo, 0.1);
	shouldBeOne = c.labels(TestUtilities.EXPECTED_ASSERTION_LABELS_ALT).get();	//but alt is just 1
	Assert.assertEquals(1.0, shouldBeOne, 0.1);		
}
 
Example #28
Source File: CountTypeUpdaterTest.java    From jmeter-prometheus-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testSuccessAssertions() {
	ListenerCollectorConfig cfg = TestUtilities.listenerCounterCfg(
			"count_assertion_success_test",
			Measurable.SuccessTotal,
			ListenerCollectorConfig.ASSERTIONS);
	
	Counter c = (Counter) reg.getOrCreateAndRegister(cfg);
	CountTypeUpdater u = new CountTypeUpdater(cfg);
	
	SampleResult result = newSampleResultWithAssertion(true);
	u.update(new SampleEvent(result,"tg1", vars()));	// #1
	double shouldBeOne = c.labels(TestUtilities.EXPECTED_ASSERTION_LABELS).get();
	Assert.assertEquals(1.0, shouldBeOne, 0.1);
	
	result = newSampleResultWithAssertion(false);
	u.update(new SampleEvent(result,"tg1", vars()));	// #could be 2, but should be 1
	shouldBeOne = c.labels(TestUtilities.EXPECTED_ASSERTION_LABELS).get();
	Assert.assertEquals(1.0, shouldBeOne, 0.1);
	
	// now update 2 assertions
	result = newSampleResultWithAssertion(true);
	result.addAssertionResult(altAssertion(true));
	u.update(new SampleEvent(result,"tg1", vars()));	// #now should be 2
	double shouldBeTwo = c.labels(TestUtilities.EXPECTED_ASSERTION_LABELS).get();
	Assert.assertEquals(2.0, shouldBeTwo, 0.1);
	shouldBeOne = c.labels(TestUtilities.EXPECTED_ASSERTION_LABELS_ALT).get();	//but alt is just 1
	Assert.assertEquals(1.0, shouldBeOne, 0.1);
}
 
Example #29
Source File: MonitoringResultsCollectorTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
/**
 * Test of monitoringSampleOccurred method, of class MonitoringResultsCollector.
 */
@Test
public void testMonitoringSampleOccurred() {
    System.out.println("monitoringSampleOccurred");
    SampleEvent event = new SampleEvent(new SampleResult(), "test");
    MonitoringResultsCollector instance = new MonitoringResultsCollector();
    instance.monitoringSampleOccurred(event);
    // TODO review the generated test code and remove the default call to fail.

}
 
Example #30
Source File: FlexibleFileWriter.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public void sampleOccurred(SampleEvent evt) {
    if (fileChannel == null || !fileChannel.isOpen()) {
        if (log.isWarnEnabled()) {
            log.warn("File writer is closed! Maybe test has already been stopped");
        }
        return;
    }

    ByteBuffer buf = ByteBuffer.allocateDirect(writeBufferSize);
    for (int n = 0; n < compiledConsts.length; n++) {
        if (compiledConsts[n] != null) {
            //noinspection SynchronizeOnNonFinalField
            synchronized (compiledConsts) {
                buf.put(compiledConsts[n].duplicate());
            }
        } else {
            if (!appendSampleResultField(buf, evt.getResult(), compiledFields[n])) {
                appendSampleVariable(buf, evt, compiledVars[n]);
            }
        }
    }

    buf.flip();

    try {
        syncWrite(buf);
    } catch (IOException ex) {
        log.error("Problems writing to file", ex);
    }
}