From 13282e0aa226b2f12b706b15742d82418ff1f977 Mon Sep 17 00:00:00 2001 From: Maciej Swiderski Date: Wed, 6 Jul 2016 19:26:39 +0200 Subject: [PATCH] JBPM-5192 - After the simulation fails the server becomes unresponsive and it does not even respond to shutdown requests (#528) --- .../java/org/jbpm/simulation/PathContext.java | 22 +++++++++++++++ .../jbpm/simulation/PathContextManager.java | 10 +++++++ .../org/jbpm/simulation/PathFinderTest.java | 28 +++++++++++++++++-- 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/jbpm-simulation/src/main/java/org/jbpm/simulation/PathContext.java b/jbpm-simulation/src/main/java/org/jbpm/simulation/PathContext.java index d37d3a7c72..f6055bdbe6 100644 --- a/jbpm-simulation/src/main/java/org/jbpm/simulation/PathContext.java +++ b/jbpm-simulation/src/main/java/org/jbpm/simulation/PathContext.java @@ -24,6 +24,8 @@ import org.eclipse.bpmn2.SequenceFlow; public class PathContext { + + private final int maxElementsSize = Integer.parseInt(System.getProperty("org.jbpm.simulation.max.elements", "500")); public enum Type { ROOT, @@ -42,6 +44,8 @@ public enum Type { private Set visitedSplitPoint = new LinkedHashSet(); + private FlowElement splitOrigin = null; + protected int getCanBeFinishedCounter() { return canBeFinishedCounter; } @@ -61,6 +65,7 @@ public PathContext(Type type) { } public void addPathElement(FlowElement element) { + checkSize(); if (!locked) { this.pathElements.add(element); } @@ -73,6 +78,7 @@ public void removePathElement(FlowElement element) { } public void addAllPathElement(List elements) { + checkSize(); if (!locked) { this.pathElements.addAll(elements); } @@ -151,4 +157,20 @@ public void setVisitedSplitPoint(Set visitedSplitPoint) { this.visitedSplitPoint = visitedSplitPoint; } + + protected void checkSize() { + if (pathElements.size() > maxElementsSize) { + throw new RuntimeException("Unable to calculate path elements of the process - max size (" + maxElementsSize + ") of elements exceeded"); + } + } + + public FlowElement getSplitOrigin() { + return splitOrigin; + } + + public void setSplitOrigin(FlowElement splitOrigin) { + this.splitOrigin = splitOrigin; + } + + } diff --git a/jbpm-simulation/src/main/java/org/jbpm/simulation/PathContextManager.java b/jbpm-simulation/src/main/java/org/jbpm/simulation/PathContextManager.java index 6fa716960f..34ab8d58b3 100644 --- a/jbpm-simulation/src/main/java/org/jbpm/simulation/PathContextManager.java +++ b/jbpm-simulation/src/main/java/org/jbpm/simulation/PathContextManager.java @@ -32,6 +32,8 @@ public class PathContextManager { + private final int maxPathSize = Integer.parseInt(System.getProperty("org.jbpm.simulation.max.paths", "100")); + private Stack paths = new Stack(); private List completePaths = new ArrayList(); private Set completedPathsIds = new HashSet(); @@ -47,6 +49,7 @@ public void setCatchingEvents(Map catchingEvents) { } public PathContext getContextFromStack() { + checkSize(); if (this.paths.isEmpty()) { this.paths.push(new PathContext()); } @@ -55,6 +58,7 @@ public PathContext getContextFromStack() { } public Stack getContextsFromStack() { + checkSize(); if (this.paths.isEmpty()) { this.paths.push(new PathContext()); } @@ -222,4 +226,10 @@ public int compare(FlowElement o1, FlowElement o2) { } } + protected void checkSize() { + if (paths.size() > maxPathSize) { + throw new RuntimeException("Unable to calculate paths of the process - max size (" + maxPathSize + ") of paths exceeded"); + } + } + } diff --git a/jbpm-simulation/src/test/java/org/jbpm/simulation/PathFinderTest.java b/jbpm-simulation/src/test/java/org/jbpm/simulation/PathFinderTest.java index 4af5da5856..003b80449c 100644 --- a/jbpm-simulation/src/test/java/org/jbpm/simulation/PathFinderTest.java +++ b/jbpm-simulation/src/test/java/org/jbpm/simulation/PathFinderTest.java @@ -28,11 +28,17 @@ import org.jbpm.simulation.helper.TestUtils; import org.json.JSONException; import org.json.JSONObject; +import org.junit.After; +import org.junit.Before; import org.junit.Test; @SuppressWarnings("unchecked") public class PathFinderTest { - - + + @After + public void setup() { + System.clearProperty("org.jbpm.simulation.max.paths"); + System.clearProperty("org.jbpm.simulation.max.elements"); + } @Test public void testSinglePath() throws IOException { List expectedIds = new ArrayList(); @@ -1689,4 +1695,22 @@ public void testEventSubProcessPath() throws IOException { TestUtils.printOutPaths(paths, jsonPaths, "testEventSubProcessPath"); } + + @Test(expected = RuntimeException.class) + public void testMaxPathExceeded() throws IOException { + System.setProperty("org.jbpm.simulation.max.paths", "3"); + PathFinder finder = PathFinderFactory.getInstance(this.getClass().getResourceAsStream("/BPMN2-MortgageProcess.bpmn2")); + + finder.findPaths(); + + } + + @Test(expected = RuntimeException.class) + public void testMaxElementsExceeded() throws IOException { + System.setProperty("org.jbpm.simulation.max.elements", "3"); + PathFinder finder = PathFinderFactory.getInstance(this.getClass().getResourceAsStream("/BPMN2-MortgageProcess.bpmn2")); + + finder.findPaths(); + + } }