diff --git a/.github/workflows/pr-downstream.yml b/.github/workflows/pr-downstream.yml index 575f4ec6dfe..fbccd515f42 100644 --- a/.github/workflows/pr-downstream.yml +++ b/.github/workflows/pr-downstream.yml @@ -33,6 +33,7 @@ on: jobs: kogito-downstream-build: + if: false concurrency: group: pr-${{ matrix.job_name }}_${{ matrix.os }}_${{ matrix.java-version }}_${{ matrix.maven-version }}_${{ github.head_ref }} cancel-in-progress: true diff --git a/.github/workflows/pr-drools-ansible.yml b/.github/workflows/pr-drools-ansible.yml index 82181f67532..234a68700b5 100644 --- a/.github/workflows/pr-drools-ansible.yml +++ b/.github/workflows/pr-drools-ansible.yml @@ -33,6 +33,7 @@ on: jobs: drools-ansible: + if: false concurrency: group: pr-drools_ansible_${{ matrix.os }}_${{ matrix.java-version }}_${{ matrix.maven-version }}_${{ github.head_ref }} cancel-in-progress: true diff --git a/.github/workflows/pr-drools-docs.yml b/.github/workflows/pr-drools-docs.yml index d33c9cdc022..8a21a376f6b 100644 --- a/.github/workflows/pr-drools-docs.yml +++ b/.github/workflows/pr-drools-docs.yml @@ -27,6 +27,7 @@ on: jobs: drools-build: + if: false concurrency: group: pr-drools_docs_${{ matrix.os }}_${{ matrix.java-version }}_${{ matrix.maven-version }}_${{ github.head_ref }} cancel-in-progress: true diff --git a/.github/workflows/pr-drools.yml b/.github/workflows/pr-drools.yml index d1f5f77b4f7..4bc354dfc38 100644 --- a/.github/workflows/pr-drools.yml +++ b/.github/workflows/pr-drools.yml @@ -52,23 +52,30 @@ jobs: - name: Support long paths if: ${{ matrix.os == 'windows-latest' }} uses: apache/incubator-kie-kogito-pipelines/.ci/actions/long-paths@main + - uses: actions/checkout@v3 - name: Java and Maven Setup uses: apache/incubator-kie-kogito-pipelines/.ci/actions/maven@main with: java-version: ${{ matrix.java-version }} maven-version: ${{ matrix.maven-version }} cache-key-prefix: ${{ runner.os }}-${{ matrix.java-version }}-maven${{ matrix.maven-version }} - - name: Build Chain - uses: apache/incubator-kie-kogito-pipelines/.ci/actions/build-chain@main - env: - BUILD_MVN_OPTS_CURRENT: '-Dfull -Dreproducible' - MAVEN_OPTS: "-Dfile.encoding=UTF-8" - with: - definition-file: https://raw.githubusercontent.com/${GROUP:apache}/incubator-kie-kogito-pipelines/${BRANCH:main}/.ci/pull-request-config.yaml - annotations-prefix: ${{ runner.os }}-${{ matrix.java-version }}/${{ matrix.maven-version }} - github-token: "${{ secrets.GITHUB_TOKEN }}" - - name: Surefire Report - uses: apache/incubator-kie-kogito-pipelines/.ci/actions/surefire-report@main - if: ${{ always() }} - with: - report_paths: '**/*-reports/TEST-*.xml' + allow-snapshots: true + - name: Build drools-core + run: mvn -B clean install -Dquickly --file drools-core/pom.xml + - name: Build drools-compiler + run: mvn -B clean install -Dquickly --file drools-compiler/pom.xml + - name: Run loop Windows + if: ${{ matrix.os == 'windows-latest' }} + shell: cmd + run: | + FOR /L %%G IN (1,1,100) DO ( + echo Iteration %%G + mvn -B clean test --file drools-test-coverage/test-compiler-integration/pom.xml -Dtest=ConcurrentBasesParallelTest,org.drools.mvel.integrationtests.KieContainerTest#testIncrementalCompilationSynchronization* + ) + - name: Run loop Linux + if: ${{ matrix.os == 'ubuntu-latest' }} + run: | + for i in {1..100}; do + echo "Iteration $i" + mvn -B clean test --file drools-test-coverage/test-compiler-integration/pom.xml -Dtest=ConcurrentBasesParallelTest,org.drools.mvel.integrationtests.KieContainerTest#testIncrementalCompilationSynchronization* + done diff --git a/.github/workflows/pr-jenkins.yml b/.github/workflows/pr-jenkins.yml index 1566cdc1188..e6437d3c29b 100644 --- a/.github/workflows/pr-jenkins.yml +++ b/.github/workflows/pr-jenkins.yml @@ -28,6 +28,7 @@ on: jobs: dsl-tests: + if: false concurrency: group: ${{ github.repository.name }}_dsl_tests-${{ github.head_ref }} cancel-in-progress: true diff --git a/drools-compiler/src/main/java/org/drools/compiler/builder/impl/processors/RuleCompilationPhase.java b/drools-compiler/src/main/java/org/drools/compiler/builder/impl/processors/RuleCompilationPhase.java index 3cbee9a04c4..4170f2c9026 100644 --- a/drools-compiler/src/main/java/org/drools/compiler/builder/impl/processors/RuleCompilationPhase.java +++ b/drools-compiler/src/main/java/org/drools/compiler/builder/impl/processors/RuleCompilationPhase.java @@ -35,9 +35,13 @@ import org.drools.kiesession.rulebase.InternalKnowledgeBase; import org.kie.api.io.Resource; import org.kie.internal.builder.ResourceChange; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class RuleCompilationPhase extends ImmutableRuleCompilationPhase { + private static final Logger LOG = LoggerFactory.getLogger(RuleCompilationPhase.class); + public static CompilationPhase of( PackageRegistry pkgRegistry, PackageDescr packageDescr, @@ -129,6 +133,7 @@ private void preProcessRules(PackageDescr packageDescr, PackageRegistry pkgRegis } } + LOG.info("preProcessRules 1: {}", rulesToBeRemoved); rulesToBeRemoved.forEach(pkg::removeRule); for (RuleDescr ruleDescr : packageDescr.getRules()) { @@ -142,6 +147,7 @@ private void preProcessRules(PackageDescr packageDescr, PackageRegistry pkgRegis if (!rulesToBeRemoved.isEmpty()) { rulesToBeRemoved.addAll(findChildrenRulesToBeRemoved(packageDescr, rulesToBeRemoved)); + LOG.info("preProcessRules 2: {}", rulesToBeRemoved); kBase.removeRules(rulesToBeRemoved); } }); diff --git a/drools-compiler/src/main/java/org/drools/compiler/kie/builder/impl/KieBaseUpdaterImpl.java b/drools-compiler/src/main/java/org/drools/compiler/kie/builder/impl/KieBaseUpdaterImpl.java index 0134ada0ae4..38b6d1c56f3 100644 --- a/drools-compiler/src/main/java/org/drools/compiler/kie/builder/impl/KieBaseUpdaterImpl.java +++ b/drools-compiler/src/main/java/org/drools/compiler/kie/builder/impl/KieBaseUpdaterImpl.java @@ -108,6 +108,7 @@ private KieBaseUpdate createKieBaseUpdate() { for (ResourceChange change : changeSet.getChanges()) { if (change.getType() == ResourceChange.Type.RULE) { + log.info("createKieBaseUpdate : change = " + change); switch (change.getChangeType()) { case ADDED: kieBaseUpdate.registerRuleToBeAdded(newPkg.getRule( change.getName() )); diff --git a/drools-compiler/src/main/java/org/drools/compiler/kie/builder/impl/KieContainerImpl.java b/drools-compiler/src/main/java/org/drools/compiler/kie/builder/impl/KieContainerImpl.java index 9d1a4a33418..cc78cb888df 100644 --- a/drools-compiler/src/main/java/org/drools/compiler/kie/builder/impl/KieContainerImpl.java +++ b/drools-compiler/src/main/java/org/drools/compiler/kie/builder/impl/KieContainerImpl.java @@ -298,6 +298,14 @@ private Results update( InternalKieModule currentKM, InternalKieModule newKM ) { ))) .forEach(compositeUpdater::add); + log.warn("update"); + cs.getChanges().entrySet().forEach( entry -> { + String resourceName = entry.getKey(); + ResourceChangeSet resourceChangeSet = entry.getValue(); + if (resourceName.equals("rules1.drl")) { + log.warn(" " + resourceName + " -> " + resourceChangeSet.getChanges()); + } + }); kBase.enqueueModification(compositeUpdater); } diff --git a/drools-core/src/main/java/org/drools/core/impl/KnowledgeBaseImpl.java b/drools-core/src/main/java/org/drools/core/impl/KnowledgeBaseImpl.java index e14d287f218..7c18a8d7576 100644 --- a/drools-core/src/main/java/org/drools/core/impl/KnowledgeBaseImpl.java +++ b/drools-core/src/main/java/org/drools/core/impl/KnowledgeBaseImpl.java @@ -1086,12 +1086,14 @@ public void removeRule( final String packageName, final String ruleName ) { } public void kBaseInternal_removeRule(InternalKnowledgePackage pkg, RuleImpl rule, Collection workingMemories) { + logger.info("kBaseInternal_removeRule: " + rule.getName()); this.reteooBuilder.removeRules(Collections.singletonList(rule), workingMemories); pkg.removeRule( rule ); addReloadDialectDatas( pkg.getDialectRuntimeRegistry() ); } public void kBaseInternal_removeRules(Collection rules, Collection workingMemories) { + logger.info("kBaseInternal_removeRules: " + rules); this.reteooBuilder.removeRules(rules, workingMemories); } @@ -1237,6 +1239,7 @@ public boolean removeObjectsGeneratedFromResource(Resource resource, Collection< for (InternalKnowledgePackage pkg : pkgs.values()) { List rulesToBeRemoved = pkg.getRulesGeneratedFromResource(resource); if (!rulesToBeRemoved.isEmpty()) { + logger.info("removeObjectsGeneratedFromResource: " + rulesToBeRemoved); this.reteooBuilder.removeRules( rulesToBeRemoved, workingMemories ); // removal of rule from package has to be delayed after the rule has been removed from the phreak network // in order to allow the correct flushing of all outstanding staged tuples diff --git a/drools-core/src/main/java/org/drools/core/reteoo/ReteooBuilder.java b/drools-core/src/main/java/org/drools/core/reteoo/ReteooBuilder.java index 2d7ada53d35..7f5506addfe 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/ReteooBuilder.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/ReteooBuilder.java @@ -48,6 +48,8 @@ import org.drools.core.reteoo.builder.ReteooRuleBuilder; import org.drools.core.util.TupleRBTree.Node; import org.kie.api.definition.rule.Rule; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Builds the Rete-OO network for a Package. @@ -57,6 +59,7 @@ public class ReteooBuilder implements Externalizable { + private static final Logger LOG = LoggerFactory.getLogger(ReteooBuilder.class); private static final long serialVersionUID = 510l; @@ -158,6 +161,7 @@ public synchronized Map getTerminalNodes() { } public synchronized void removeRules(Collection rulesToBeRemoved, Collection workingMemories) { + LOG.info("removeRules: " + rulesToBeRemoved); for (Rule r : rulesToBeRemoved) { RuleImpl rule = (RuleImpl) r; if (rule.hasChildren() && !rulesToBeRemoved.containsAll( rule.getChildren() )) { diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/KieContainerTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/KieContainerTest.java index 0bebcd07b8e..05fb8fba93b 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/KieContainerTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/KieContainerTest.java @@ -25,6 +25,8 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import org.apache.commons.io.IOUtils; import org.drools.compiler.compiler.io.Folder; @@ -49,6 +51,8 @@ import org.kie.api.io.ResourceType; import org.kie.api.runtime.KieContainer; import org.kie.api.runtime.KieSession; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import static org.assertj.core.api.Assertions.assertThat; import static org.drools.core.util.DroolsAssert.assertEnumerationSize; @@ -57,6 +61,8 @@ @RunWith(Parameterized.class) public class KieContainerTest { + private final Logger LOG = LoggerFactory.getLogger(KieContainerTest.class); + private final KieBaseTestConfiguration kieBaseTestConfiguration; public KieContainerTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { @@ -248,47 +254,91 @@ private void insertMessageFromTypeDeclaration(KieSession ksession) throws Instan ksession.insert(message); } + private static volatile boolean running = true; @Test(timeout = 20000) public void testIncrementalCompilationSynchronization() { - final KieServices kieServices = KieServices.Factory.get(); - - ReleaseId releaseId = kieServices.newReleaseId("org.kie.test", "sync-scanner-test", "1.0.0"); - KieUtil.getKieModuleFromDrls(releaseId, kieBaseTestConfiguration, createDRL("rule0")); - - final KieContainer kieContainer = kieServices.newKieContainer(releaseId); - KieSession kieSession = kieContainer.newKieSession(); - List list = new ArrayList<>(); - kieSession.setGlobal("list", list); - kieSession.fireAllRules(); - kieSession.dispose(); - assertThat(list.size()).isEqualTo(1); - - Thread t = new Thread(() -> { - for (int i = 1; i < 10; i++) { - ReleaseId releaseId1 = kieServices.newReleaseId("org.kie.test", "sync-scanner-test", "1.0." + i); - KieUtil.getKieModuleFromDrls(releaseId1, kieBaseTestConfiguration, createDRL("rule" + i)); - kieContainer.updateToVersion(releaseId1); - } - }); - - t.setDaemon(true); - t.start(); - - while (true) { - kieSession = kieContainer.newKieSession(); - list = new ArrayList<>(); - kieSession.setGlobal("list", list); - kieSession.fireAllRules(); - kieSession.dispose(); - // There can be multiple items in the list if an updateToVersion is triggered during a fireAllRules - // (updateToVersion can be called multiple times during fireAllRules, especially on slower machines) - // in that case it may fire with the old rule and multiple new ones - assertThat(list).isNotEmpty(); - if (list.get(0).equals("rule9")) { - break; + int MAX_THREAD = 8; + ExecutorService executor = Executors.newFixedThreadPool(MAX_THREAD); + + try { + for (int n = 0; n < 1; n++) { + LOG.info("*** run : n = " + n); + + final KieServices kieServices = KieServices.Factory.get(); + + ReleaseId releaseId = kieServices.newReleaseId("org.kie.test", "sync-scanner-test", "1.0.0"); + KieUtil.getKieModuleFromDrls(releaseId, kieBaseTestConfiguration, createDRL("rule0")); + + final KieContainer kieContainer = kieServices.newKieContainer(releaseId); + + KieSession kieSession = kieContainer.newKieSession(); + List list = new ArrayList<>(); + kieSession.setGlobal("list", list); + kieSession.fireAllRules(); + kieSession.dispose(); + assertThat(list.size()).isEqualTo(1); + LOG.info(" 1st iteration done"); + + running = true; +// for (int m = 0; m < MAX_THREAD; m++) { +// executor.execute(new Runnable() { +// +// public void run() { +// long dummy = 0; +// while (running) { // The thread runs until 'running' is set to false +// dummy += 1; // Simple increment to keep the thread busy +// if (dummy < 0) { +// dummy = 0; +// } +// dummy += 1; +// } +// } +// }); +// } + + Thread t = new Thread(() -> { + for (int i = 1; i < 10; i++) { + ReleaseId releaseId1 = kieServices.newReleaseId("org.kie.test", "sync-scanner-test", "1.0." + i); + LOG.info(" getKieModuleFromDrls: " + releaseId1.toExternalForm()); + KieUtil.getKieModuleFromDrls(releaseId1, kieBaseTestConfiguration, createDRL("rule" + i)); + LOG.info(" updateToVersion: " + releaseId1.toExternalForm()); + kieContainer.updateToVersion(releaseId1); + } + }); + + t.setDaemon(true); + t.start(); + + String lastResult = ""; + int sameResultCounter = 0; + while (true) { + kieSession = kieContainer.newKieSession(); + list = new ArrayList<>(); + kieSession.setGlobal("list", list); + kieSession.fireAllRules(); + kieSession.dispose(); + // There can be multiple items in the list if an updateToVersion is triggered during a fireAllRules + // (updateToVersion can be called multiple times during fireAllRules, especially on slower machines) + // in that case it may fire with the old rule and multiple new ones + assertThat(list).isNotEmpty(); + if (list.get(0).equals("rule9")) { + running = false; + break; + } else { + if (!lastResult.equals(list.toString())) { + LOG.info(" Fired rule: list = " + list + ", previous sameResultCounter = " + sameResultCounter); + lastResult = list.toString(); + sameResultCounter = 0; + } else { + sameResultCounter++; + } + } + } } + } finally { + running = false; } } diff --git a/drools-test-coverage/test-compiler-integration/src/test/resources/logback-test.xml b/drools-test-coverage/test-compiler-integration/src/test/resources/logback-test.xml index ce4cf145c90..b1dc748b8e8 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/resources/logback-test.xml +++ b/drools-test-coverage/test-compiler-integration/src/test/resources/logback-test.xml @@ -30,6 +30,11 @@ + + + + + diff --git a/pom.xml b/pom.xml index c23c483f355..11d60a0a52c 100644 --- a/pom.xml +++ b/pom.xml @@ -207,7 +207,7 @@ drools-model drools-examples-api drools-test-coverage - drools-scenario-simulation +