Copilot commented on code in PR #7296:
URL: https://github.com/apache/incubator-kie/pull/7296#discussion_r4563933224


##########
drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/SegmentPosMaskOverflowTest.java:
##########
@@ -0,0 +1,114 @@
+/*
+ * 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.compiler.integrationtests;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Stream;
+
+import org.drools.testcoverage.common.util.KieBaseTestConfiguration;
+import org.drools.testcoverage.common.util.KieBaseUtil;
+import org.drools.testcoverage.common.util.TestParametersUtil2;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.kie.api.KieBase;
+import org.kie.api.runtime.KieSession;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class SegmentPosMaskOverflowTest {
+
+    private static final int RULE_COUNT = 40;
+
+    private static final int NOT_PATTERN_INDEX = 32;
+
+    public static Stream<KieBaseTestConfiguration> parameters() {
+        return 
TestParametersUtil2.getKieBaseCloudConfigurations(true).stream();
+    }
+
+    private static String buildDrl() {
+        StringBuilder drl = new StringBuilder();
+        drl.append("package 
org.drools.compiler.integrationtests.segmentposmask;\n");
+        drl.append("global java.util.List results;\n");
+        for (int rule = 0; rule < RULE_COUNT; rule++) {
+            drl.append("rule \"rule").append(rule).append("\"\n");
+            drl.append("when\n");
+            for (int pattern = 0; pattern <= rule; pattern++) {
+                if (pattern == 0) {
+                    drl.append("    $first : Integer( this == 0 )\n");
+                } else if (pattern == NOT_PATTERN_INDEX) {
+                    drl.append("    not Long( this == $first )\n");

Review Comment:
   The `not Long( this == $first )` condition relies on cross-type comparison 
between `Long` and a bound `Integer` (`$first`). This can be harder to 
understand and may be more brittle across constraint dialects/engines. Consider 
making the `not` pattern use the same fact type as the rest of the test but 
with a constraint that is guaranteed to be unsatisfied by inserted facts (e.g., 
`not Integer( this == -1 )`) so it remains always-true while keeping types 
consistent.



##########
drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/SegmentPosMaskOverflowTest.java:
##########
@@ -0,0 +1,114 @@
+/*
+ * 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.compiler.integrationtests;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Stream;
+
+import org.drools.testcoverage.common.util.KieBaseTestConfiguration;
+import org.drools.testcoverage.common.util.KieBaseUtil;
+import org.drools.testcoverage.common.util.TestParametersUtil2;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.kie.api.KieBase;
+import org.kie.api.runtime.KieSession;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class SegmentPosMaskOverflowTest {
+
+    private static final int RULE_COUNT = 40;
+
+    private static final int NOT_PATTERN_INDEX = 32;
+
+    public static Stream<KieBaseTestConfiguration> parameters() {
+        return 
TestParametersUtil2.getKieBaseCloudConfigurations(true).stream();
+    }
+
+    private static String buildDrl() {
+        StringBuilder drl = new StringBuilder();
+        drl.append("package 
org.drools.compiler.integrationtests.segmentposmask;\n");
+        drl.append("global java.util.List results;\n");
+        for (int rule = 0; rule < RULE_COUNT; rule++) {
+            drl.append("rule \"rule").append(rule).append("\"\n");
+            drl.append("when\n");
+            for (int pattern = 0; pattern <= rule; pattern++) {
+                if (pattern == 0) {
+                    drl.append("    $first : Integer( this == 0 )\n");
+                } else if (pattern == NOT_PATTERN_INDEX) {
+                    drl.append("    not Long( this == $first )\n");
+                } else {
+                    drl.append("    Integer( this == 
").append(pattern).append(" )\n");
+                }
+            }
+            drl.append("then\n");
+            drl.append("    results.add(\"rule").append(rule).append("\");\n");
+            drl.append("end\n");
+        }
+        return drl.toString();
+    }
+
+    @ParameterizedTest(name = "KieBase type={0}")
+    @MethodSource("parameters")
+    public void testRuleWithMoreThan32SegmentsFires(KieBaseTestConfiguration 
cfg) {
+        String drl = buildDrl();
+        System.out.println("=== DRL (" + cfg + ") ===");
+        System.out.println(drl);

Review Comment:
   Avoid unconditional stdout printing in automated tests since it creates 
noisy logs and can slow CI. Prefer removing these prints, or only emitting 
diagnostics when the assertion fails (e.g., include details in the assertion 
message) or via a logger at a debug level.



##########
drools-core/src/main/java/org/drools/core/phreak/BuildtimeSegmentUtilities.java:
##########
@@ -166,7 +166,7 @@ public static SegmentPrototype[] 
createLeftTupleNodeProtoMemories(SegmentPrototy
         } while (segmentRoot != null); // it's after lian
 
         // reset to find the next segments and set their position and their 
bit mask
-        int ruleSegmentPosMask = 1;
+        long ruleSegmentPosMask = 1;

Review Comment:
   Since `ruleSegmentPosMask` is a `long`, initialize it with a `long` literal 
(`1L`) for clarity and to avoid accidental reintroduction of `int`-based 
intermediate math in future edits.



##########
drools-core/src/main/java/org/drools/core/phreak/SegmentMemorySupportImpl.java:
##########
@@ -498,7 +498,7 @@ public SegmentMemory 
createSegmentMemoryLazily(LeftTupleSource segmentRoot) {
 
         // iterate to find root and determine the SegmentNodes position in the 
RuleSegment
         LeftTupleSource pathRoot = segmentRoot;
-        int ruleSegmentPosMask = 1;
+        long ruleSegmentPosMask = 1;

Review Comment:
   Since `ruleSegmentPosMask` is a `long`, initialize it with a `long` literal 
(`1L`) for clarity and to avoid accidental reintroduction of `int`-based 
intermediate math in future edits.



##########
drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/SegmentPosMaskOverflowTest.java:
##########
@@ -0,0 +1,114 @@
+/*
+ * 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.compiler.integrationtests;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Stream;
+
+import org.drools.testcoverage.common.util.KieBaseTestConfiguration;
+import org.drools.testcoverage.common.util.KieBaseUtil;
+import org.drools.testcoverage.common.util.TestParametersUtil2;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.kie.api.KieBase;
+import org.kie.api.runtime.KieSession;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class SegmentPosMaskOverflowTest {
+
+    private static final int RULE_COUNT = 40;
+
+    private static final int NOT_PATTERN_INDEX = 32;
+
+    public static Stream<KieBaseTestConfiguration> parameters() {
+        return 
TestParametersUtil2.getKieBaseCloudConfigurations(true).stream();
+    }
+
+    private static String buildDrl() {
+        StringBuilder drl = new StringBuilder();
+        drl.append("package 
org.drools.compiler.integrationtests.segmentposmask;\n");
+        drl.append("global java.util.List results;\n");
+        for (int rule = 0; rule < RULE_COUNT; rule++) {
+            drl.append("rule \"rule").append(rule).append("\"\n");
+            drl.append("when\n");
+            for (int pattern = 0; pattern <= rule; pattern++) {
+                if (pattern == 0) {
+                    drl.append("    $first : Integer( this == 0 )\n");
+                } else if (pattern == NOT_PATTERN_INDEX) {
+                    drl.append("    not Long( this == $first )\n");
+                } else {
+                    drl.append("    Integer( this == 
").append(pattern).append(" )\n");
+                }
+            }
+            drl.append("then\n");
+            drl.append("    results.add(\"rule").append(rule).append("\");\n");
+            drl.append("end\n");
+        }
+        return drl.toString();
+    }
+
+    @ParameterizedTest(name = "KieBase type={0}")
+    @MethodSource("parameters")
+    public void testRuleWithMoreThan32SegmentsFires(KieBaseTestConfiguration 
cfg) {
+        String drl = buildDrl();
+        System.out.println("=== DRL (" + cfg + ") ===");
+        System.out.println(drl);
+
+        KieBase kbase = 
KieBaseUtil.getKieBaseFromKieModuleFromDrl("segment-pos-mask-overflow", cfg, 
drl);
+        KieSession ks = kbase.newKieSession();
+        try {
+            List<String> results = new ArrayList<>();
+            ks.setGlobal("results", results);
+
+            for (int i = 0; i < RULE_COUNT; i++) {
+                if (i != NOT_PATTERN_INDEX) {
+                    ks.insert(i);
+                }
+            }
+            ks.fireAllRules();
+
+            Set<String> expected = new HashSet<>();
+            for (int rule = 0; rule < RULE_COUNT; rule++) {
+                expected.add("rule" + rule);
+            }
+
+            Set<String> missing = new LinkedHashSet<>();
+            for (int rule = 0; rule < RULE_COUNT; rule++) {
+                if (!results.contains("rule" + rule)) {
+                    missing.add("rule" + rule);
+                }
+            }
+            System.out.println("=== Fired rules (" + results.size() + "/" + 
RULE_COUNT + ") ===");
+            System.out.println(results);
+            System.out.println("=== Rules that did NOT fire (" + 
missing.size() + ") ===");
+            System.out.println(missing);

Review Comment:
   Avoid unconditional stdout printing in automated tests since it creates 
noisy logs and can slow CI. Prefer removing these prints, or only emitting 
diagnostics when the assertion fails (e.g., include details in the assertion 
message) or via a logger at a debug level.



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