Skip to content

Commit

Permalink
Release 2.4 (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
diego-ferrand authored Apr 15, 2024
1 parent fd7131e commit 112aa9c
Show file tree
Hide file tree
Showing 46 changed files with 1,736 additions and 246 deletions.
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>com.blazemeter</groupId>
<artifactId>jmeter-bzm-correlation-recorder</artifactId>
<packaging>jar</packaging>
<version>2.3</version>
<version>2.4</version>
<name>Correlation Recorder as JMeter plugin</name>
<description>Correlation Recorder Plugin for JMeter</description>
<url>https://github.com/Blazemeter/CorrelationRecorder</url>
Expand Down Expand Up @@ -92,6 +92,12 @@
<version>2.13.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.9.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public static List<CorrelationSuggestion> generateCorrelationSuggestions() {
}

if (part instanceof CorrelationExtractor) {
RegexCorrelationExtractor<?> extractor = (RegexCorrelationExtractor<?>) part;
CorrelationExtractor<?> extractor = (CorrelationExtractor<?>) part;
for (ReportEntry entry : report.entries) {
ExtractionSuggestion extraction = new ExtractionSuggestion(extractor, entry.getSampler());
extraction.setValue(entry.value);
Expand All @@ -161,7 +161,7 @@ public static List<CorrelationSuggestion> generateCorrelationSuggestions() {
suggestion.addExtractionSuggestion(extraction);
}
} else {
RegexCorrelationReplacement<?> replacement = (RegexCorrelationReplacement<?>) part;
CorrelationReplacement<?> replacement = (CorrelationReplacement<?>) part;
for (ReportEntry entry : report.entries) {
ReplacementSuggestion replacementSuggestion
= new ReplacementSuggestion(replacement,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class CorrelationHistory {
public static final String AUXILIARY_STEP_MESSAGE =
"Auxiliary Iterarion (No Recording iteration found)";
public static final String ORIGINAL_RECORDING_MESSAGE = "Original Recording";
public static final String CUSTOM_ITERATION_MESSAGE = "Checkpoint Iteration";

public static final String FAILED_REPLAY_MESSAGE =
"Replay result: %s requests pending resolution.";
public static final String SUCCESS_REPLAY_TEMPLATE = "Replay %s";
Expand Down Expand Up @@ -69,8 +71,21 @@ public void addOriginalRecordingStep(String originalRecordingFilepath,

steps = new ArrayList<>();
Step step = new Step(ORIGINAL_RECORDING_MESSAGE);
step.setTestPlanFilepath(originalRecordingFilepath);
step.setRecordingTraceFilepath(originalRecordingTraceFilepath);
step.setTestPlanFilepath(
FileManagementUtils.getRelativeFatherPath(originalRecordingFilepath));
step.setRecordingTraceFilepath(
FileManagementUtils.getRelativeFatherPath(originalRecordingTraceFilepath));
step.setNotes("Automatically generated iteration after recording");
addStep(step);
}

public void addCustomIteration() {
Step step = new Step(CUSTOM_ITERATION_MESSAGE);
step.setTestPlanFilepath(
FileManagementUtils.getRelativeFatherPath(saveCurrentTestPlanSupplier.get()));
step.setRecordingTraceFilepath(
FileManagementUtils.getRelativeFatherPath(recordingFilePathSupplier.get()));
step.setNotes("Checkpoint generated by user. [Double click to edit]");
addStep(step);
}

Expand All @@ -80,8 +95,11 @@ public void addSuccessfulReplay(String testPlanFilepath, String replayTraceFilep
(hadErrors ? SUCCESS_REPLAY_POSTFIX_WITH_ERRORS
: SUCCESS_REPLAY_POSTFIX_WITHOUT_ERRORS)));

step.setTestPlanFilepath(testPlanFilepath);
step.setReplayTraceFilepath(replayTraceFilepath);
step.setTestPlanFilepath(
FileManagementUtils.getRelativeFatherPath(testPlanFilepath));
step.setReplayTraceFilepath(
FileManagementUtils.getRelativeFatherPath(replayTraceFilepath));
step.setNotes("Automatically generated iteration after replay");
addStep(step);
}

Expand All @@ -97,15 +115,23 @@ public List<Step> getSteps() {
public void addFailedReplay(String testPlanFilepath, String replayTraceFilepath,
Integer newErrors) {
Step step = new Step(String.format(FAILED_REPLAY_MESSAGE, newErrors));
step.setTestPlanFilepath(testPlanFilepath);
step.setReplayTraceFilepath(replayTraceFilepath);

step.setTestPlanFilepath(
FileManagementUtils.getRelativeFatherPath(testPlanFilepath));
step.setReplayTraceFilepath(
FileManagementUtils.getRelativeFatherPath(replayTraceFilepath));
step.setNotes("Automatically generated iteration after replay");

addStep(step);
}

public void addAnalysisStep(String message, String testPlanFilepath, String traceFilepath) {
Step step = new Step(message);
step.setTestPlanFilepath(testPlanFilepath);
step.setReplayTraceFilepath(traceFilepath);
step.setTestPlanFilepath(
FileManagementUtils.getRelativeFatherPath(testPlanFilepath));
step.setReplayTraceFilepath(
FileManagementUtils.getRelativeFatherPath(traceFilepath));
step.setNotes("Automatically generated iteration after correlation suggestions application");
addStep(step);
}

Expand All @@ -131,8 +157,10 @@ public Step getRecordingStep() {
if (steps.isEmpty()) {
LOG.error("CorrelationHistory has no iterations, forcing an auxiliary iteartion");
Step auxiliaryStep = new Step(AUXILIARY_STEP_MESSAGE);
auxiliaryStep.setTestPlanFilepath(saveCurrentTestPlanSupplier.get());
auxiliaryStep.setRecordingTraceFilepath(recordingFilePathSupplier.get());
auxiliaryStep.setTestPlanFilepath(
FileManagementUtils.getRelativeFatherPath(saveCurrentTestPlanSupplier.get()));
auxiliaryStep.setRecordingTraceFilepath(
FileManagementUtils.getRelativeFatherPath(recordingFilePathSupplier.get()));
addStep(auxiliaryStep);
}
return steps.get(0);
Expand Down Expand Up @@ -194,11 +222,11 @@ public void deleteSteps(List<Step> steps) {
}

public void addRestoredStep(Step step) {
Step newStep = new Step(
"Restored iteration with timestamp: %s", step.getTimestamp());
Step newStep = new Step("Restored iteration");
newStep.setTestPlanFilepath(step.getTestPlanFilepath());
newStep.setRecordingTraceFilepath(step.getRecordingTraceFilepath());
newStep.setReplayTraceFilepath(step.getReplayTraceFilepath());
newStep.setNotes("Reverted to the iteration with timestamp: " + step.getTimestamp());
this.steps.add(newStep);
saveToFile();
}
Expand Down Expand Up @@ -278,6 +306,7 @@ public static class Step {
private String replayTraceFilepath;
private String timestamp;
private String fatherTimeStamp = null;
private String notes;

@JsonIgnore
private Supplier<String> saveCurrentTestPlanSupplier = saveCurrentTestPlan();
Expand Down Expand Up @@ -309,6 +338,14 @@ public String getStepMessage() {
return String.format(stepMessage, msgEnd);
}

public String getNotes() {
return notes;
}

public void setNotes(String notes) {
this.notes = notes;
}

@VisibleForTesting
public void setStepMessage(String stepMessage) {
this.stepMessage = stepMessage;
Expand Down Expand Up @@ -343,7 +380,8 @@ public void setReplayTraceFilepath(String replayTraceFilepath) {
}

public void addCurrentTestPlan() {
setTestPlanFilepath(saveCurrentTestPlanSupplier.get());
setTestPlanFilepath(
FileManagementUtils.getRelativeFatherPath(saveCurrentTestPlanSupplier.get()));
}

public String getTimestamp() {
Expand All @@ -367,6 +405,7 @@ public String toString() {
", replayTraceFilepath='" + replayTraceFilepath + '\'' +
", time='" + timestamp + '\'' +
", fatherTimestamp='" + fatherTimeStamp + '\'' +
", notes='" + notes + '\'' +
'}';
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ExtractionSuggestion {
private List<CorrelationExtractor<?>> extractors = new ArrayList<>();

//TODO:Remove the single extractor and only use the list
private RegexCorrelationExtractor<?> extractor;
private CorrelationExtractor<?> extractor;
private SampleResult sampleResult;
private String value;
private String name;
Expand All @@ -25,18 +25,13 @@ public ExtractionSuggestion(CorrelationExtractor<?> extractors, SampleResult sam
this.sampleResult = sampleResult;
}

public ExtractionSuggestion(RegexCorrelationExtractor<?> extractor, SampleResult sampleResult) {
this.extractor = extractor;
this.sampleResult = sampleResult;
}

public ExtractionSuggestion(RegexCorrelationExtractor<?> extractor, HTTPSamplerBase sampler) {
public ExtractionSuggestion(CorrelationExtractor<?> extractor, HTTPSamplerBase sampler) {
this.extractor = extractor;
this.sampler = sampler;
this.comesFromSampleResult = false;
}

public RegexCorrelationExtractor<?> getExtractor() {
public CorrelationExtractor<?> getExtractor() {
return extractor;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ private static void makeFolderAtBin(String name) {
private static Path getPathInBin(String name) {
return Paths.get(JMeterUtils.getJMeterBinDir(), name);
}

public static String getRelativeFatherPath(String fullPathStr) {
Path fullPath = Paths.get(fullPathStr);
return fullPath.getParent().toString() + File.separator +
fullPath.getFileName().toString();
}

public static void makeReplayResultsFolder() {
makeFolderAtBin(REPLAY_FOLDER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.blazemeter.jmeter.correlation.CorrelationProxyControl;
import com.helger.commons.annotation.VisibleForTesting;
import com.jayway.jsonpath.InvalidPathException;
import com.jayway.jsonpath.JsonPath;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
Expand Down Expand Up @@ -155,7 +157,7 @@ public static String saveTestPlanConverted(HashTree testPlan, String name) {
try {
convertSubTree(testPlan);
SaveService.saveTree(testPlan,
Files.newOutputStream(Paths.get(name)));
Files.newOutputStream(Paths.get(name)));
LOG.info("Test Plan's Snapshot saved to {}", name);
return name;
} catch (IOException e) {
Expand All @@ -166,7 +168,7 @@ public static String saveTestPlanConverted(HashTree testPlan, String name) {

public static String saveTestPlanSnapshot() {
return saveTestPlanConverted(getTreeModel().getTestPlan(),
FileManagementUtils.getSnapshotFileName());
FileManagementUtils.getSnapshotFileName());
}

public static String saveTestPlan(HashTree testPlan, String filename) {
Expand Down Expand Up @@ -241,7 +243,7 @@ private boolean isIgnoredHeader(String key) {
return configuration.getIgnoredHeaders().stream().anyMatch(key::equalsIgnoreCase);
}

static boolean isJson(String value) {
public static boolean isJson(String value) {
try {
new JSONObject(value);
} catch (JSONException ex) {
Expand Down Expand Up @@ -466,6 +468,73 @@ public void extractParametersFromJsonArray(JSONArray array, Map<String,
}
}

public static boolean canBeString(Object value) {
return value instanceof String || value instanceof Boolean || value instanceof Integer
|| value instanceof Float || value instanceof Double || value instanceof Long;
}

public static boolean classIsNumberOrBoolean(Class toClass) {
return toClass.equals(Boolean.class)
|| toClass.equals(Integer.class)
|| toClass.equals(Float.class)
|| toClass.equals(Double.class)
|| toClass.equals(Long.class);
}

public static String toJsonString(Object value) {
if (value instanceof net.minidev.json.JSONArray) {
return ((net.minidev.json.JSONArray) value).toJSONString();
} else if (value instanceof String) {
return (String) value;
} else if (canBeString(value)) {
return value.toString();
} else {
return null;
}
}

public static Object getJsonValue(String jsonpath, String input) {
Object value = null;
try {
value = JsonPath.read(input, jsonpath);
} catch (InvalidPathException e) {
// JsonPath use exception when jsonpath does not match
// Remember, If the match does not occur it does not matter
// Only those places when matches, the value matched is what matter.
// The evaluation is over all the fields of all request, take care about add log error here
}
return value;
}

public static Pair<Class, ArrayList<String>> jsonFindMatches(String input, String jsonpath) {
Object result = null;
ArrayList<String> matches = new ArrayList<>();
try {
result = JsonPath.read(input, jsonpath);
} catch (InvalidPathException e) {
// When no match, no report error, only no return any data
}
if (result == null) {
return Pair.of(null, matches);
} else if (result instanceof net.minidev.json.JSONArray) {
net.minidev.json.JSONArray results = (net.minidev.json.JSONArray) result;
for (Object value : results) {
matches.add(toJsonString(value));
}
} else if (canBeString(result)) {
matches.add(toJsonString(result));
} else if (result instanceof Map) {
LOG.warn(
"Valued returned by JSONPath is a json object and not a text value, " +
"return value is null");
return Pair.of(result.getClass(), matches);
} else {
LOG.warn(
"Valued returned by JSONPath is not supported, return value is null");
}
return Pair.of(result != null ? result.getClass() : null, matches);
}

/**
* Obtains the HTTPArgument from a JMeterProperty element.
* Note: this method requires that the JMeterProperty is an instance of HTTPArgument.
Expand Down Expand Up @@ -639,7 +708,7 @@ public static void refreshJMeter() {
*
* @param path The file path of the JMeter test plan to load.
* @return A HashTree representing the structure of the loaded JMeter test plan.
* If an error occurs during loading, this method will return null.
* If an error occurs during loading, this method will return null.
*/
public static HashTree getTestPlan(String path) {
HashTree hashTree = new HashTree();
Expand Down Expand Up @@ -1105,9 +1174,9 @@ private static List<JMeterTreeNode> getCorrelationProxyControllers(JMeterTreeMod
}

/*
* Reminder: This method is not properly working (or at least the generated nodes
* are not properly working)
* */
* Reminder: This method is not properly working (or at least the generated nodes
* are not properly working)
* */
public static List<JMeterTreeNode> getSamplerNodes(HashTree testPlan) {
/*
Reminder: We commented this code because we have the theory that
Expand Down Expand Up @@ -1139,4 +1208,5 @@ public static JMeterTreeModel getCurrentJMeterTreeModel() {
}
return model;
}

}
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package com.blazemeter.jmeter.correlation.core.automatic;

import com.blazemeter.jmeter.correlation.core.replacements.RegexCorrelationReplacement;
import com.blazemeter.jmeter.correlation.core.replacements.CorrelationReplacement;
import org.apache.jmeter.testelement.TestElement;

public class ReplacementSuggestion {
private final RegexCorrelationReplacement<?> replacementSuggestion;
private final CorrelationReplacement<?> replacementSuggestion;
private final TestElement usage;
private String source;
private String value;
private String name;

public ReplacementSuggestion(RegexCorrelationReplacement<?> replacementSuggestion,
public ReplacementSuggestion(CorrelationReplacement<?> replacementSuggestion,
TestElement usage) {
this.replacementSuggestion = replacementSuggestion;
this.usage = usage;
}

public RegexCorrelationReplacement<?> getReplacementSuggestion() {
public CorrelationReplacement<?> getReplacementSuggestion() {
return replacementSuggestion;
}

Expand Down
Loading

0 comments on commit 112aa9c

Please sign in to comment.