tkobayas commented on code in PR #7223:
URL: https://github.com/apache/incubator-kie/pull/7223#discussion_r4335123018


##########
drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/sequential/SequentialInsertDeleteUpdateTest.java:
##########
@@ -0,0 +1,1055 @@
+/*
+ * 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.drools.mvel.integrationtests.sequential;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Stream;
+
+import org.drools.mvel.compiler.Cheese;
+import org.drools.mvel.compiler.Person;
+import org.drools.testcoverage.common.util.KieBaseTestConfiguration;
+import org.drools.testcoverage.common.util.KieBaseUtil;
+import org.drools.testcoverage.common.util.KieUtil;
+import org.drools.testcoverage.common.util.TestParametersUtil2;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.kie.api.KieBase;
+import org.kie.api.builder.KieModule;
+import org.kie.api.conf.SequentialOption;
+import org.kie.api.runtime.StatelessKieSession;
+import org.kie.internal.command.CommandFactory;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Tests how insert, delete and update in the RHS work in sequential mode.
+ * <p>
+ * In sequential mode, rules are evaluated one by one in salience and load 
order, and each rule is evaluated only once.
+ * A rule which has not been evaluated yet sees the working memory changes 
made by previously fired rules.
+ * A rule which has already been evaluated is not re-evaluated.
+ *
+ * @see <a 
href="https://github.com/apache/incubator-kie/issues/7221";>incubator-kie#7221</a>
+ */
+public class SequentialInsertDeleteUpdateTest {
+
+    public static Stream<KieBaseTestConfiguration> parameters() {
+        return 
TestParametersUtil2.getKieBaseCloudConfigurations(true).stream();
+    }
+
+    // =====================================================================
+    // insert tests
+    // =====================================================================
+
+    /**
+     * R2 has not been evaluated yet, so it matches the Cheese inserted by R1.
+     */
+    @ParameterizedTest(name = "KieBase type={0}")
+    @MethodSource("parameters")
+    public void testInsertMatchedByLaterRule(KieBaseTestConfiguration 
kieBaseTestConfiguration) {
+        String str =
+                "package org.drools.mvel.compiler.test\n" +
+                "import " + Person.class.getCanonicalName() + "\n" +
+                "import " + Cheese.class.getCanonicalName() + "\n" +
+                "global " + List.class.getCanonicalName() + " list\n" +
+                "rule R1 salience 100 when\n" +
+                "    $p : Person()\n" +
+                "then\n" +
+                "    insert( new Cheese( \"stilton\", 10 ) );\n" +
+                "    list.add( \"R1\" );\n" +
+                "end\n" +
+                "rule R2 when\n" +
+                "    $c : Cheese()\n" +
+                "then\n" +
+                "    list.add( \"R2:\" + $c.getType() );\n" +
+                "end\n";
+
+        List<String> list = executeSequential(str, kieBaseTestConfiguration, 
new Person("p1", "stilton", 0));
+        assertThat(list).containsExactly("R1", "R2:stilton");
+    }
+
+    /**
+     * R1 has already been evaluated when R2 inserts a Cheese, so R1 is not 
re-evaluated.
+     */
+    @ParameterizedTest(name = "KieBase type={0}")
+    @MethodSource("parameters")
+    public void testInsertNotMatchedByEarlierRule(KieBaseTestConfiguration 
kieBaseTestConfiguration) {
+        String str =
+                "package org.drools.mvel.compiler.test\n" +
+                "import " + Person.class.getCanonicalName() + "\n" +
+                "import " + Cheese.class.getCanonicalName() + "\n" +
+                "global " + List.class.getCanonicalName() + " list\n" +
+                "rule R1 salience 100 when\n" +
+                "    $c : Cheese()\n" +
+                "then\n" +
+                "    list.add( \"R1:\" + $c.getType() );\n" +
+                "end\n" +
+                "rule R2 when\n" +
+                "    $p : Person()\n" +
+                "then\n" +
+                "    insert( new Cheese( \"stilton\", 10 ) );\n" +
+                "    list.add( \"R2\" );\n" +
+                "end\n";
+
+        List<String> list = executeSequential(str, kieBaseTestConfiguration, 
new Person("p1", "stilton", 0));
+        assertThat(list).containsExactly("R2");
+    }
+
+    /**
+     * R1 inserts a Person which matches R1 itself. R1 is not re-evaluated, so 
it doesn't loop even without no-loop.
+     */
+    @ParameterizedTest(name = "KieBase type={0}")
+    @MethodSource("parameters")
+    public void testInsertNotMatchedBySameRule(KieBaseTestConfiguration 
kieBaseTestConfiguration) {
+        String str =
+                "package org.drools.mvel.compiler.test\n" +
+                "import " + Person.class.getCanonicalName() + "\n" +
+                "global " + List.class.getCanonicalName() + " list\n" +
+                "rule R1 when\n" +
+                "    $p : Person()\n" +
+                "then\n" +
+                "    insert( new Person( $p.getName() + \"_child\", 
\"stilton\", 0 ) );\n" +
+                "    list.add( \"R1:\" + $p.getName() );\n" +
+                "end\n" +
+                "rule R2 when\n" +
+                "    $p : Person()\n" +
+                "then\n" +
+                "    list.add( \"R2:\" + $p.getName() );\n" +
+                "end\n";
+
+        List<String> list = executeSequential(str, kieBaseTestConfiguration, 
new Person("p1", "stilton", 0));
+        assertThat(list).containsExactlyInAnyOrder("R1:p1", "R2:p1", 
"R2:p1_child");
+        assertThat(list.get(0)).isEqualTo("R1:p1");
+    }
+
+    /**
+     * Inserting an object which is already in the working memory.
+     */
+    @ParameterizedTest(name = "KieBase type={0}")
+    @MethodSource("parameters")
+    @Disabled("Behaves differently from non-sequential mode. See 
https://github.com/apache/incubator-kie/issues/7222";)
+    public void testInsertSameObjectAgain(KieBaseTestConfiguration 
kieBaseTestConfiguration) {

Review Comment:
   This test class has 3 disabled edge-case tests, which may behave 
unexpectedly. They will be evaluated in a separate issue 
https://github.com/apache/incubator-kie/issues/7222



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to