This is an automated email from the ASF dual-hosted git repository.

tkobayas pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie-drools.git


The following commit(s) were added to refs/heads/main by this push:
     new d7f097f1be [incubator-kie-drools-6706] Parallel Build of Inline 
Accumulate rules… (#6708)
d7f097f1be is described below

commit d7f097f1beaa2cd5b11a74b7add75d30afddd984
Author: Toshiya Kobayashi <[email protected]>
AuthorDate: Thu May 21 09:33:37 2026 +0900

    [incubator-kie-drools-6706] Parallel Build of Inline Accumulate rules… 
(#6708)
    
    * [incubator-kie-drools-6706] Parallel Build of Inline Accumulate rules 
cause a build error
    
    * mark runTurtleTests
---
 drools-model/drools-model-codegen/pom.xml          |  28 +++++
 .../model/codegen/execmodel/PackageModel.java      |   3 +-
 .../execmodel/ParallelBuildAccumulateTest.java     | 121 +++++++++++++++++++++
 3 files changed, 151 insertions(+), 1 deletion(-)

diff --git a/drools-model/drools-model-codegen/pom.xml 
b/drools-model/drools-model-codegen/pom.xml
index 174224e2c0..9cfeeaa310 100644
--- a/drools-model/drools-model-codegen/pom.xml
+++ b/drools-model/drools-model-codegen/pom.xml
@@ -150,4 +150,32 @@
         </dependency>
     </dependencies>
 
+    <profiles>
+        <profile>
+            <id>runTurtleTests</id>
+            <activation>
+                <property>
+                    <name>runTurtleTests</name>
+                </property>
+            </activation>
+            <build>
+                <pluginManagement>
+                    <plugins>
+                        <plugin>
+                            <artifactId>maven-surefire-plugin</artifactId>
+                            <configuration>
+                                <systemProperties>
+                                    <property>
+                                        <name>runTurtleTests</name>
+                                        <value>true</value>
+                                    </property>
+                                </systemProperties>
+                            </configuration>
+                        </plugin>
+                    </plugins>
+                </pluginManagement>
+            </build>
+        </profile>
+    </profiles>
+
 </project>
\ No newline at end of file
diff --git 
a/drools-model/drools-model-codegen/src/main/java/org/drools/model/codegen/execmodel/PackageModel.java
 
b/drools-model/drools-model-codegen/src/main/java/org/drools/model/codegen/execmodel/PackageModel.java
index 9cadd9bd39..8740af2858 100644
--- 
a/drools-model/drools-model-codegen/src/main/java/org/drools/model/codegen/execmodel/PackageModel.java
+++ 
b/drools-model/drools-model-codegen/src/main/java/org/drools/model/codegen/execmodel/PackageModel.java
@@ -32,6 +32,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.TreeMap;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.stream.Collectors;
 
 import com.github.javaparser.StaticJavaParser;
@@ -154,7 +155,7 @@ public class PackageModel {
 
     private final List<MethodDeclaration> functions = new ArrayList<>();
 
-    private final List<TypeDeclaration> generatedPOJOs = new ArrayList<>();
+    private final List<TypeDeclaration> generatedPOJOs = new 
CopyOnWriteArrayList<>();
     private final List<GeneratedClassWithPackage> generatedAccumulateClasses = 
new ArrayList<>();
 
     private final Set<Class<?>> domainClasses = new LinkedHashSet<>();
diff --git 
a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ParallelBuildAccumulateTest.java
 
b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ParallelBuildAccumulateTest.java
new file mode 100644
index 0000000000..108997c818
--- /dev/null
+++ 
b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ParallelBuildAccumulateTest.java
@@ -0,0 +1,121 @@
+/*
+ * 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.model.codegen.execmodel;
+
+import org.drools.model.codegen.ExecutableModelProject;
+import org.drools.model.codegen.execmodel.domain.Person;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
+import org.kie.api.KieServices;
+import org.kie.api.builder.model.KieModuleModel;
+import org.kie.api.io.ResourceType;
+import org.kie.internal.builder.conf.ParallelRulesBuildThresholdOption;
+import org.kie.internal.utils.KieHelper;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+
+@EnabledIfSystemProperty(named = "runTurtleTests", matches = "true")
+class ParallelBuildAccumulateTest {
+
+    private static final int BUILD_ATTEMPTS = 50;
+    private static final int RULE_COUNT = 8;
+    private static final int PARALLEL_RULES_BUILD_THRESHOLD = 4;
+
+    @Test
+    void buildExecutableModelWithParallelInlineAccumulates() {
+        assumeTrue(Runtime.getRuntime().availableProcessors() > 1,
+                   "Parallel rules build requires more than one available 
processor");
+
+        assertBuildDoesNotThrow(createInlineAccumulateDrl(RULE_COUNT));
+    }
+
+    @Test
+    void buildExecutableModelWithParallelBuiltInAccumulates() {
+        assumeTrue(Runtime.getRuntime().availableProcessors() > 1,
+                   "Parallel rules build requires more than one available 
processor");
+
+        assertBuildDoesNotThrow(createBuiltInAccumulateDrl(RULE_COUNT));
+    }
+
+    private void assertBuildDoesNotThrow(String drl) {
+        for (int i = 0; i < BUILD_ATTEMPTS; i++) {
+            int buildAttempt = i;
+            assertDoesNotThrow(() -> buildExecutableModel(drl),
+                               "Build attempt " + buildAttempt + " should not 
throw an exception");
+        }
+    }
+
+    private void buildExecutableModel(String drl) {
+        new KieHelper()
+                
.setKieModuleModel(kieModuleModelWithParallelRulesBuildThreshold())
+                .addContent(drl, ResourceType.DRL)
+                .build(ExecutableModelProject.class);
+    }
+
+    private KieModuleModel kieModuleModelWithParallelRulesBuildThreshold() {
+        KieModuleModel kieModuleModel = 
KieServices.Factory.get().newKieModuleModel();
+        
kieModuleModel.setConfigurationProperty(ParallelRulesBuildThresholdOption.PROPERTY_NAME,
+                                                
String.valueOf(PARALLEL_RULES_BUILD_THRESHOLD));
+        return kieModuleModel;
+    }
+
+    private String createInlineAccumulateDrl(int ruleCount) {
+        StringBuilder drl = new StringBuilder();
+        drl.append("package org.drools.model.codegen.execmodel;\n")
+                .append("import 
").append(Person.class.getCanonicalName()).append(";\n")
+                .append("global java.util.List list;\n\n");
+
+        for (int i = 0; i < ruleCount; i++) {
+            int initialValue = i * 3;
+            drl.append("rule \"accumulate").append(i).append("\"\n")
+                    .append("when\n")
+                    .append("    $person : Person(name == 
\"").append(i).append("\")\n")
+                    .append("    $totalAge : Number() from 
accumulate(Person($age : age),\n")
+                    .append("                              init(double total = 
").append(initialValue).append(";),\n")
+                    .append("                              action(total += 
$age;),\n")
+                    .append("                              reverse(total -= 
$age;),\n")
+                    .append("                              result(total))\n")
+                    .append("then\n")
+                    .append("    list.add(drools.getRule().getName());\n")
+                    .append("end\n\n");
+        }
+
+        return drl.toString();
+    }
+
+    private String createBuiltInAccumulateDrl(int ruleCount) {
+        StringBuilder drl = new StringBuilder();
+        drl.append("package org.drools.model.codegen.execmodel;\n")
+                .append("import 
").append(Person.class.getCanonicalName()).append(";\n")
+                .append("global java.util.List list;\n\n");
+
+        for (int i = 0; i < ruleCount; i++) {
+            drl.append("rule \"builtInAccumulate").append(i).append("\"\n")
+                    .append("when\n")
+                    .append("    $person : Person(name == 
\"").append(i).append("\")\n")
+                    .append("    $totalAge : Number() from 
accumulate(Person($age : age), sum($age))\n")
+                    .append("then\n")
+                    .append("    list.add(drools.getRule().getName());\n")
+                    .append("end\n\n");
+        }
+
+        return drl.toString();
+    }
+}


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

Reply via email to