Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,21 @@ public List<Profile> getProfiles() {
public Profile getProfile(Context context, Element element) {
return new Profile(context, element, executions.get(context).get(element));
}

public static SimpleProfiler createFromExecutionPath(List<Execution> executionPath) {
SimpleProfiler profiler = new SimpleProfiler();
for (Execution execution : executionPath) {
Context context = execution.getContext();
if (!profiler.executions.containsKey(context)) {
profiler.executions.put(context, new HashMap<>());
}
Element element = execution.getElement();
if (!profiler.executions.get(context).containsKey(element)) {
profiler.executions.get(context).put(element, new ArrayList<>());
}
profiler.executionPath.add(execution);
profiler.executions.get(context).get(element).add(execution);
}
return profiler;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,18 @@
*/

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertThat;

import org.graphwalker.core.condition.EdgeCoverage;
import org.graphwalker.core.generator.RandomPath;
import org.graphwalker.core.model.*;
import org.graphwalker.core.statistics.Execution;
import org.graphwalker.core.statistics.SimpleProfiler;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -57,6 +61,37 @@ public void replayMachine() throws Exception {
assertThat(replayedPath, is(expectedPath));
}

@Test
public void replayMachineFromExecutionPath() {
Machine machine = createMachineExecution();
List<Execution> executionPath = new ArrayList<>(machine.getProfiler().getExecutionPath());
Machine replayMachine = new ReplayMachine(SimpleProfiler.createFromExecutionPath(executionPath));
while (replayMachine.hasNextStep()) {
replayMachine.getNextStep();
}
List<Element> expectedPath = machine.getProfiler().getExecutionPath().stream()
.map(Execution::getElement).collect(Collectors.toList());
List<Element> replayedPath = replayMachine.getProfiler().getExecutionPath().stream()
.map(Execution::getElement).collect(Collectors.toList());
assertEquals(expectedPath, replayedPath);
}

@Test
public void replayMachineFromAlteredExecutionPath() {
Machine machine = createMachineExecution();
List<Execution> executionPath = new ArrayList<>(machine.getProfiler().getExecutionPath());
executionPath.remove(executionPath.size() - 1);
Machine replayMachine = new ReplayMachine(SimpleProfiler.createFromExecutionPath(executionPath));
while (replayMachine.hasNextStep()) {
replayMachine.getNextStep();
}
List<Element> originalPath = machine.getProfiler().getExecutionPath().stream()
.map(Execution::getElement).collect(Collectors.toList());
List<Element> replayedPath = replayMachine.getProfiler().getExecutionPath().stream()
.map(Execution::getElement).collect(Collectors.toList());
assertNotEquals(originalPath, replayedPath);
}

private Machine createMachineExecution() {
Vertex vertex = new Vertex();
Edge edge1 = new Edge().setSourceVertex(vertex).setTargetVertex(vertex).addAction(new Action("flag = true;")).setName("edge1");
Expand Down