Skip to content
Merged
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 @@ -28,6 +28,7 @@

import org.graphwalker.core.statistics.Execution;
import org.graphwalker.core.statistics.Profiler;
import org.graphwalker.core.statistics.SimpleProfiler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -81,6 +82,8 @@ private void createContexts(Profiler profiler) {
try {
Context newContext = context.getClass().newInstance();
newContext.setModel(context.getModel());
newContext.setPathGenerator(context.getPathGenerator());
newContext.setProfiler(new SimpleProfiler());
contexts.put(context, newContext);
} catch (InstantiationException | IllegalAccessException e) {
LOG.error(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@ public class ReplayMachineTest {

@Test
public void replayMachine() throws Exception {
Machine machine = createMachineExecution();
compareMachineWithReplayMachine(createMachineExecution());
}

@Test
public void replayMultiModelMachine() throws Exception {
compareMachineWithReplayMachine(createMultiModelMachineExecution());
}

private void compareMachineWithReplayMachine(Machine machine) {
Machine replayMachine = new ReplayMachine(machine.getProfiler());
while (replayMachine.hasNextStep()) {
replayMachine.getNextStep();
Expand All @@ -70,4 +78,29 @@ private Machine createMachineExecution() {
}
return machine;
}

private Machine createMultiModelMachineExecution() {
Vertex vertex1 = new Vertex();
vertex1.setName("vertex1");
vertex1.setSharedState("sharedState");
Edge edge1a = new Edge().setSourceVertex(vertex1).setTargetVertex(vertex1).addAction(new Action("flag = true;")).setName("edge1a");
Edge edge1b = new Edge().setSourceVertex(vertex1).setTargetVertex(vertex1).setGuard(new Guard("flag === true")).setName("edge1b");
Model model1 = new Model().addEdge(edge1a).addEdge(edge1b).addAction(new Action("var flag = false;"));
Context context1 = new TestExecutionContext(model1, new RandomPath(new EdgeCoverage(100)));
context1.setNextElement(vertex1);

Vertex vertex2 = new Vertex();
vertex2.setName("vertex2");
vertex2.setSharedState("sharedState");
Edge edge2a = new Edge().setSourceVertex(vertex2).setTargetVertex(vertex2).addAction(new Action("flag = true;")).setName("edge2a");
Edge edge2b = new Edge().setSourceVertex(vertex2).setTargetVertex(vertex2).setGuard(new Guard("flag === true")).setName("edge2b");
Model model2 = new Model().addEdge(edge2a).addEdge(edge2b).addAction(new Action("var flag = false;"));
Context context2 = new TestExecutionContext(model2, new RandomPath(new EdgeCoverage(100)));

Machine machine = new SimpleMachine(context1, context2);
while (machine.hasNextStep()) {
machine.getNextStep();
}
return machine;
}
}