From 7685790f608a48cc60fefe533d37eb1d613b7d60 Mon Sep 17 00:00:00 2001 From: Gabriele-Cardosi Date: Tue, 8 Oct 2024 10:39:35 +0200 Subject: [PATCH 01/11] [incubator-kie-issues#1497] Using the getSerializableNodeInstances inside ProtobufProcessInstanceWriter --- .../instance/node/ForEachNodeInstance.java | 23 +++++++++++-------- .../impl/ProtobufProcessInstanceWriter.java | 2 +- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/ForEachNodeInstance.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/ForEachNodeInstance.java index 339f48d3f2a..5f665df4851 100755 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/ForEachNodeInstance.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/ForEachNodeInstance.java @@ -18,14 +18,8 @@ */ package org.jbpm.workflow.instance.node; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; +import java.util.stream.*; import org.jbpm.process.core.ContextContainer; import org.jbpm.process.core.context.variable.VariableScope; @@ -48,7 +42,7 @@ import org.jbpm.workflow.instance.impl.NodeInstanceImpl; import org.jbpm.workflow.instance.impl.NodeInstanceResolverFactory; import org.kie.api.definition.process.Connection; -import org.kie.kogito.internal.process.runtime.KogitoNodeInstance; +import org.kie.kogito.internal.process.runtime.*; import org.mvel2.integration.VariableResolver; import org.mvel2.integration.impl.SimpleValueResolver; @@ -58,6 +52,8 @@ public class ForEachNodeInstance extends CompositeContextNodeInstance { private static final long serialVersionUID = 510L; + private static final List> NOT_SERIALIZABLE_CLASSES = Arrays.asList(ForEachJoinNodeInstance.class); // using Arrays.asList to allow multiple exclusions + public static final String TEMP_OUTPUT_VAR = "foreach_output"; private int totalInstances; @@ -131,6 +127,11 @@ public ContextContainer getContextContainer() { return getForEachNode().getCompositeNode(); } + @Override + public Collection getSerializableNodeInstances() { + return getNodeInstances().stream().filter(this::isSerializable).collect(Collectors.toUnmodifiableList()); + } + private boolean isSequential() { return getForEachNode().isSequential() || hasAsyncInstances; } @@ -350,6 +351,10 @@ public int getLevelForNode(String uniqueID) { return 1; } + private boolean isSerializable(org.kie.api.runtime.process.NodeInstance toCheck) { + return !NOT_SERIALIZABLE_CLASSES.contains(toCheck.getClass()); + } + private class ForEachNodeInstanceResolverFactory extends NodeInstanceResolverFactory { private static final long serialVersionUID = -8856846610671009685L; diff --git a/jbpm/process-serialization-protobuf/src/main/java/org/jbpm/flow/serialization/impl/ProtobufProcessInstanceWriter.java b/jbpm/process-serialization-protobuf/src/main/java/org/jbpm/flow/serialization/impl/ProtobufProcessInstanceWriter.java index b0f67430dbb..7b76171f042 100644 --- a/jbpm/process-serialization-protobuf/src/main/java/org/jbpm/flow/serialization/impl/ProtobufProcessInstanceWriter.java +++ b/jbpm/process-serialization-protobuf/src/main/java/org/jbpm/flow/serialization/impl/ProtobufProcessInstanceWriter.java @@ -249,7 +249,7 @@ public FieldDescriptor getContextField(GeneratedMessageV3.Builder builder) { } private WorkflowContext buildWorkflowContext(T nodeInstance) { - List nodeInstances = new ArrayList<>(nodeInstance.getNodeInstances()); + List nodeInstances = new ArrayList<>(nodeInstance.getSerializableNodeInstances()); List exclusiveGroupInstances = nodeInstance.getContextInstances(ExclusiveGroup.EXCLUSIVE_GROUP); VariableScopeInstance variableScopeInstance = (VariableScopeInstance) nodeInstance.getContextInstance(VariableScope.VARIABLE_SCOPE); List> variables = (variableScopeInstance != null) ? new ArrayList<>(variableScopeInstance.getVariables().entrySet()) : Collections.emptyList(); From f710fe4ccd6568bf5e15f2d97ca95af84ef8df5e Mon Sep 17 00:00:00 2001 From: Gabriele-Cardosi Date: Tue, 8 Oct 2024 11:27:31 +0200 Subject: [PATCH 02/11] [incubator-kie-issues#1497] Overriding getSerializableNodeInstances inside CompositeNodeInstance --- .../instance/node/CompositeNodeInstance.java | 19 ++++++++++++++++- .../instance/node/ForEachNodeInstance.java | 21 +++++++++++-------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/CompositeNodeInstance.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/CompositeNodeInstance.java index 2612be7998b..d804703897f 100755 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/CompositeNodeInstance.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/CompositeNodeInstance.java @@ -28,6 +28,7 @@ import java.util.UUID; import java.util.function.Function; import java.util.function.Predicate; +import java.util.stream.Collectors; import org.jbpm.workflow.core.Node; import org.jbpm.workflow.core.node.CompositeNode; @@ -204,7 +205,12 @@ public void removeNodeInstance(final NodeInstance nodeInstance) { @Override public Collection getNodeInstances() { - return new ArrayList<>(getNodeInstances(false)); + return Collections.unmodifiableCollection(nodeInstances); + } + + @Override + public Collection getSerializableNodeInstances() { + return nodeInstances.stream().filter(this::isSerializable).collect(Collectors.toUnmodifiableList()); } @Override @@ -473,4 +479,15 @@ public Map getIterationLevels() { return iterationLevels; } + /** + * Check if the given org.kie.api.runtime.process.NodeInstance is serializable. + * Every subclass should override it, if needed, to avoid polluting the parent one (this) with children details + * + * @param toCheck + * @return + */ + protected boolean isSerializable(org.kie.api.runtime.process.NodeInstance toCheck) { + return true; + } + } diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/ForEachNodeInstance.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/ForEachNodeInstance.java index 5f665df4851..ae9fd869377 100755 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/ForEachNodeInstance.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/ForEachNodeInstance.java @@ -18,8 +18,15 @@ */ package org.jbpm.workflow.instance.node; -import java.util.*; -import java.util.stream.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; import org.jbpm.process.core.ContextContainer; import org.jbpm.process.core.context.variable.VariableScope; @@ -42,7 +49,7 @@ import org.jbpm.workflow.instance.impl.NodeInstanceImpl; import org.jbpm.workflow.instance.impl.NodeInstanceResolverFactory; import org.kie.api.definition.process.Connection; -import org.kie.kogito.internal.process.runtime.*; +import org.kie.kogito.internal.process.runtime.KogitoNodeInstance; import org.mvel2.integration.VariableResolver; import org.mvel2.integration.impl.SimpleValueResolver; @@ -127,11 +134,6 @@ public ContextContainer getContextContainer() { return getForEachNode().getCompositeNode(); } - @Override - public Collection getSerializableNodeInstances() { - return getNodeInstances().stream().filter(this::isSerializable).collect(Collectors.toUnmodifiableList()); - } - private boolean isSequential() { return getForEachNode().isSequential() || hasAsyncInstances; } @@ -351,7 +353,8 @@ public int getLevelForNode(String uniqueID) { return 1; } - private boolean isSerializable(org.kie.api.runtime.process.NodeInstance toCheck) { + @Override + protected boolean isSerializable(org.kie.api.runtime.process.NodeInstance toCheck) { return !NOT_SERIALIZABLE_CLASSES.contains(toCheck.getClass()); } From d4824d74d93527c44c3e628d4edfec3d09f47203 Mon Sep 17 00:00:00 2001 From: Gabriele-Cardosi Date: Tue, 8 Oct 2024 11:43:03 +0200 Subject: [PATCH 03/11] [incubator-kie-issues#1497] Implementing getNotSerializableClasses inside CompositeNodeInstance - overriding in ForEachNodeInstance --- .../instance/node/CompositeNodeInstance.java | 19 ++++++++++++++----- .../instance/node/ForEachNodeInstance.java | 8 ++++---- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/CompositeNodeInstance.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/CompositeNodeInstance.java index d804703897f..1dbe2cfa3a3 100755 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/CompositeNodeInstance.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/CompositeNodeInstance.java @@ -25,6 +25,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.UUID; import java.util.function.Function; import java.util.function.Predicate; @@ -55,7 +56,6 @@ /** * Runtime counterpart of a composite node. - * */ public class CompositeNodeInstance extends StateBasedNodeInstance implements NodeInstanceContainer, EventNodeInstanceInterface, EventBasedNodeInstanceInterface { @@ -480,14 +480,23 @@ public Map getIterationLevels() { } /** - * Check if the given org.kie.api.runtime.process.NodeInstance is serializable. + * Return a Set of classes that are not serializable * Every subclass should override it, if needed, to avoid polluting the parent one (this) with children details - * + * + * @return + */ + protected Set> getNotSerializableClasses() { + return Collections.emptySet(); + } + + /** + * Check if the given org.kie.api.runtime.process.NodeInstance is serializable. + * * @param toCheck * @return */ - protected boolean isSerializable(org.kie.api.runtime.process.NodeInstance toCheck) { - return true; + private boolean isSerializable(org.kie.api.runtime.process.NodeInstance toCheck) { + return !getNotSerializableClasses().contains(toCheck.getClass()); } } diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/ForEachNodeInstance.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/ForEachNodeInstance.java index ae9fd869377..882061b29ac 100755 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/ForEachNodeInstance.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/ForEachNodeInstance.java @@ -19,7 +19,6 @@ package org.jbpm.workflow.instance.node; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Date; @@ -27,6 +26,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.Set; import org.jbpm.process.core.ContextContainer; import org.jbpm.process.core.context.variable.VariableScope; @@ -59,7 +59,7 @@ public class ForEachNodeInstance extends CompositeContextNodeInstance { private static final long serialVersionUID = 510L; - private static final List> NOT_SERIALIZABLE_CLASSES = Arrays.asList(ForEachJoinNodeInstance.class); // using Arrays.asList to allow multiple exclusions + private static final Set> NOT_SERIALIZABLE_CLASSES = Set.of(ForEachJoinNodeInstance.class); // using Arrays.asList to allow multiple exclusions public static final String TEMP_OUTPUT_VAR = "foreach_output"; @@ -354,8 +354,8 @@ public int getLevelForNode(String uniqueID) { } @Override - protected boolean isSerializable(org.kie.api.runtime.process.NodeInstance toCheck) { - return !NOT_SERIALIZABLE_CLASSES.contains(toCheck.getClass()); + protected Set> getNotSerializableClasses() { + return NOT_SERIALIZABLE_CLASSES; } private class ForEachNodeInstanceResolverFactory extends NodeInstanceResolverFactory { From 7ff40110092f171387c5c2d814be5739a0c67c4f Mon Sep 17 00:00:00 2001 From: Gabriele-Cardosi Date: Tue, 8 Oct 2024 17:39:44 +0200 Subject: [PATCH 04/11] [incubator-kie-issues#1497] Unit-testing ForEachNodeInstance --- .../node/ForEachNodeInstanceTest.java | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 jbpm/jbpm-flow/src/test/java/org/jbpm/workflow/instance/node/ForEachNodeInstanceTest.java diff --git a/jbpm/jbpm-flow/src/test/java/org/jbpm/workflow/instance/node/ForEachNodeInstanceTest.java b/jbpm/jbpm-flow/src/test/java/org/jbpm/workflow/instance/node/ForEachNodeInstanceTest.java new file mode 100644 index 00000000000..c02f4671b89 --- /dev/null +++ b/jbpm/jbpm-flow/src/test/java/org/jbpm/workflow/instance/node/ForEachNodeInstanceTest.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jbpm.workflow.instance.node; + +import java.util.Collection; +import java.util.Set; + +import org.junit.jupiter.api.Test; +import org.kie.api.runtime.process.NodeInstance; + +import static org.assertj.core.api.Assertions.assertThat; + +class ForEachNodeInstanceTest { + + @Test + void getNodeInstances() { + ForEachNodeInstance toTest = new ForEachNodeInstance(); + CompositeNodeInstance compositeNodeInstance = new CompositeNodeInstance(); + toTest.addNodeInstance(compositeNodeInstance); + Collection nodeInstances = toTest.getNodeInstances(); + assertThat(nodeInstances) + .isNotNull() + .hasSize(1) + .contains(compositeNodeInstance); + ForEachNodeInstance.ForEachJoinNodeInstance forEachJoinNodeInstance = toTest.new ForEachJoinNodeInstance(); + toTest.addNodeInstance(forEachJoinNodeInstance); + nodeInstances = toTest.getNodeInstances(); + assertThat(nodeInstances) + .isNotNull() + .hasSize(2) + .contains(compositeNodeInstance, forEachJoinNodeInstance); + } + + @Test + void getSerializableNodeInstances() { + ForEachNodeInstance toTest = new ForEachNodeInstance(); + CompositeNodeInstance compositeNodeInstance = new CompositeNodeInstance(); + toTest.addNodeInstance(compositeNodeInstance); + Collection serializableNodeInstances = toTest.getSerializableNodeInstances(); + assertThat(serializableNodeInstances) + .isNotNull() + .hasSize(1) + .contains(compositeNodeInstance); + ForEachNodeInstance.ForEachJoinNodeInstance forEachJoinNodeInstance = toTest.new ForEachJoinNodeInstance(); + toTest.addNodeInstance(forEachJoinNodeInstance); + serializableNodeInstances = toTest.getSerializableNodeInstances(); + assertThat(serializableNodeInstances) + .isNotNull() + .hasSize(1) + .contains(compositeNodeInstance); + } + + @Test + void getNotSerializableClasses() { + Set> retrieved = new ForEachNodeInstance().getNotSerializableClasses(); + assertThat(retrieved).isNotNull() + .hasSize(1) + .allMatch(cls -> cls.equals(ForEachNodeInstance.ForEachJoinNodeInstance.class)); + } +} \ No newline at end of file From 509c8a62e9ff0997921618eadeef7e0838ffa7ce Mon Sep 17 00:00:00 2001 From: Gabriele-Cardosi Date: Wed, 9 Oct 2024 10:33:57 +0200 Subject: [PATCH 05/11] [incubator-kie-issues#1497] Improving Serializable Nodes management - avoid stream/filter on each getSerializableNodeInstances invocation --- .../instance/node/CompositeNodeInstance.java | 7 +- .../instance/node/ForEachNodeInstance.java | 2 +- .../node/CompositeNodeInstanceTest.java | 96 +++++++++++++++++++ 3 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 jbpm/jbpm-flow/src/test/java/org/jbpm/workflow/instance/node/CompositeNodeInstanceTest.java diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/CompositeNodeInstance.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/CompositeNodeInstance.java index 1dbe2cfa3a3..49efa981d57 100755 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/CompositeNodeInstance.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/CompositeNodeInstance.java @@ -62,6 +62,7 @@ public class CompositeNodeInstance extends StateBasedNodeInstance implements Nod private static final long serialVersionUID = 510l; private final List nodeInstances = new ArrayList<>(); + private final List serializableNodeInstances = new ArrayList<>(); private int state = STATE_ACTIVE; private Map iterationLevels = new HashMap<>(); @@ -196,11 +197,15 @@ public void addNodeInstance(final NodeInstance nodeInstance) { ((NodeInstanceImpl) nodeInstance).setId(UUID.randomUUID().toString()); } this.nodeInstances.add(nodeInstance); + if (isSerializable(nodeInstance)) { + this.serializableNodeInstances.add(nodeInstance); + } } @Override public void removeNodeInstance(final NodeInstance nodeInstance) { this.nodeInstances.remove(nodeInstance); + this.serializableNodeInstances.remove(nodeInstance); } @Override @@ -210,7 +215,7 @@ public Collection getNodeInstances() { @Override public Collection getSerializableNodeInstances() { - return nodeInstances.stream().filter(this::isSerializable).collect(Collectors.toUnmodifiableList()); + return Collections.unmodifiableCollection(serializableNodeInstances); } @Override diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/ForEachNodeInstance.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/ForEachNodeInstance.java index 882061b29ac..92c65bd0abb 100755 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/ForEachNodeInstance.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/ForEachNodeInstance.java @@ -349,7 +349,7 @@ public ContextInstance getContextInstance(String contextId) { @Override public int getLevelForNode(String uniqueID) { - // always 1 for for each + // always 1 for each return 1; } diff --git a/jbpm/jbpm-flow/src/test/java/org/jbpm/workflow/instance/node/CompositeNodeInstanceTest.java b/jbpm/jbpm-flow/src/test/java/org/jbpm/workflow/instance/node/CompositeNodeInstanceTest.java new file mode 100644 index 00000000000..748147c249c --- /dev/null +++ b/jbpm/jbpm-flow/src/test/java/org/jbpm/workflow/instance/node/CompositeNodeInstanceTest.java @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jbpm.workflow.instance.node; + +import java.util.Collection; +import java.util.Set; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.kie.api.runtime.process.NodeInstance; + +import static org.assertj.core.api.Assertions.assertThat; + +class CompositeNodeInstanceTest { + + private CompositeNodeInstance compositeNodeInstance; + + @BeforeEach + public void init() { + compositeNodeInstance = new CheckedCompositeNodeInstance(); + } + + @Test + void addNodeInstanceSerializable() { + SerializableNode serializableNode = new SerializableNode(); + compositeNodeInstance.addNodeInstance(serializableNode); + Collection nodeInstances = compositeNodeInstance.getNodeInstances(); + assertThat(nodeInstances).isNotNull().hasSize(1).containsExactly(serializableNode); + Collection serializableNodeInstances = compositeNodeInstance.getSerializableNodeInstances(); + assertThat(serializableNodeInstances).isNotNull().hasSize(1).containsExactly(serializableNode); + } + + @Test + void addNodeInstanceNotSerializable() { + NotSerializableNode notSerializableNode = new NotSerializableNode(); + compositeNodeInstance.addNodeInstance(notSerializableNode); + Collection nodeInstances = compositeNodeInstance.getNodeInstances(); + assertThat(nodeInstances).isNotNull().hasSize(1).containsExactly(notSerializableNode); + Collection serializableNodeInstances = compositeNodeInstance.getSerializableNodeInstances(); + assertThat(serializableNodeInstances).isNotNull().isEmpty(); + } + + @Test + void removeNodeInstance() { + SerializableNode serializableNode = new SerializableNode(); + compositeNodeInstance.addNodeInstance(serializableNode); + NotSerializableNode notSerializableNode = new NotSerializableNode(); + compositeNodeInstance.addNodeInstance(notSerializableNode); + Collection nodeInstances = compositeNodeInstance.getNodeInstances(); + assertThat(nodeInstances).isNotNull().hasSize(2).containsExactly(serializableNode, notSerializableNode); + Collection serializableNodeInstances = compositeNodeInstance.getSerializableNodeInstances(); + assertThat(serializableNodeInstances).isNotNull().hasSize(1).containsExactly(serializableNode); + + compositeNodeInstance.removeNodeInstance(serializableNode); + nodeInstances = compositeNodeInstance.getNodeInstances(); + assertThat(nodeInstances).isNotNull().hasSize(1).containsExactly(notSerializableNode); + serializableNodeInstances = compositeNodeInstance.getSerializableNodeInstances(); + assertThat(serializableNodeInstances).isNotNull().isEmpty(); + + compositeNodeInstance.removeNodeInstance(notSerializableNode); + nodeInstances = compositeNodeInstance.getNodeInstances(); + assertThat(nodeInstances).isNotNull().isEmpty(); + serializableNodeInstances = compositeNodeInstance.getSerializableNodeInstances(); + assertThat(serializableNodeInstances).isNotNull().isEmpty(); + } + + private static class CheckedCompositeNodeInstance extends CompositeNodeInstance { + + private static final Set> notSerializableClasses = Set.of(NotSerializableNode.class); + + @Override + protected Set> getNotSerializableClasses() { + return notSerializableClasses; + } + } + + private static class SerializableNode extends CompositeNodeInstance { } + + private static class NotSerializableNode extends CompositeNodeInstance { } +} \ No newline at end of file From 51e9ff089e1f2f4501e28cf91e740a9c5e3d1e2d Mon Sep 17 00:00:00 2001 From: Gabriele-Cardosi Date: Wed, 9 Oct 2024 11:02:40 +0200 Subject: [PATCH 06/11] [incubator-kie-issues#1497] Fix formatting --- .../workflow/instance/node/CompositeNodeInstanceTest.java | 6 ++++-- .../workflow/instance/node/ForEachNodeInstanceTest.java | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/jbpm/jbpm-flow/src/test/java/org/jbpm/workflow/instance/node/CompositeNodeInstanceTest.java b/jbpm/jbpm-flow/src/test/java/org/jbpm/workflow/instance/node/CompositeNodeInstanceTest.java index 748147c249c..6e6289fc2e5 100644 --- a/jbpm/jbpm-flow/src/test/java/org/jbpm/workflow/instance/node/CompositeNodeInstanceTest.java +++ b/jbpm/jbpm-flow/src/test/java/org/jbpm/workflow/instance/node/CompositeNodeInstanceTest.java @@ -90,7 +90,9 @@ protected Set> getNotS } } - private static class SerializableNode extends CompositeNodeInstance { } + private static class SerializableNode extends CompositeNodeInstance { + } - private static class NotSerializableNode extends CompositeNodeInstance { } + private static class NotSerializableNode extends CompositeNodeInstance { + } } \ No newline at end of file diff --git a/jbpm/jbpm-flow/src/test/java/org/jbpm/workflow/instance/node/ForEachNodeInstanceTest.java b/jbpm/jbpm-flow/src/test/java/org/jbpm/workflow/instance/node/ForEachNodeInstanceTest.java index c02f4671b89..8c2a8fa0700 100644 --- a/jbpm/jbpm-flow/src/test/java/org/jbpm/workflow/instance/node/ForEachNodeInstanceTest.java +++ b/jbpm/jbpm-flow/src/test/java/org/jbpm/workflow/instance/node/ForEachNodeInstanceTest.java @@ -57,7 +57,7 @@ void getSerializableNodeInstances() { .isNotNull() .hasSize(1) .contains(compositeNodeInstance); - ForEachNodeInstance.ForEachJoinNodeInstance forEachJoinNodeInstance = toTest.new ForEachJoinNodeInstance(); + ForEachNodeInstance.ForEachJoinNodeInstance forEachJoinNodeInstance = toTest.new ForEachJoinNodeInstance(); toTest.addNodeInstance(forEachJoinNodeInstance); serializableNodeInstances = toTest.getSerializableNodeInstances(); assertThat(serializableNodeInstances) From 814c29818083a21c24f3b9918c4f6a21384b772c Mon Sep 17 00:00:00 2001 From: Gabriele-Cardosi Date: Wed, 9 Oct 2024 11:36:05 +0200 Subject: [PATCH 07/11] [incubator-kie-issues#1497] Fix imports --- .../org/jbpm/workflow/instance/node/CompositeNodeInstance.java | 1 - 1 file changed, 1 deletion(-) diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/CompositeNodeInstance.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/CompositeNodeInstance.java index 49efa981d57..46c0ce271a8 100755 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/CompositeNodeInstance.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/CompositeNodeInstance.java @@ -29,7 +29,6 @@ import java.util.UUID; import java.util.function.Function; import java.util.function.Predicate; -import java.util.stream.Collectors; import org.jbpm.workflow.core.Node; import org.jbpm.workflow.core.node.CompositeNode; From d02eb8aec68af7c7c8aa6e34ab6400f0c1b3b67a Mon Sep 17 00:00:00 2001 From: Gabriele-Cardosi Date: Wed, 9 Oct 2024 14:28:02 +0200 Subject: [PATCH 08/11] [incubator-kie-issues#1497] Implemented ProtobufProcessInstanceWriterTest.buildWorkflowContext unit test --- .../node/ForEachNodeInstanceTest.java | 2 +- .../impl/ProtobufProcessInstanceWriter.java | 4 +- .../ProtobufProcessInstanceWriterTest.java | 149 ++++++++++++++++++ 3 files changed, 152 insertions(+), 3 deletions(-) create mode 100644 jbpm/process-serialization-protobuf/src/test/java/org/jbpm/flow/serialization/impl/ProtobufProcessInstanceWriterTest.java diff --git a/jbpm/jbpm-flow/src/test/java/org/jbpm/workflow/instance/node/ForEachNodeInstanceTest.java b/jbpm/jbpm-flow/src/test/java/org/jbpm/workflow/instance/node/ForEachNodeInstanceTest.java index 8c2a8fa0700..b5b5fb08653 100644 --- a/jbpm/jbpm-flow/src/test/java/org/jbpm/workflow/instance/node/ForEachNodeInstanceTest.java +++ b/jbpm/jbpm-flow/src/test/java/org/jbpm/workflow/instance/node/ForEachNodeInstanceTest.java @@ -71,6 +71,6 @@ void getNotSerializableClasses() { Set> retrieved = new ForEachNodeInstance().getNotSerializableClasses(); assertThat(retrieved).isNotNull() .hasSize(1) - .allMatch(cls -> cls.equals(ForEachNodeInstance.ForEachJoinNodeInstance.class)); + .contains(ForEachNodeInstance.ForEachJoinNodeInstance.class); } } \ No newline at end of file diff --git a/jbpm/process-serialization-protobuf/src/main/java/org/jbpm/flow/serialization/impl/ProtobufProcessInstanceWriter.java b/jbpm/process-serialization-protobuf/src/main/java/org/jbpm/flow/serialization/impl/ProtobufProcessInstanceWriter.java index 7b76171f042..700d7abd422 100644 --- a/jbpm/process-serialization-protobuf/src/main/java/org/jbpm/flow/serialization/impl/ProtobufProcessInstanceWriter.java +++ b/jbpm/process-serialization-protobuf/src/main/java/org/jbpm/flow/serialization/impl/ProtobufProcessInstanceWriter.java @@ -175,7 +175,7 @@ private List buildSwimlaneContexts(Swimlane return contexts; } - private KogitoTypesProtobuf.WorkflowContext buildWorkflowContext(List nodeInstances, + protected KogitoTypesProtobuf.WorkflowContext buildWorkflowContext(List nodeInstances, List exclusiveGroupInstances, List> variables, List> iterationlevels) { @@ -248,7 +248,7 @@ public FieldDescriptor getContextField(GeneratedMessageV3.Builder builder) { return null; } - private WorkflowContext buildWorkflowContext(T nodeInstance) { + protected WorkflowContext buildWorkflowContext(T nodeInstance) { List nodeInstances = new ArrayList<>(nodeInstance.getSerializableNodeInstances()); List exclusiveGroupInstances = nodeInstance.getContextInstances(ExclusiveGroup.EXCLUSIVE_GROUP); VariableScopeInstance variableScopeInstance = (VariableScopeInstance) nodeInstance.getContextInstance(VariableScope.VARIABLE_SCOPE); diff --git a/jbpm/process-serialization-protobuf/src/test/java/org/jbpm/flow/serialization/impl/ProtobufProcessInstanceWriterTest.java b/jbpm/process-serialization-protobuf/src/test/java/org/jbpm/flow/serialization/impl/ProtobufProcessInstanceWriterTest.java new file mode 100644 index 00000000000..4d37ade30f2 --- /dev/null +++ b/jbpm/process-serialization-protobuf/src/test/java/org/jbpm/flow/serialization/impl/ProtobufProcessInstanceWriterTest.java @@ -0,0 +1,149 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jbpm.flow.serialization.impl; + +import java.io.ByteArrayOutputStream; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.ServiceLoader; + +import org.jbpm.flow.serialization.MarshallerContextName; +import org.jbpm.flow.serialization.NodeInstanceWriter; +import org.jbpm.flow.serialization.ObjectMarshallerStrategyHelper; +import org.jbpm.process.core.context.variable.VariableScope; +import org.jbpm.process.instance.ContextInstance; +import org.jbpm.process.instance.context.variable.VariableScopeInstance; +import org.jbpm.ruleflow.core.WorkflowElementIdentifierFactory; +import org.jbpm.util.JbpmClassLoaderUtil; +import org.jbpm.workflow.core.impl.WorkflowProcessImpl; +import org.jbpm.workflow.instance.node.ForEachNodeInstance; +import org.jbpm.workflow.instance.node.HumanTaskNodeInstance; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.kie.api.definition.process.WorkflowElementIdentifier; +import org.kie.api.runtime.process.NodeInstance; +import org.kie.kogito.internal.process.runtime.KogitoProcessRuntime; +import org.kie.kogito.process.impl.AbstractProcess; +import org.mockito.ArgumentCaptor; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +class ProtobufProcessInstanceWriterTest { + + private static AbstractProcess mockProcess; + private static NodeInstanceWriter[] nodeInstanceWriters; + private ProtobufProcessMarshallerWriteContext writeContext; + + @BeforeAll + static void setup() { + ServiceLoader writerLoader = ServiceLoader.load(NodeInstanceWriter.class, JbpmClassLoaderUtil.findClassLoader()); + int items = (int) writerLoader.stream().count(); + nodeInstanceWriters = writerLoader.stream().map(ServiceLoader.Provider::get).map(NodeInstanceWriter.class::cast).toArray(value -> new NodeInstanceWriter[items]); + mockProcess = getMockedProcess(); + } + + @BeforeEach + void init() { + writeContext = new ProtobufProcessMarshallerWriteContext(new ByteArrayOutputStream()); + writeContext.set(MarshallerContextName.OBJECT_MARSHALLING_STRATEGIES, ObjectMarshallerStrategyHelper.defaultStrategies()); + writeContext.set(MarshallerContextName.MARSHALLER_PROCESS, mockProcess); + writeContext.set(MarshallerContextName.MARSHALLER_NODE_INSTANCE_WRITER, nodeInstanceWriters); + } + + @SuppressWarnings("unchecked") + @Test + void buildWorkflowContext() { + ProtobufProcessInstanceWriter spiedProtobufProcessInstanceWriter = spy(new ProtobufProcessInstanceWriter(writeContext)); + ForEachNodeInstance nodeInstance = getNodeInstanceContainer(); + try { + spiedProtobufProcessInstanceWriter.buildWorkflowContext(nodeInstance); + } catch (Exception e) { + // expected due to partial instantiation + assertThat(e).isInstanceOf(NullPointerException.class); + ArgumentCaptor> nodeInstancesCapture = ArgumentCaptor.forClass(ArrayList.class); + ArgumentCaptor> exclusiveGroupInstancesCapture = ArgumentCaptor.forClass(ArrayList.class); + ArgumentCaptor>> variablesCapture = ArgumentCaptor.forClass(ArrayList.class); + ArgumentCaptor>> iterationlevelsCapture = ArgumentCaptor.forClass(ArrayList.class); + verify(spiedProtobufProcessInstanceWriter).buildWorkflowContext(nodeInstancesCapture.capture(), exclusiveGroupInstancesCapture.capture(), variablesCapture.capture(), + iterationlevelsCapture.capture()); + Collection expected = nodeInstance.getSerializableNodeInstances(); + List retrieved = nodeInstancesCapture.getValue(); + assertThat(retrieved).isNotNull().hasSize(expected.size()).allMatch(expected::contains); + } + } + + private ForEachNodeInstance getNodeInstanceContainer() { + String id = "NodeInstanceContainer"; + ForEachNodeInstance toReturn = new ForEachNodeInstance(); + toReturn.setId(id); + toReturn.setLevel(1); + toReturn.addNodeInstance(getNodeInstanceSerializable(id)); + toReturn.addNodeInstance(getNodeInstanceNotSerializable(id)); + toReturn.setNodeId(getWorkflowElementIdentifier(id)); + toReturn.setContextInstance(VariableScope.VARIABLE_SCOPE, new VariableScopeInstance()); + Collection nodeInstances = toReturn.getNodeInstances(); + assertThat(nodeInstances) + .isNotNull() + .hasSize(2) + .anyMatch(HumanTaskNodeInstance.class::isInstance) + .anyMatch(ForEachNodeInstance.ForEachJoinNodeInstance.class::isInstance); + Collection serializableNodeInstances = toReturn.getSerializableNodeInstances(); + assertThat(serializableNodeInstances) + .isNotNull() + .hasSize(1) + .allMatch(HumanTaskNodeInstance.class::isInstance); + return toReturn; + } + + private ForEachNodeInstance.ForEachJoinNodeInstance getNodeInstanceNotSerializable(String parent) { + String id = String.format("%s-%s", parent, "nestedNodeInstanceNotSerializable"); + ForEachNodeInstance.ForEachJoinNodeInstance toReturn = new ForEachNodeInstance().new ForEachJoinNodeInstance(); + toReturn.setId(id); + toReturn.setLevel(2); + return toReturn; + } + + private HumanTaskNodeInstance getNodeInstanceSerializable(String parent) { + String id = String.format("%s-%s", parent, "nestedNodeInstanceSerializable"); + HumanTaskNodeInstance toReturn = new HumanTaskNodeInstance(); + toReturn.setId(id); + toReturn.setNodeId(getWorkflowElementIdentifier(id)); + return toReturn; + } + + private WorkflowElementIdentifier getWorkflowElementIdentifier(String parent) { + String id = String.format("%s-%s", parent, "workflowElementIdentifier"); + return WorkflowElementIdentifierFactory.fromExternalFormat(id); + } + + private static AbstractProcess getMockedProcess() { + AbstractProcess toReturn = mock(AbstractProcess.class); + when(toReturn.getProcessRuntime()).thenReturn(mock(KogitoProcessRuntime.class)); + when(toReturn.get()).thenReturn(new WorkflowProcessImpl()); + return toReturn; + } + +} From f06b4ab8be1d3ca0bcfea5aac1172769b2ae2f3f Mon Sep 17 00:00:00 2001 From: Gabriele-Cardosi Date: Fri, 11 Oct 2024 13:27:18 +0200 Subject: [PATCH 09/11] [incubator-kie-issues#1497] Removing serializableNodes list --- .../workflow/instance/node/CompositeNodeInstance.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/CompositeNodeInstance.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/CompositeNodeInstance.java index 46c0ce271a8..89184ce7e34 100755 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/CompositeNodeInstance.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/CompositeNodeInstance.java @@ -29,6 +29,7 @@ import java.util.UUID; import java.util.function.Function; import java.util.function.Predicate; +import java.util.stream.Collectors; import org.jbpm.workflow.core.Node; import org.jbpm.workflow.core.node.CompositeNode; @@ -61,7 +62,6 @@ public class CompositeNodeInstance extends StateBasedNodeInstance implements Nod private static final long serialVersionUID = 510l; private final List nodeInstances = new ArrayList<>(); - private final List serializableNodeInstances = new ArrayList<>(); private int state = STATE_ACTIVE; private Map iterationLevels = new HashMap<>(); @@ -191,20 +191,16 @@ public void cancel(CancelType cancelType) { @Override public void addNodeInstance(final NodeInstance nodeInstance) { if (nodeInstance.getStringId() == null) { - // assign new id only if it does not exist as it might already be set by marshalling + // assign new id only if it does not exist as it might already be set by marshalling // it's important to keep same ids of node instances as they might be references e.g. exclusive group ((NodeInstanceImpl) nodeInstance).setId(UUID.randomUUID().toString()); } this.nodeInstances.add(nodeInstance); - if (isSerializable(nodeInstance)) { - this.serializableNodeInstances.add(nodeInstance); - } } @Override public void removeNodeInstance(final NodeInstance nodeInstance) { this.nodeInstances.remove(nodeInstance); - this.serializableNodeInstances.remove(nodeInstance); } @Override @@ -214,7 +210,7 @@ public Collection getNodeInstances() { @Override public Collection getSerializableNodeInstances() { - return Collections.unmodifiableCollection(serializableNodeInstances); + return nodeInstances.stream().filter(this::isSerializable).collect(Collectors.toUnmodifiableList()); } @Override From 754e9679a43360710c4eb9e4cd298965bd97fcd8 Mon Sep 17 00:00:00 2001 From: Gabriele-Cardosi Date: Fri, 18 Oct 2024 08:45:49 +0200 Subject: [PATCH 10/11] [incubator-kie-issues#1497] Reverting to modification only in ForEachNodeInstance --- .../instance/node/CompositeNodeInstance.java | 28 +----- .../instance/node/ForEachNodeInstance.java | 17 +++- .../node/CompositeNodeInstanceTest.java | 98 ------------------- .../node/ForEachNodeInstanceTest.java | 10 +- 4 files changed, 21 insertions(+), 132 deletions(-) delete mode 100644 jbpm/jbpm-flow/src/test/java/org/jbpm/workflow/instance/node/CompositeNodeInstanceTest.java diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/CompositeNodeInstance.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/CompositeNodeInstance.java index 89184ce7e34..ea9a6774629 100755 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/CompositeNodeInstance.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/CompositeNodeInstance.java @@ -25,11 +25,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.UUID; import java.util.function.Function; import java.util.function.Predicate; -import java.util.stream.Collectors; import org.jbpm.workflow.core.Node; import org.jbpm.workflow.core.node.CompositeNode; @@ -56,6 +54,7 @@ /** * Runtime counterpart of a composite node. + * */ public class CompositeNodeInstance extends StateBasedNodeInstance implements NodeInstanceContainer, EventNodeInstanceInterface, EventBasedNodeInstanceInterface { @@ -208,11 +207,6 @@ public Collection getNodeInstances() { return Collections.unmodifiableCollection(nodeInstances); } - @Override - public Collection getSerializableNodeInstances() { - return nodeInstances.stream().filter(this::isSerializable).collect(Collectors.toUnmodifiableList()); - } - @Override public org.kie.api.runtime.process.NodeInstance getNodeInstance(long l) { throw new UnsupportedOperationException(); @@ -479,24 +473,4 @@ public Map getIterationLevels() { return iterationLevels; } - /** - * Return a Set of classes that are not serializable - * Every subclass should override it, if needed, to avoid polluting the parent one (this) with children details - * - * @return - */ - protected Set> getNotSerializableClasses() { - return Collections.emptySet(); - } - - /** - * Check if the given org.kie.api.runtime.process.NodeInstance is serializable. - * - * @param toCheck - * @return - */ - private boolean isSerializable(org.kie.api.runtime.process.NodeInstance toCheck) { - return !getNotSerializableClasses().contains(toCheck.getClass()); - } - } diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/ForEachNodeInstance.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/ForEachNodeInstance.java index 92c65bd0abb..76b0922e849 100755 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/ForEachNodeInstance.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/ForEachNodeInstance.java @@ -27,6 +27,7 @@ import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; import org.jbpm.process.core.ContextContainer; import org.jbpm.process.core.context.variable.VariableScope; @@ -353,11 +354,23 @@ public int getLevelForNode(String uniqueID) { return 1; } + @Override - protected Set> getNotSerializableClasses() { - return NOT_SERIALIZABLE_CLASSES; + public Collection getSerializableNodeInstances() { + return getNodeInstances().stream().filter(ForEachNodeInstance::isSerializable).collect(Collectors.toUnmodifiableList()); + } + + /** + * Check if the given org.kie.api.runtime.process.NodeInstance is serializable. + * + * @param toCheck + * @return + */ + static boolean isSerializable(org.kie.api.runtime.process.NodeInstance toCheck) { + return !NOT_SERIALIZABLE_CLASSES.contains(toCheck.getClass()); } + private class ForEachNodeInstanceResolverFactory extends NodeInstanceResolverFactory { private static final long serialVersionUID = -8856846610671009685L; diff --git a/jbpm/jbpm-flow/src/test/java/org/jbpm/workflow/instance/node/CompositeNodeInstanceTest.java b/jbpm/jbpm-flow/src/test/java/org/jbpm/workflow/instance/node/CompositeNodeInstanceTest.java deleted file mode 100644 index 6e6289fc2e5..00000000000 --- a/jbpm/jbpm-flow/src/test/java/org/jbpm/workflow/instance/node/CompositeNodeInstanceTest.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jbpm.workflow.instance.node; - -import java.util.Collection; -import java.util.Set; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.kie.api.runtime.process.NodeInstance; - -import static org.assertj.core.api.Assertions.assertThat; - -class CompositeNodeInstanceTest { - - private CompositeNodeInstance compositeNodeInstance; - - @BeforeEach - public void init() { - compositeNodeInstance = new CheckedCompositeNodeInstance(); - } - - @Test - void addNodeInstanceSerializable() { - SerializableNode serializableNode = new SerializableNode(); - compositeNodeInstance.addNodeInstance(serializableNode); - Collection nodeInstances = compositeNodeInstance.getNodeInstances(); - assertThat(nodeInstances).isNotNull().hasSize(1).containsExactly(serializableNode); - Collection serializableNodeInstances = compositeNodeInstance.getSerializableNodeInstances(); - assertThat(serializableNodeInstances).isNotNull().hasSize(1).containsExactly(serializableNode); - } - - @Test - void addNodeInstanceNotSerializable() { - NotSerializableNode notSerializableNode = new NotSerializableNode(); - compositeNodeInstance.addNodeInstance(notSerializableNode); - Collection nodeInstances = compositeNodeInstance.getNodeInstances(); - assertThat(nodeInstances).isNotNull().hasSize(1).containsExactly(notSerializableNode); - Collection serializableNodeInstances = compositeNodeInstance.getSerializableNodeInstances(); - assertThat(serializableNodeInstances).isNotNull().isEmpty(); - } - - @Test - void removeNodeInstance() { - SerializableNode serializableNode = new SerializableNode(); - compositeNodeInstance.addNodeInstance(serializableNode); - NotSerializableNode notSerializableNode = new NotSerializableNode(); - compositeNodeInstance.addNodeInstance(notSerializableNode); - Collection nodeInstances = compositeNodeInstance.getNodeInstances(); - assertThat(nodeInstances).isNotNull().hasSize(2).containsExactly(serializableNode, notSerializableNode); - Collection serializableNodeInstances = compositeNodeInstance.getSerializableNodeInstances(); - assertThat(serializableNodeInstances).isNotNull().hasSize(1).containsExactly(serializableNode); - - compositeNodeInstance.removeNodeInstance(serializableNode); - nodeInstances = compositeNodeInstance.getNodeInstances(); - assertThat(nodeInstances).isNotNull().hasSize(1).containsExactly(notSerializableNode); - serializableNodeInstances = compositeNodeInstance.getSerializableNodeInstances(); - assertThat(serializableNodeInstances).isNotNull().isEmpty(); - - compositeNodeInstance.removeNodeInstance(notSerializableNode); - nodeInstances = compositeNodeInstance.getNodeInstances(); - assertThat(nodeInstances).isNotNull().isEmpty(); - serializableNodeInstances = compositeNodeInstance.getSerializableNodeInstances(); - assertThat(serializableNodeInstances).isNotNull().isEmpty(); - } - - private static class CheckedCompositeNodeInstance extends CompositeNodeInstance { - - private static final Set> notSerializableClasses = Set.of(NotSerializableNode.class); - - @Override - protected Set> getNotSerializableClasses() { - return notSerializableClasses; - } - } - - private static class SerializableNode extends CompositeNodeInstance { - } - - private static class NotSerializableNode extends CompositeNodeInstance { - } -} \ No newline at end of file diff --git a/jbpm/jbpm-flow/src/test/java/org/jbpm/workflow/instance/node/ForEachNodeInstanceTest.java b/jbpm/jbpm-flow/src/test/java/org/jbpm/workflow/instance/node/ForEachNodeInstanceTest.java index b5b5fb08653..26f1ab063d8 100644 --- a/jbpm/jbpm-flow/src/test/java/org/jbpm/workflow/instance/node/ForEachNodeInstanceTest.java +++ b/jbpm/jbpm-flow/src/test/java/org/jbpm/workflow/instance/node/ForEachNodeInstanceTest.java @@ -67,10 +67,10 @@ void getSerializableNodeInstances() { } @Test - void getNotSerializableClasses() { - Set> retrieved = new ForEachNodeInstance().getNotSerializableClasses(); - assertThat(retrieved).isNotNull() - .hasSize(1) - .contains(ForEachNodeInstance.ForEachJoinNodeInstance.class); + void isSerializable() { + assertThat(ForEachNodeInstance.isSerializable(new CompositeNodeInstance())).isTrue(); + assertThat(ForEachNodeInstance.isSerializable(new ForEachNodeInstance())).isTrue(); + assertThat(ForEachNodeInstance.isSerializable(new ForEachNodeInstance().new ForEachJoinNodeInstance())).isFalse(); } + } \ No newline at end of file From ef1b5acc00f76c695cbbec84bb3f53f2f4f12cf6 Mon Sep 17 00:00:00 2001 From: Gabriele-Cardosi Date: Fri, 18 Oct 2024 10:40:15 +0200 Subject: [PATCH 11/11] [incubator-kie-issues#1497] Fix format/imports --- .../org/jbpm/workflow/instance/node/ForEachNodeInstance.java | 2 -- .../jbpm/workflow/instance/node/ForEachNodeInstanceTest.java | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/ForEachNodeInstance.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/ForEachNodeInstance.java index 76b0922e849..9b17022e460 100755 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/ForEachNodeInstance.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/ForEachNodeInstance.java @@ -354,7 +354,6 @@ public int getLevelForNode(String uniqueID) { return 1; } - @Override public Collection getSerializableNodeInstances() { return getNodeInstances().stream().filter(ForEachNodeInstance::isSerializable).collect(Collectors.toUnmodifiableList()); @@ -370,7 +369,6 @@ static boolean isSerializable(org.kie.api.runtime.process.NodeInstance toCheck) return !NOT_SERIALIZABLE_CLASSES.contains(toCheck.getClass()); } - private class ForEachNodeInstanceResolverFactory extends NodeInstanceResolverFactory { private static final long serialVersionUID = -8856846610671009685L; diff --git a/jbpm/jbpm-flow/src/test/java/org/jbpm/workflow/instance/node/ForEachNodeInstanceTest.java b/jbpm/jbpm-flow/src/test/java/org/jbpm/workflow/instance/node/ForEachNodeInstanceTest.java index 26f1ab063d8..23194d30272 100644 --- a/jbpm/jbpm-flow/src/test/java/org/jbpm/workflow/instance/node/ForEachNodeInstanceTest.java +++ b/jbpm/jbpm-flow/src/test/java/org/jbpm/workflow/instance/node/ForEachNodeInstanceTest.java @@ -19,7 +19,6 @@ package org.jbpm.workflow.instance.node; import java.util.Collection; -import java.util.Set; import org.junit.jupiter.api.Test; import org.kie.api.runtime.process.NodeInstance; @@ -73,4 +72,4 @@ void isSerializable() { assertThat(ForEachNodeInstance.isSerializable(new ForEachNodeInstance().new ForEachJoinNodeInstance())).isFalse(); } -} \ No newline at end of file +}