Skip to content

Commit

Permalink
Fix logic to disconnect RTE connections only once per thread group it…
Browse files Browse the repository at this point in the history
…eration

iterationStart method is invoked once for each sampler in each controller (thread group, loop controller, if controller, etc) start. To avoid disconnecting RTE when for example an RTE sampler is included in an IF controller, and to avoid unnecessary
calls, we only reset connection when the sampler is the first sampler in the thread group iteration.
  • Loading branch information
rabelenda-abstracta committed Jul 27, 2018
1 parent c2e243b commit a2e33f8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>com.blazemeter.jmeter</groupId>
<artifactId>jmeter-bzm-rte</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<version>1.0.1</version>
<name>RTEPlugin Sampler as JMeter plugin</name>

<properties>
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/com/blazemeter/jmeter/rte/sampler/RTESampler.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.jmeter.testelement.ThreadListener;
import org.apache.jmeter.testelement.property.JMeterProperty;
import org.apache.jmeter.testelement.property.TestElementProperty;
import org.apache.jmeter.threads.JMeterVariables;
import org.apache.jmeter.util.JMeterUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -616,9 +617,21 @@ private void closeConnections() {

@Override
public void iterationStart(LoopIterationEvent loopIterationEvent) {
if (!isReuseConnections()) {
if (!isReuseConnections() && isFirstRteSamplerInLoop()) {
closeConnections();
}
}

private boolean isFirstRteSamplerInLoop() {
JMeterVariables vars = getThreadContext().getVariables();
Integer currentThreadIteration = vars.getIteration();
String rteIterationVarName = "RTESampler.iteration";
Integer lastRteSamplerIteration = (Integer) vars.getObject(rteIterationVarName);
if (!currentThreadIteration.equals(lastRteSamplerIteration)) {
vars.putObject(rteIterationVarName, currentThreadIteration);
return true;
}
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -93,6 +94,7 @@ public void setup() {
createDefaultRTEConfig();
rteSampler.addTestElement(configTestElement);
rteSampler.setPayload(createInputs());
rteSampler.getThreadContext().getVariables().incIteration();
}

private void createDefaultRTEConfig() {
Expand Down Expand Up @@ -323,6 +325,17 @@ private void connectClient() {
sampler.sample(null);
}

@Test
public void shouldNotDisconnectEmulatorWhenIterationStartAndIterationHasNotChanged()
throws Exception {
rteSampler.sample(null);
rteSampler.iterationStart(null);
reset(rteProtocolClientMock);
rteSampler.sample(null);
rteSampler.iterationStart(null);
verify(rteProtocolClientMock, never()).disconnect();
}

@Test
public void shouldGetDisconnectActionResultWhenSampleWithDisconnectAction() {
connectClient();
Expand Down

0 comments on commit a2e33f8

Please sign in to comment.