Copilot commented on code in PR #6760:
URL: 
https://github.com/apache/incubator-kie-drools/pull/6760#discussion_r3432428061


##########
drools-model/drools-model-compiler/src/test/java/org/drools/modelcompiler/OrNegatedJoinAfterReproTest.java:
##########
@@ -0,0 +1,144 @@
+/*
+ * 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.modelcompiler;
+
+import org.drools.model.Model;
+import org.drools.model.Rule;
+import org.drools.model.Variable;
+import org.drools.model.impl.ModelImpl;
+import org.drools.modelcompiler.KieBaseBuilder;
+import org.junit.jupiter.api.Test;
+import org.kie.api.KieBase;
+import org.kie.api.KieServices;
+import org.kie.api.conf.EventProcessingOption;
+import org.kie.api.definition.type.Role;
+import org.kie.api.runtime.KieSession;
+import org.kie.api.runtime.KieSessionConfiguration;
+import org.kie.api.runtime.conf.ClockTypeOption;
+import org.kie.api.time.SessionPseudoClock;
+
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import static org.drools.model.DSL.after;
+import static org.drools.model.DSL.declarationOf;
+import static org.drools.model.DSL.execute;
+import static org.drools.model.DSL.not;
+import static org.drools.model.PatternDSL.and;
+import static org.drools.model.PatternDSL.or;
+import static org.drools.model.PatternDSL.pattern;
+import static org.drools.model.PatternDSL.rule;
+
+public class OrNegatedJoinAfterReproTest {
+
+    @Role(Role.Type.EVENT) public static class EvA { public int id; public 
EvA(int id){this.id=id;} public int getId(){return id;} }
+    @Role(Role.Type.EVENT) public static class EvC { public int id; public 
EvC(int id){this.id=id;} public int getId(){return id;} }
+    @Role(Role.Type.EVENT) public static class EvD { public int id; public 
EvD(int id){this.id=id;} public int getId(){return id;} }
+    @Role(Role.Type.EVENT) public static class EvE { public int id; public 
EvE(int id){this.id=id;} public int getId(){return id;} }
+
+    private static void buildAndReplay(Rule r) {
+        Model model = new ModelImpl().addRule(r);
+        KieBase kb = KieBaseBuilder.createKieBaseFromModel(model, 
EventProcessingOption.STREAM);
+        KieSessionConfiguration conf = 
KieServices.get().newKieSessionConfiguration();
+        conf.setOption(ClockTypeOption.PSEUDO);
+        KieSession ks = kb.newKieSession(conf, null);
+        SessionPseudoClock clock = ks.getSessionClock();
+        List<Object> events = List.of(
+            new EvA(1), new EvC(1), new EvD(1), new EvE(1),
+            new EvA(2), new EvC(2), new EvD(2), new EvE(2));
+        try {
+            for (Object e : events) {
+                clock.advanceTime(1, TimeUnit.MILLISECONDS);
+                ks.insert(e);
+                ks.fireAllRules();
+            }
+            ks.fireAllRules();
+        } finally {
+            ks.dispose();
+        }
+    }
+
+    @Test
+    public void orWithNegatedJoinBranch_plusDownstreamAfter_runsWithoutNPE() {

Review Comment:
   Test method names in this module are consistently camelCase (no 
underscores). Renaming this method to camelCase keeps it aligned with the 
surrounding test suite and avoids inconsistent naming.



##########
drools-model/drools-model-compiler/src/test/java/org/drools/modelcompiler/OrNegatedJoinAfterReproTest.java:
##########
@@ -0,0 +1,144 @@
+/*
+ * 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.modelcompiler;
+
+import org.drools.model.Model;
+import org.drools.model.Rule;
+import org.drools.model.Variable;
+import org.drools.model.impl.ModelImpl;
+import org.drools.modelcompiler.KieBaseBuilder;
+import org.junit.jupiter.api.Test;
+import org.kie.api.KieBase;
+import org.kie.api.KieServices;
+import org.kie.api.conf.EventProcessingOption;
+import org.kie.api.definition.type.Role;
+import org.kie.api.runtime.KieSession;
+import org.kie.api.runtime.KieSessionConfiguration;
+import org.kie.api.runtime.conf.ClockTypeOption;
+import org.kie.api.time.SessionPseudoClock;
+
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import static org.drools.model.DSL.after;
+import static org.drools.model.DSL.declarationOf;
+import static org.drools.model.DSL.execute;
+import static org.drools.model.DSL.not;
+import static org.drools.model.PatternDSL.and;
+import static org.drools.model.PatternDSL.or;
+import static org.drools.model.PatternDSL.pattern;
+import static org.drools.model.PatternDSL.rule;
+
+public class OrNegatedJoinAfterReproTest {
+
+    @Role(Role.Type.EVENT) public static class EvA { public int id; public 
EvA(int id){this.id=id;} public int getId(){return id;} }
+    @Role(Role.Type.EVENT) public static class EvC { public int id; public 
EvC(int id){this.id=id;} public int getId(){return id;} }
+    @Role(Role.Type.EVENT) public static class EvD { public int id; public 
EvD(int id){this.id=id;} public int getId(){return id;} }
+    @Role(Role.Type.EVENT) public static class EvE { public int id; public 
EvE(int id){this.id=id;} public int getId(){return id;} }
+
+    private static void buildAndReplay(Rule r) {
+        Model model = new ModelImpl().addRule(r);
+        KieBase kb = KieBaseBuilder.createKieBaseFromModel(model, 
EventProcessingOption.STREAM);
+        KieSessionConfiguration conf = 
KieServices.get().newKieSessionConfiguration();
+        conf.setOption(ClockTypeOption.PSEUDO);
+        KieSession ks = kb.newKieSession(conf, null);
+        SessionPseudoClock clock = ks.getSessionClock();
+        List<Object> events = List.of(
+            new EvA(1), new EvC(1), new EvD(1), new EvE(1),
+            new EvA(2), new EvC(2), new EvD(2), new EvE(2));

Review Comment:
   `EvA` is never referenced by any of the rules in this test, so both the 
event type and the inserted events add noise without contributing to the repro. 
Removing them keeps the test minimal and easier to understand/maintain.



##########
drools-model/drools-model-compiler/src/test/java/org/drools/modelcompiler/OrNegatedJoinAfterReproTest.java:
##########
@@ -0,0 +1,144 @@
+/*
+ * 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.modelcompiler;
+
+import org.drools.model.Model;
+import org.drools.model.Rule;
+import org.drools.model.Variable;
+import org.drools.model.impl.ModelImpl;
+import org.drools.modelcompiler.KieBaseBuilder;
+import org.junit.jupiter.api.Test;
+import org.kie.api.KieBase;
+import org.kie.api.KieServices;
+import org.kie.api.conf.EventProcessingOption;
+import org.kie.api.definition.type.Role;
+import org.kie.api.runtime.KieSession;
+import org.kie.api.runtime.KieSessionConfiguration;
+import org.kie.api.runtime.conf.ClockTypeOption;
+import org.kie.api.time.SessionPseudoClock;
+
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import static org.drools.model.DSL.after;
+import static org.drools.model.DSL.declarationOf;
+import static org.drools.model.DSL.execute;
+import static org.drools.model.DSL.not;
+import static org.drools.model.PatternDSL.and;
+import static org.drools.model.PatternDSL.or;
+import static org.drools.model.PatternDSL.pattern;
+import static org.drools.model.PatternDSL.rule;
+
+public class OrNegatedJoinAfterReproTest {
+
+    @Role(Role.Type.EVENT) public static class EvA { public int id; public 
EvA(int id){this.id=id;} public int getId(){return id;} }
+    @Role(Role.Type.EVENT) public static class EvC { public int id; public 
EvC(int id){this.id=id;} public int getId(){return id;} }
+    @Role(Role.Type.EVENT) public static class EvD { public int id; public 
EvD(int id){this.id=id;} public int getId(){return id;} }
+    @Role(Role.Type.EVENT) public static class EvE { public int id; public 
EvE(int id){this.id=id;} public int getId(){return id;} }
+
+    private static void buildAndReplay(Rule r) {
+        Model model = new ModelImpl().addRule(r);
+        KieBase kb = KieBaseBuilder.createKieBaseFromModel(model, 
EventProcessingOption.STREAM);
+        KieSessionConfiguration conf = 
KieServices.get().newKieSessionConfiguration();
+        conf.setOption(ClockTypeOption.PSEUDO);
+        KieSession ks = kb.newKieSession(conf, null);
+        SessionPseudoClock clock = ks.getSessionClock();
+        List<Object> events = List.of(
+            new EvA(1), new EvC(1), new EvD(1), new EvE(1),
+            new EvA(2), new EvC(2), new EvD(2), new EvE(2));
+        try {
+            for (Object e : events) {
+                clock.advanceTime(1, TimeUnit.MILLISECONDS);
+                ks.insert(e);
+                ks.fireAllRules();
+            }
+            ks.fireAllRules();
+        } finally {
+            ks.dispose();
+        }
+    }
+
+    @Test
+    public void orWithNegatedJoinBranch_plusDownstreamAfter_runsWithoutNPE() {
+        Variable<EvE> e1 = declarationOf(EvE.class);
+        Variable<EvE> e2 = declarationOf(EvE.class);
+        Variable<EvC> c  = declarationOf(EvC.class);
+        Variable<EvE> et = declarationOf(EvE.class);
+        Variable<EvD> d  = declarationOf(EvD.class);
+
+        Rule r = rule("min-or-negjoin-after").build(
+            or(
+                pattern(e1).expr("e1", v -> true),
+                and(
+                        not(pattern(e2).expr("e2", v -> true)),
+                        pattern(c).expr("c", v -> true)
+                )
+            ),
+            pattern(et).expr("et", v -> true),
+            pattern(d).expr("d", v -> true).expr("d_after_et", et, after()),
+            execute(() -> {})
+        );
+
+        buildAndReplay(r);   // must not throw
+    }
+
+    @Test
+    public void control_dropAfter_runsWithoutNPE() {
+        Variable<EvE> e1 = declarationOf(EvE.class);
+        Variable<EvE> e2 = declarationOf(EvE.class);
+        Variable<EvC> c  = declarationOf(EvC.class);
+        Variable<EvE> et = declarationOf(EvE.class);
+        Variable<EvD> d  = declarationOf(EvD.class);
+
+        Rule r = rule("ctrl-no-after").build(
+            or(
+                pattern(e1).expr("e1", v -> true),
+                and(
+                        not(pattern(e2).expr("e2", v -> true)),
+                        pattern(c).expr("c", v -> true)
+                )
+            ),
+            pattern(et).expr("et", v -> true),
+            pattern(d).expr("d", v -> true),
+            execute(() -> {})
+        );
+
+        buildAndReplay(r);
+    }
+
+    @Test
+    public void control_dropOr_runsWithoutNPE() {

Review Comment:
   Test method names in this module are consistently camelCase (no 
underscores). Renaming this method to camelCase keeps it aligned with the 
surrounding test suite and avoids inconsistent naming.



##########
drools-model/drools-model-compiler/src/test/java/org/drools/modelcompiler/OrNegatedJoinAfterReproTest.java:
##########
@@ -0,0 +1,144 @@
+/*
+ * 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.modelcompiler;
+
+import org.drools.model.Model;
+import org.drools.model.Rule;
+import org.drools.model.Variable;
+import org.drools.model.impl.ModelImpl;
+import org.drools.modelcompiler.KieBaseBuilder;
+import org.junit.jupiter.api.Test;
+import org.kie.api.KieBase;
+import org.kie.api.KieServices;
+import org.kie.api.conf.EventProcessingOption;
+import org.kie.api.definition.type.Role;
+import org.kie.api.runtime.KieSession;
+import org.kie.api.runtime.KieSessionConfiguration;
+import org.kie.api.runtime.conf.ClockTypeOption;
+import org.kie.api.time.SessionPseudoClock;
+
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import static org.drools.model.DSL.after;
+import static org.drools.model.DSL.declarationOf;
+import static org.drools.model.DSL.execute;
+import static org.drools.model.DSL.not;
+import static org.drools.model.PatternDSL.and;
+import static org.drools.model.PatternDSL.or;
+import static org.drools.model.PatternDSL.pattern;
+import static org.drools.model.PatternDSL.rule;
+
+public class OrNegatedJoinAfterReproTest {
+
+    @Role(Role.Type.EVENT) public static class EvA { public int id; public 
EvA(int id){this.id=id;} public int getId(){return id;} }
+    @Role(Role.Type.EVENT) public static class EvC { public int id; public 
EvC(int id){this.id=id;} public int getId(){return id;} }
+    @Role(Role.Type.EVENT) public static class EvD { public int id; public 
EvD(int id){this.id=id;} public int getId(){return id;} }
+    @Role(Role.Type.EVENT) public static class EvE { public int id; public 
EvE(int id){this.id=id;} public int getId(){return id;} }
+
+    private static void buildAndReplay(Rule r) {
+        Model model = new ModelImpl().addRule(r);
+        KieBase kb = KieBaseBuilder.createKieBaseFromModel(model, 
EventProcessingOption.STREAM);
+        KieSessionConfiguration conf = 
KieServices.get().newKieSessionConfiguration();
+        conf.setOption(ClockTypeOption.PSEUDO);
+        KieSession ks = kb.newKieSession(conf, null);
+        SessionPseudoClock clock = ks.getSessionClock();
+        List<Object> events = List.of(
+            new EvA(1), new EvC(1), new EvD(1), new EvE(1),
+            new EvA(2), new EvC(2), new EvD(2), new EvE(2));
+        try {
+            for (Object e : events) {
+                clock.advanceTime(1, TimeUnit.MILLISECONDS);
+                ks.insert(e);
+                ks.fireAllRules();
+            }
+            ks.fireAllRules();
+        } finally {
+            ks.dispose();
+        }
+    }
+
+    @Test
+    public void orWithNegatedJoinBranch_plusDownstreamAfter_runsWithoutNPE() {
+        Variable<EvE> e1 = declarationOf(EvE.class);
+        Variable<EvE> e2 = declarationOf(EvE.class);
+        Variable<EvC> c  = declarationOf(EvC.class);
+        Variable<EvE> et = declarationOf(EvE.class);
+        Variable<EvD> d  = declarationOf(EvD.class);
+
+        Rule r = rule("min-or-negjoin-after").build(
+            or(
+                pattern(e1).expr("e1", v -> true),
+                and(
+                        not(pattern(e2).expr("e2", v -> true)),
+                        pattern(c).expr("c", v -> true)
+                )
+            ),
+            pattern(et).expr("et", v -> true),
+            pattern(d).expr("d", v -> true).expr("d_after_et", et, after()),
+            execute(() -> {})
+        );
+
+        buildAndReplay(r);   // must not throw
+    }
+
+    @Test
+    public void control_dropAfter_runsWithoutNPE() {

Review Comment:
   Test method names in this module are consistently camelCase (no 
underscores). Renaming this method to camelCase keeps it aligned with the 
surrounding test suite and avoids inconsistent naming.



##########
drools-model/drools-model-compiler/src/main/java/org/drools/modelcompiler/constraints/TemporalConstraintEvaluator.java:
##########
@@ -110,7 +112,7 @@ private long getNonEventTimestamp(TemporalConstraint 
temporalConstraint, FactHan
 
     @Override
     public TemporalConstraintEvaluator clone() {
-        return new TemporalConstraintEvaluator( getDeclarations(), 
getPattern(), constraint );
+        return new TemporalConstraintEvaluator( Arrays.copyOf( declarations, 
declarations.length ), getPattern(), constraint );
     }

Review Comment:
   This PR also includes files under 
`drools-model/drools-codegen-common/build/**` (e.g. `build/generated/**`, 
`build/classes/**`). These look like build outputs and should not be committed 
to source control; please remove them from the PR and ensure the build 
directory is excluded (or not produced) during development commits.



-- 
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