Skip to content

Commit

Permalink
JBPM-5192 - After the simulation fails the server becomes unresponsiv…
Browse files Browse the repository at this point in the history
…e and it does not even respond to shutdown requests (kiegroup#528)
  • Loading branch information
mswiderski authored and csadilek committed Jul 6, 2016
1 parent cf3842f commit 13282e0
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
22 changes: 22 additions & 0 deletions jbpm-simulation/src/main/java/org/jbpm/simulation/PathContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -42,6 +44,8 @@ public enum Type {

private Set<FlowElement> visitedSplitPoint = new LinkedHashSet<FlowElement>();

private FlowElement splitOrigin = null;

protected int getCanBeFinishedCounter() {
return canBeFinishedCounter;
}
Expand All @@ -61,6 +65,7 @@ public PathContext(Type type) {
}

public void addPathElement(FlowElement element) {
checkSize();
if (!locked) {
this.pathElements.add(element);
}
Expand All @@ -73,6 +78,7 @@ public void removePathElement(FlowElement element) {
}

public void addAllPathElement(List<SequenceFlow> elements) {
checkSize();
if (!locked) {
this.pathElements.addAll(elements);
}
Expand Down Expand Up @@ -151,4 +157,20 @@ public void setVisitedSplitPoint(Set<FlowElement> 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;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

public class PathContextManager {

private final int maxPathSize = Integer.parseInt(System.getProperty("org.jbpm.simulation.max.paths", "100"));

private Stack<PathContext> paths = new Stack<PathContext>();
private List<PathContext> completePaths = new ArrayList<PathContext>();
private Set<String> completedPathsIds = new HashSet<String>();
Expand All @@ -47,6 +49,7 @@ public void setCatchingEvents(Map<String, FlowElement> catchingEvents) {
}

public PathContext getContextFromStack() {
checkSize();
if (this.paths.isEmpty()) {
this.paths.push(new PathContext());
}
Expand All @@ -55,6 +58,7 @@ public PathContext getContextFromStack() {
}

public Stack<PathContext> getContextsFromStack() {
checkSize();
if (this.paths.isEmpty()) {
this.paths.push(new PathContext());
}
Expand Down Expand Up @@ -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");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> expectedIds = new ArrayList<String>();
Expand Down Expand Up @@ -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();

}
}

0 comments on commit 13282e0

Please sign in to comment.