From e6f4a3333537487c0b76a3f9e9248e90757ad740 Mon Sep 17 00:00:00 2001 From: Magnus Teekivi Date: Thu, 15 Apr 2021 12:56:17 +0300 Subject: [PATCH 1/2] Add replayMultiModelMachine test exposing a bug Currently, executing ReplayMachine with a multi-model machine runs into this error as soon as the execution leaves the initial model: org.graphwalker.core.machine.MachineException: No path generator is defined --- .../core/machine/ReplayMachineTest.java | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/graphwalker-core/src/test/java/org/graphwalker/core/machine/ReplayMachineTest.java b/graphwalker-core/src/test/java/org/graphwalker/core/machine/ReplayMachineTest.java index fc97e041a..2581767ea 100644 --- a/graphwalker-core/src/test/java/org/graphwalker/core/machine/ReplayMachineTest.java +++ b/graphwalker-core/src/test/java/org/graphwalker/core/machine/ReplayMachineTest.java @@ -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(); @@ -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; + } } From 534121ce23bd2b5e17e9323727aa3595829ff5ed Mon Sep 17 00:00:00 2001 From: Magnus Teekivi Date: Thu, 15 Apr 2021 14:47:38 +0300 Subject: [PATCH 2/2] Fix error when executing multi-model ReplayMachine Prior to this commit, executing a multi-model ReplayMachine ran into the following error as soon as the execution left the first model: org.graphwalker.core.machine.MachineException: No path generator is defined --- .../main/java/org/graphwalker/core/machine/ReplayMachine.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/graphwalker-core/src/main/java/org/graphwalker/core/machine/ReplayMachine.java b/graphwalker-core/src/main/java/org/graphwalker/core/machine/ReplayMachine.java index a9b45e897..a615a56c6 100644 --- a/graphwalker-core/src/main/java/org/graphwalker/core/machine/ReplayMachine.java +++ b/graphwalker-core/src/main/java/org/graphwalker/core/machine/ReplayMachine.java @@ -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; @@ -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());