Skip to content

Commit 20a50c4

Browse files
jvangaalenvlsi
authored andcommitted
Clear transaction from subresults
1 parent 12f8439 commit 20a50c4

File tree

4 files changed

+17
-117
lines changed

4 files changed

+17
-117
lines changed

src/core/src/main/java/org/apache/jmeter/samplers/SampleResult.java

Lines changed: 2 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,9 @@
3030
import java.util.concurrent.TimeUnit;
3131

3232
import org.apache.jmeter.assertions.AssertionResult;
33-
import org.apache.jmeter.control.TransactionSampler;
3433
import org.apache.jmeter.gui.Searchable;
3534
import org.apache.jmeter.testelement.TestPlan;
36-
import org.apache.jmeter.threads.JMeterContext;
3735
import org.apache.jmeter.threads.JMeterContext.TestLogicalAction;
38-
import org.apache.jmeter.threads.JMeterContextService;
3936
import org.apache.jmeter.util.JMeterUtils;
4037
import org.apache.jorphan.util.JOrphanUtils;
4138
import org.apache.jorphan.util.StringUtilities;
@@ -67,15 +64,10 @@ public class SampleResult implements Serializable, Cloneable, Searchable {
6764
private static final String INVALID_CALL_SEQUENCE_MSG = "Invalid call sequence"; // $NON-NLS-1$
6865

6966

70-
// Bug 33196 - encoding ISO-8859-1 is only suitable for Western countries
71-
// However the suggested System.getProperty("file.encoding") is Cp1252 on
72-
// Windows
73-
// So use a new property with the original value as default
74-
// needs to be accessible from test code
7567
/**
7668
* The default encoding to be used to decode the responseData byte array.
7769
* The value is defined by the property "sampleresult.default.encoding"
78-
* with a default of DEFAULT_HTTP_ENCODING if that is not defined.
70+
* with a default of {@link #DEFAULT_HTTP_ENCODING} if that is not defined.
7971
*/
8072
protected static final String DEFAULT_ENCODING
8173
= JMeterUtils.getPropDefault("sampleresult.default.encoding", // $NON-NLS-1$
@@ -1603,62 +1595,10 @@ public void setStartNextThreadLoop(boolean startNextThreadLoop) {
16031595
}
16041596

16051597
/**
1606-
* Clean up cached data, but only if this is a root result (no parent)
1607-
* and not part of a parent transaction.
1598+
* Clean up cached data
16081599
*/
16091600
public void cleanAfterSample() {
1610-
// Only clean if this is a root result (no parent)
1611-
if (parent != null) {
1612-
return;
1613-
}
1614-
1615-
// Check if we're part of a parent transaction by walking up the sampler hierarchy
1616-
JMeterContext context = JMeterContextService.getContext();
1617-
if (context != null) {
1618-
Sampler currentSampler = context.getCurrentSampler();
1619-
if (currentSampler instanceof TransactionSampler) {
1620-
TransactionSampler transSampler = (TransactionSampler) currentSampler;
1621-
// Get the parent sampler from the transaction
1622-
Sampler parentSampler = transSampler.getSubSampler();
1623-
// If there's a parent sampler and it's a transaction, we're nested
1624-
if (parentSampler instanceof TransactionSampler) {
1625-
return;
1626-
}
1627-
}
1628-
}
1629-
1630-
cleanRecursively();
1631-
}
1632-
1633-
/**
1634-
* Internal method to clean this result and all its sub-results
1635-
*/
1636-
private void cleanRecursively() {
1637-
// Clean sub-results first
1638-
if (subResults != null) {
1639-
for (SampleResult subResult : subResults) {
1640-
if (subResult != null) {
1641-
subResult.cleanRecursively();
1642-
}
1643-
}
1644-
subResults.clear();
1645-
subResults = null;
1646-
}
1647-
1648-
// Clean assertion results
1649-
if (assertionResults != null) {
1650-
assertionResults.clear();
1651-
assertionResults = null;
1652-
}
1653-
1654-
// Clear only memory-heavy data and caches, preserve samplerData
1655-
this.parent = null;
16561601
this.responseDataAsString = null;
1657-
this.responseData = EMPTY_BA;
1658-
this.responseHeaders = "";
1659-
this.requestHeaders = "";
1660-
this.samplerData = null;
1661-
16621602
}
16631603

16641604
@Override
@@ -1726,50 +1666,4 @@ public TestLogicalAction getTestLogicalAction() {
17261666
public void setTestLogicalAction(TestLogicalAction testLogicalAction) {
17271667
this.testLogicalAction = testLogicalAction;
17281668
}
1729-
1730-
/**
1731-
* Create a deep copy for async listeners
1732-
* @return A deep copy of this result
1733-
*/
1734-
public SampleResult cloneForListeners() {
1735-
// Create clone with the correct type
1736-
SampleResult clone;
1737-
try {
1738-
// Use the same constructor that was used to create this instance
1739-
clone = this.getClass().getConstructor(this.getClass()).newInstance(this);
1740-
} catch (Exception e) {
1741-
// Fallback to base class if constructor is not available
1742-
log.debug("Could not create clone with type: " + this.getClass().getName() + ", using base class", e);
1743-
clone = new SampleResult(this);
1744-
}
1745-
1746-
// Deep copy mutable fields that the copy constructor doesn't handle deeply
1747-
if (responseData != EMPTY_BA) {
1748-
clone.responseData = responseData.clone();
1749-
}
1750-
1751-
// Deep copy subResults
1752-
if (subResults != null) {
1753-
clone.subResults = new ArrayList<>(subResults.size());
1754-
for (SampleResult sub : subResults) {
1755-
SampleResult subClone = sub.cloneForListeners();
1756-
subClone.setParent(clone);
1757-
clone.subResults.add(subClone);
1758-
}
1759-
}
1760-
1761-
// Deep copy assertion results
1762-
if (assertionResults != null) {
1763-
clone.assertionResults = new ArrayList<>(assertionResults.size());
1764-
for (AssertionResult assertionResult : assertionResults) {
1765-
clone.assertionResults.add(assertionResult); // AssertionResult is immutable
1766-
}
1767-
}
1768-
1769-
// Clear only the caches and unnecessary references in the clone
1770-
clone.responseDataAsString = null;
1771-
clone.parent = null; // Parent reference not needed in the clone
1772-
1773-
return clone;
1774-
}
17751669
}

src/core/src/main/java/org/apache/jmeter/threads/JMeterThread.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -672,12 +672,6 @@ private SampleResult doEndTransactionSampler(
672672
notifyListeners(transactionPack.getSampleListeners(), transactionResult);
673673
}
674674
compiler.done(transactionPack);
675-
676-
// Clean up the transaction result after listeners have processed it
677-
if (transactionResult != null) {
678-
transactionResult.cleanAfterSample();
679-
}
680-
681675
return transactionResult;
682676
}
683677

@@ -1034,7 +1028,7 @@ void notifyTestListeners() {
10341028
}
10351029

10361030
private void notifyListeners(List<SampleListener> listeners, SampleResult result) {
1037-
SampleEvent event = new SampleEvent(result.cloneForListeners(), threadGroup.getName(), threadVars);
1031+
SampleEvent event = new SampleEvent(result, threadGroup.getName(), threadVars);
10381032
notifier.notifyListeners(event, listeners);
10391033
}
10401034

src/core/src/main/java/org/apache/jmeter/threads/TestCompiler.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,21 @@ public SamplePackage configureTransactionSampler(TransactionSampler transactionS
115115
}
116116

117117
/**
118-
* Reset pack to its initial state
118+
* Reset pack to its initial state and clean up transaction results if needed
119119
* @param pack the {@link SamplePackage} to reset
120120
*/
121121
public void done(SamplePackage pack) {
122+
Sampler sampler = pack.getSampler();
123+
if (sampler instanceof TransactionSampler) {
124+
TransactionSampler transactionSampler = (TransactionSampler) sampler;
125+
TransactionController controller = transactionSampler.getTransactionController();
126+
if (transactionSampler.isTransactionDone()) {
127+
// Create new sampler for next iteration
128+
TransactionSampler newSampler = new TransactionSampler(controller, transactionSampler.getName());
129+
SamplePackage newPack = transactionControllerConfigMap.get(controller);
130+
newPack.setSampler(newSampler);
131+
}
132+
}
122133
pack.recoverRunningVersion();
123134
}
124135

src/dist-check/src/test/java/org/apache/jmeter/junit/JMeterTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,8 @@ static Stream<Serializable> serializableObjects() throws Throwable {
581581
return getObjects(Serializable.class)
582582
.stream()
583583
.map(Serializable.class::cast)
584-
.filter(o -> !o.getClass().getName().endsWith("_Stub"));
584+
.filter(o -> !o.getClass().getName().endsWith("_Stub"))
585+
.filter(o -> o.getClass().getName().startsWith("org.apache.jmeter."));
585586
}
586587

587588
/**

0 commit comments

Comments
 (0)