Skip to content

Commit

Permalink
Merge pull request #94 from OctoPerf/master
Browse files Browse the repository at this point in the history
Fix: parallel sampler plugin is broken in JMeter 5.6.x
  • Loading branch information
Baraujo25 authored Mar 14, 2024
2 parents d06a552 + da0f781 commit 19fa282
Showing 1 changed file with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Objects;

public class JMeterThreadParallel extends JMeterThread {
private static final Logger log = LoggerFactory.getLogger(ParallelSampler.class);
Expand Down Expand Up @@ -37,16 +40,30 @@ protected void copyCompilerFromParent() throws IllegalAccessException, NoSuchFie
field.set(this, parallelCompiler);
}

private TestCompilerParallel cloneTestCompiler(TestCompiler parent) throws NoSuchFieldException, IllegalAccessException {
TestCompilerParallel cloned = new TestCompilerParallel(new HashTree(), generateParent);
private TestCompilerParallel cloneTestCompiler(final TestCompiler parent) throws NoSuchFieldException, IllegalAccessException {
final TestCompilerParallel cloned = new TestCompilerParallel(new HashTree(), generateParent);

Field samplerConfigMap = TestCompiler.class.getDeclaredField("samplerConfigMap");
samplerConfigMap.setAccessible(true);
samplerConfigMap.set(cloned, ((HashMap) (samplerConfigMap.get(parent))).clone());
final Field samplerConfigMapField = TestCompiler.class.getDeclaredField("samplerConfigMap");
samplerConfigMapField.setAccessible(true);

Field transactionControllerConfigMap = TestCompiler.class.getDeclaredField("transactionControllerConfigMap");
transactionControllerConfigMap.setAccessible(true);
transactionControllerConfigMap.set(cloned, ((HashMap) (transactionControllerConfigMap.get(parent))).clone());
final Field transactionControllerConfigMapField = TestCompiler.class.getDeclaredField("transactionControllerConfigMap");
transactionControllerConfigMapField.setAccessible(true);

final Map<?, ?> sampleConfigMap;
final Map<?, ?> transactionMap;

if (Objects.equals(IdentityHashMap.class, samplerConfigMapField.getType())) {
// JMeter >= 5.6
sampleConfigMap = new IdentityHashMap<>((Map<?, ?>) samplerConfigMapField.get(parent));
transactionMap = new IdentityHashMap((Map<?, ?>) transactionControllerConfigMapField.get(parent));
} else {
// Backward compatibility with JMeter <= 5.5
sampleConfigMap = new HashMap<>((Map<?, ?>) samplerConfigMapField.get(parent));
transactionMap = new HashMap<>((Map<?, ?>) transactionControllerConfigMapField.get(parent));
}

samplerConfigMapField.set(cloned, sampleConfigMap);
transactionControllerConfigMapField.set(cloned, transactionMap);

return cloned;
}
Expand Down

0 comments on commit 19fa282

Please sign in to comment.