Skip to content

Commit

Permalink
Fixed sub results labels for JMeter 5.0 (Blazemeter#70)
Browse files Browse the repository at this point in the history
* Fixed sub results labels for JMeter 5.0

* add test
  • Loading branch information
Artem Fedorov authored and undera committed Nov 8, 2018
1 parent fc35ff9 commit 2d29603
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
2 changes: 1 addition & 1 deletion parallel/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.blazemeter</groupId>
<artifactId>jmeter-parallel</artifactId>
<version>0.7</version>
<version>0.8</version>
<name>Parallel Sampling for JMeter</name>
<description>Parallel Sampling for JMeter</description>
<licenses>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ public class ParallelListenerNotifier extends ListenerNotifier implements Serial
@Override
public void notifyListeners(SampleEvent res, List<SampleListener> listeners) {
log.debug("Adding subresult " + res.getResult());
SampleResult result = res.getResult();
String label = result.getSampleLabel();
synchronized (this) {
container.addSubResult(res.getResult());
container.addSubResult(result);
if (!res.getResult().isSuccessful()) {
container.setSuccessful(false);
}
}
// because https://bz.apache.org/bugzilla/show_bug.cgi?id=62550 in JMeter 5.0
result.setSampleLabel(label);
super.notifyListeners(res, listeners);
log.debug("Added subresult " + res.getResult());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.blazemeter.jmeter.controller;

import org.apache.jmeter.samplers.SampleEvent;
import org.apache.jmeter.samplers.SampleListener;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.testelement.AbstractTestElement;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.assertEquals;

public class ParallelListenerNotifierTest {

@Test
public void testSubResultsLabels() {
ParallelListenerNotifier notifier = new ParallelListenerNotifier();
SampleResult container = new SampleResult() {
@Override
public void addSubResult(SampleResult subResult) {
// generate JMeter 5.0 behaviour
// https://bz.apache.org/bugzilla/show_bug.cgi?id=62550
subResult.setSampleLabel("new Label");
}
};


notifier.setContainer(container);

SampleResult subSampler = new SampleResult();
subSampler.setSampleLabel("label");

SampleListenerExt sampleListenerExt = new SampleListenerExt();
List<SampleListener> list = new ArrayList<>();
list.add(sampleListenerExt);


notifier.notifyListeners(new SampleEvent(subSampler, ""), list);
assertEquals("label", subSampler.getSampleLabel());
assertEquals(1, sampleListenerExt.count);
}

private static class SampleListenerExt extends AbstractTestElement implements SampleListener {
int count = 0;
@Override
public void sampleOccurred(SampleEvent sampleEvent) {
assertEquals("label", sampleEvent.getResult().getSampleLabel());
count++;
}

@Override
public void sampleStarted(SampleEvent sampleEvent) {

}

@Override
public void sampleStopped(SampleEvent sampleEvent) {

}
}


}

0 comments on commit 2d29603

Please sign in to comment.