From eeaf429887ec2227d86f8f3ee0764b145327e59d Mon Sep 17 00:00:00 2001 From: Toshiya Kobayashi Date: Thu, 13 Jul 2023 15:49:50 +0900 Subject: [PATCH] [DROOLS-7485] StoresOnly Strategy - multiple kieSession from the same KieBase test (#5387) - Parameterize multiple ksession tests to use multiple kbases or one kbase --- .../infinispan/ReliabilityCepTest.java | 40 +++++----- .../infinispan/ReliabilityTest.java | 80 +++++++++---------- .../infinispan/ReliabilityTestBasics.java | 36 ++++++++- 3 files changed, 95 insertions(+), 61 deletions(-) diff --git a/drools-reliability/drools-reliability-infinispan/src/test/java/org/drools/reliability/infinispan/ReliabilityCepTest.java b/drools-reliability/drools-reliability-infinispan/src/test/java/org/drools/reliability/infinispan/ReliabilityCepTest.java index 44a1915eac1..3e1b4e8a066 100644 --- a/drools-reliability/drools-reliability-infinispan/src/test/java/org/drools/reliability/infinispan/ReliabilityCepTest.java +++ b/drools-reliability/drools-reliability-infinispan/src/test/java/org/drools/reliability/infinispan/ReliabilityCepTest.java @@ -161,10 +161,10 @@ void insertAdvanceFireFailoverExpire_shouldExpireAfterFailover(PersistedSessionO } @ParameterizedTest - @MethodSource("strategyProviderStoresOnlyWithExplicitSafepoints") - void multipleKieSessions_insertAdvanceInsertFailoverFire_shouldRecoverFromFailover(PersistedSessionOption.PersistenceStrategy persistenceStrategy, PersistedSessionOption.SafepointStrategy safepointStrategy) { - KieSession session1 = createSession(CEP_RULE, persistenceStrategy, safepointStrategy, EventProcessingOption.STREAM, ClockTypeOption.PSEUDO); - KieSession session2 = createSession(CEP_RULE, persistenceStrategy, safepointStrategy, EventProcessingOption.STREAM, ClockTypeOption.PSEUDO); + @MethodSource("strategyProviderStoresOnlyWithExplicitSafepointsAndKieBaseCache") + void multipleKieSessions_insertAdvanceInsertFailoverFire_shouldRecoverFromFailover(PersistedSessionOption.PersistenceStrategy persistenceStrategy, PersistedSessionOption.SafepointStrategy safepointStrategy, boolean useKieBaseCache) { + KieSession session1 = createSession(CEP_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache, EventProcessingOption.STREAM, ClockTypeOption.PSEUDO); + KieSession session2 = createSession(CEP_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache, EventProcessingOption.STREAM, ClockTypeOption.PSEUDO); SessionPseudoClock clock1 = getSessionClock(session1); SessionPseudoClock clock2 = getSessionClock(session2); @@ -180,9 +180,9 @@ void multipleKieSessions_insertAdvanceInsertFailoverFire_shouldRecoverFromFailov //-- Assume JVM down here. Fail-over to other JVM or rebooted JVM //-- ksession and kbase are lost. CacheManager is recreated. Client knows only "id" failover(); - session1=restoreSession(session1.getIdentifier(), CEP_RULE, persistenceStrategy, safepointStrategy, EventProcessingOption.STREAM, ClockTypeOption.PSEUDO); + session1=restoreSession(session1.getIdentifier(), CEP_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache, EventProcessingOption.STREAM, ClockTypeOption.PSEUDO); clock1 = getSessionClock(session1); - session2=restoreSession(session2.getIdentifier(), CEP_RULE, persistenceStrategy, safepointStrategy, EventProcessingOption.STREAM, ClockTypeOption.PSEUDO); + session2=restoreSession(session2.getIdentifier(), CEP_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache, EventProcessingOption.STREAM, ClockTypeOption.PSEUDO); clock2 = getSessionClock(session2); assertThat(fireAllRules(session1)).isEqualTo(1); @@ -200,9 +200,9 @@ void multipleKieSessions_insertAdvanceInsertFailoverFire_shouldRecoverFromFailov insert(session2, new StockTick("ACME")); failover(); - session1=restoreSession(session1.getIdentifier(), CEP_RULE, persistenceStrategy, safepointStrategy, EventProcessingOption.STREAM, ClockTypeOption.PSEUDO); + session1=restoreSession(session1.getIdentifier(), CEP_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache, EventProcessingOption.STREAM, ClockTypeOption.PSEUDO); clock1 = getSessionClock(session1); - session2=restoreSession(session2.getIdentifier(), CEP_RULE, persistenceStrategy, safepointStrategy, EventProcessingOption.STREAM, ClockTypeOption.PSEUDO); + session2=restoreSession(session2.getIdentifier(), CEP_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache, EventProcessingOption.STREAM, ClockTypeOption.PSEUDO); clock2 = getSessionClock(session2); assertThat(fireAllRules(session1)).isEqualTo(0); @@ -216,11 +216,11 @@ void multipleKieSessions_insertAdvanceInsertFailoverFire_shouldRecoverFromFailov } @ParameterizedTest - @MethodSource("strategyProviderStoresOnlyWithExplicitSafepoints") - void multipleKieSessions_insertAdvanceFailoverExpireFire_shouldExpireAfterFailover(PersistedSessionOption.PersistenceStrategy persistenceStrategy, PersistedSessionOption.SafepointStrategy safepointStrategy) { + @MethodSource("strategyProviderStoresOnlyWithExplicitSafepointsAndKieBaseCache") + void multipleKieSessions_insertAdvanceFailoverExpireFire_shouldExpireAfterFailover(PersistedSessionOption.PersistenceStrategy persistenceStrategy, PersistedSessionOption.SafepointStrategy safepointStrategy, boolean useKieBaseCache) { - KieSession session1 = createSession(CEP_RULE, persistenceStrategy, safepointStrategy, EventProcessingOption.STREAM, ClockTypeOption.PSEUDO); - KieSession session2 = createSession(CEP_RULE, persistenceStrategy, safepointStrategy, EventProcessingOption.STREAM, ClockTypeOption.PSEUDO); + KieSession session1 = createSession(CEP_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache, EventProcessingOption.STREAM, ClockTypeOption.PSEUDO); + KieSession session2 = createSession(CEP_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache, EventProcessingOption.STREAM, ClockTypeOption.PSEUDO); SessionPseudoClock clock1 = getSessionClock(session1); SessionPseudoClock clock2 = getSessionClock(session2); @@ -234,9 +234,9 @@ void multipleKieSessions_insertAdvanceFailoverExpireFire_shouldExpireAfterFailov insert(session2, new StockTick("ACME")); failover(); - session1 = restoreSession(session1.getIdentifier(), CEP_RULE, persistenceStrategy, safepointStrategy, EventProcessingOption.STREAM, ClockTypeOption.PSEUDO); + session1 = restoreSession(session1.getIdentifier(), CEP_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache, EventProcessingOption.STREAM, ClockTypeOption.PSEUDO); clock1 = getSessionClock(session1); - session2 = restoreSession(session2.getIdentifier(), CEP_RULE, persistenceStrategy, safepointStrategy, EventProcessingOption.STREAM, ClockTypeOption.PSEUDO); + session2 = restoreSession(session2.getIdentifier(), CEP_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache, EventProcessingOption.STREAM, ClockTypeOption.PSEUDO); clock2 = getSessionClock(session2); clock1.advanceTime(58, TimeUnit.SECONDS); @@ -252,12 +252,12 @@ void multipleKieSessions_insertAdvanceFailoverExpireFire_shouldExpireAfterFailov } @ParameterizedTest - @MethodSource("strategyProviderStoresOnlyWithExplicitSafepoints") - void multipleKieSessions_insertAdvanceFireFailoverExpire_shouldExpireAfterFailover(PersistedSessionOption.PersistenceStrategy persistenceStrategy, PersistedSessionOption.SafepointStrategy safepointStrategy) { + @MethodSource("strategyProviderStoresOnlyWithExplicitSafepointsAndKieBaseCache") + void multipleKieSessions_insertAdvanceFireFailoverExpire_shouldExpireAfterFailover(PersistedSessionOption.PersistenceStrategy persistenceStrategy, PersistedSessionOption.SafepointStrategy safepointStrategy, boolean useKieBaseCache) { - KieSession session1 = createSession(CEP_RULE, persistenceStrategy, safepointStrategy, EventProcessingOption.STREAM, ClockTypeOption.PSEUDO); + KieSession session1 = createSession(CEP_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache, EventProcessingOption.STREAM, ClockTypeOption.PSEUDO); SessionPseudoClock clock1 = getSessionClock(session1); - KieSession session2 = createSession(CEP_RULE, persistenceStrategy, safepointStrategy, EventProcessingOption.STREAM, ClockTypeOption.PSEUDO); + KieSession session2 = createSession(CEP_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache, EventProcessingOption.STREAM, ClockTypeOption.PSEUDO); SessionPseudoClock clock2 = getSessionClock(session2); insert(session1, new StockTick("DROO")); @@ -272,9 +272,9 @@ void multipleKieSessions_insertAdvanceFireFailoverExpire_shouldExpireAfterFailov assertThat(fireAllRules(session2)).isEqualTo(0); failover(); - session1 = restoreSession(session1.getIdentifier(), CEP_RULE, persistenceStrategy, safepointStrategy, EventProcessingOption.STREAM, ClockTypeOption.PSEUDO); + session1 = restoreSession(session1.getIdentifier(), CEP_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache, EventProcessingOption.STREAM, ClockTypeOption.PSEUDO); clock1 = getSessionClock(session1); - session2 = restoreSession(session2.getIdentifier(), CEP_RULE, persistenceStrategy, safepointStrategy, EventProcessingOption.STREAM, ClockTypeOption.PSEUDO); + session2 = restoreSession(session2.getIdentifier(), CEP_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache, EventProcessingOption.STREAM, ClockTypeOption.PSEUDO); clock2 = getSessionClock(session2); clock1.advanceTime(58, TimeUnit.SECONDS); diff --git a/drools-reliability/drools-reliability-infinispan/src/test/java/org/drools/reliability/infinispan/ReliabilityTest.java b/drools-reliability/drools-reliability-infinispan/src/test/java/org/drools/reliability/infinispan/ReliabilityTest.java index b10bc94bbae..23d1887913e 100644 --- a/drools-reliability/drools-reliability-infinispan/src/test/java/org/drools/reliability/infinispan/ReliabilityTest.java +++ b/drools-reliability/drools-reliability-infinispan/src/test/java/org/drools/reliability/infinispan/ReliabilityTest.java @@ -282,10 +282,10 @@ void updateByObjectBeforeFailover_shouldMatchUpdatedFact(PersistedSessionOption. } @ParameterizedTest - @MethodSource("strategyProviderStoresOnlyWithExplicitSafepoints") - void multipleKieSessions_BasicTest(PersistedSessionOption.PersistenceStrategy persistenceStrategy, PersistedSessionOption.SafepointStrategy safepointStrategy) { - KieSession session1 = createSession(BASIC_RULE, persistenceStrategy, safepointStrategy); - KieSession session2 = createSession(BASIC_RULE, persistenceStrategy, safepointStrategy); + @MethodSource("strategyProviderStoresOnlyWithExplicitSafepointsAndKieBaseCache") + void multipleKieSessions_BasicTest(PersistedSessionOption.PersistenceStrategy persistenceStrategy, PersistedSessionOption.SafepointStrategy safepointStrategy, boolean useKieBaseCache) { + KieSession session1 = createSession(BASIC_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache); + KieSession session2 = createSession(BASIC_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache); insert(session1, "M"); insert(session2, "N"); @@ -298,8 +298,8 @@ void multipleKieSessions_BasicTest(PersistedSessionOption.PersistenceStrategy pe failover(); - session1 = restoreSession(session1.getIdentifier(), BASIC_RULE, persistenceStrategy, safepointStrategy); - session2 = restoreSession(session2.getIdentifier(), BASIC_RULE, persistenceStrategy, safepointStrategy); + session1 = restoreSession(session1.getIdentifier(), BASIC_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache); + session2 = restoreSession(session2.getIdentifier(), BASIC_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache); // clear results clearResults(session1); @@ -313,10 +313,10 @@ void multipleKieSessions_BasicTest(PersistedSessionOption.PersistenceStrategy pe } @ParameterizedTest - @MethodSource("strategyProviderStoresOnlyWithExplicitSafepoints") // FULL fails with "ReliablePropagationList; no valid constructor" - void multipleKieSessions_insertFailoverInsertFire_shouldRecoverFromFailover(PersistedSessionOption.PersistenceStrategy persistenceStrategy, PersistedSessionOption.SafepointStrategy safepointStrategy) { - KieSession session1 = createSession(BASIC_RULE, persistenceStrategy, safepointStrategy); - KieSession session2 = createSession(BASIC_RULE, persistenceStrategy, safepointStrategy); + @MethodSource("strategyProviderStoresOnlyWithExplicitSafepointsAndKieBaseCache") // FULL fails with "ReliablePropagationList; no valid constructor" + void multipleKieSessions_insertFailoverInsertFire_shouldRecoverFromFailover(PersistedSessionOption.PersistenceStrategy persistenceStrategy, PersistedSessionOption.SafepointStrategy safepointStrategy, boolean useKieBaseCache) { + KieSession session1 = createSession(BASIC_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache); + KieSession session2 = createSession(BASIC_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache); insert(session1,"M"); insertMatchingPerson(session1, "Mike", 37); @@ -325,8 +325,8 @@ void multipleKieSessions_insertFailoverInsertFire_shouldRecoverFromFailover(Pers failover(); - session1 = restoreSession(session1.getIdentifier(), BASIC_RULE, persistenceStrategy, safepointStrategy); - session2 = restoreSession(session2.getIdentifier(), BASIC_RULE, persistenceStrategy, safepointStrategy); + session1 = restoreSession(session1.getIdentifier(), BASIC_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache); + session2 = restoreSession(session2.getIdentifier(), BASIC_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache); insertNonMatchingPerson(session1,"Toshiya", 35); insertMatchingPerson(session2,"Nicole", 40); @@ -339,11 +339,11 @@ void multipleKieSessions_insertFailoverInsertFire_shouldRecoverFromFailover(Pers } @ParameterizedTest - @MethodSource("strategyProviderStoresOnlyWithExplicitSafepoints") // With Remote, FULL fails with "ReliablePropagationList; no valid constructor" even without failover - void multipleKieSessions_noFailover(PersistedSessionOption.PersistenceStrategy persistenceStrategy, PersistedSessionOption.SafepointStrategy safepointStrategy) { + @MethodSource("strategyProviderStoresOnlyWithExplicitSafepointsAndKieBaseCache") // With Remote, FULL fails with "ReliablePropagationList; no valid constructor" even without failover + void multipleKieSessions_noFailover(PersistedSessionOption.PersistenceStrategy persistenceStrategy, PersistedSessionOption.SafepointStrategy safepointStrategy, boolean useKieBaseCache) { - KieSession session1 = createSession(BASIC_RULE, persistenceStrategy, safepointStrategy); - KieSession session2 = createSession(BASIC_RULE, persistenceStrategy, safepointStrategy); + KieSession session1 = createSession(BASIC_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache); + KieSession session2 = createSession(BASIC_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache); insert(session1,"M"); insertMatchingPerson(session1,"Matching Person One", 37); @@ -353,8 +353,8 @@ void multipleKieSessions_noFailover(PersistedSessionOption.PersistenceStrategy p safepoint(); } - session1 = restoreSession(session1.getIdentifier(), BASIC_RULE, persistenceStrategy, safepointStrategy); - session2 = restoreSession(session2.getIdentifier(), BASIC_RULE, persistenceStrategy, safepointStrategy); + session1 = restoreSession(session1.getIdentifier(), BASIC_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache); + session2 = restoreSession(session2.getIdentifier(), BASIC_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache); insertNonMatchingPerson(session1,"Toshiya", 41); insertMatchingPerson(session1,"Matching Person Two", 40); @@ -368,11 +368,11 @@ void multipleKieSessions_noFailover(PersistedSessionOption.PersistenceStrategy p } @ParameterizedTest - @MethodSource("strategyProviderStoresOnlyWithExplicitSafepoints") // FULL fails with "ReliablePropagationList; no valid constructor" - void multipleKieSessions_insertFireInsertFailoverInsertFire_shouldMatchFactInsertedBeforeFailover(PersistedSessionOption.PersistenceStrategy persistenceStrategy, PersistedSessionOption.SafepointStrategy safepointStrategy) { + @MethodSource("strategyProviderStoresOnlyWithExplicitSafepointsAndKieBaseCache") // FULL fails with "ReliablePropagationList; no valid constructor" + void multipleKieSessions_insertFireInsertFailoverInsertFire_shouldMatchFactInsertedBeforeFailover(PersistedSessionOption.PersistenceStrategy persistenceStrategy, PersistedSessionOption.SafepointStrategy safepointStrategy, boolean useKieBaseCache) { - KieSession session1 = createSession(BASIC_RULE, persistenceStrategy, safepointStrategy); - KieSession session2 = createSession(BASIC_RULE, persistenceStrategy, safepointStrategy); + KieSession session1 = createSession(BASIC_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache); + KieSession session2 = createSession(BASIC_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache); insert(session1,"M"); insertMatchingPerson(session1,"Matching Person One", 37); @@ -387,8 +387,8 @@ void multipleKieSessions_insertFireInsertFailoverInsertFire_shouldMatchFactInser failover(); - session1 = restoreSession(session1.getIdentifier(),BASIC_RULE, persistenceStrategy, safepointStrategy); - session2 = restoreSession(session2.getIdentifier(), BASIC_RULE, persistenceStrategy, safepointStrategy); + session1 = restoreSession(session1.getIdentifier(),BASIC_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache); + session2 = restoreSession(session2.getIdentifier(), BASIC_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache); clearResults(session1); clearResults(session2); @@ -406,10 +406,10 @@ void multipleKieSessions_insertFireInsertFailoverInsertFire_shouldMatchFactInser } @ParameterizedTest - @MethodSource("strategyProviderStoresOnlyWithExplicitSafepoints") // FULL fails with "ReliablePropagationList; no valid constructor" - void multipleKieSessions_updateBeforeFailover_shouldRecoverFromFailover(PersistedSessionOption.PersistenceStrategy persistenceStrategy, PersistedSessionOption.SafepointStrategy safepointStrategy) { - KieSession session1 = createSession(BASIC_RULE, persistenceStrategy, safepointStrategy); - KieSession session2 = createSession(BASIC_RULE, persistenceStrategy, safepointStrategy); + @MethodSource("strategyProviderStoresOnlyWithExplicitSafepointsAndKieBaseCache") // FULL fails with "ReliablePropagationList; no valid constructor" + void multipleKieSessions_updateBeforeFailover_shouldRecoverFromFailover(PersistedSessionOption.PersistenceStrategy persistenceStrategy, PersistedSessionOption.SafepointStrategy safepointStrategy, boolean useKieBaseCache) { + KieSession session1 = createSession(BASIC_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache); + KieSession session2 = createSession(BASIC_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache); insert(session1,"M"); Person p1 = new Person("Mario", 49); @@ -429,8 +429,8 @@ void multipleKieSessions_updateBeforeFailover_shouldRecoverFromFailover(Persiste update(session1, fh2, p2); failover(); - session1 = restoreSession(session1.getIdentifier(), BASIC_RULE, persistenceStrategy, safepointStrategy); - session2 = restoreSession(session2.getIdentifier(), BASIC_RULE, persistenceStrategy, safepointStrategy); + session1 = restoreSession(session1.getIdentifier(), BASIC_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache); + session2 = restoreSession(session2.getIdentifier(), BASIC_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache); assertThat(fireAllRules(session1)).isEqualTo(1); assertThat(getResults(session1)).containsExactlyInAnyOrder("Mario", "MegaToshiya"); @@ -438,8 +438,8 @@ void multipleKieSessions_updateBeforeFailover_shouldRecoverFromFailover(Persiste assertThat(getResults(session2)).containsExactlyInAnyOrder("Toshiya"); failover(); - session1 = restoreSession(session1.getIdentifier(), BASIC_RULE, persistenceStrategy, safepointStrategy); - session2 = restoreSession(session2.getIdentifier(), BASIC_RULE, persistenceStrategy, safepointStrategy); + session1 = restoreSession(session1.getIdentifier(), BASIC_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache); + session2 = restoreSession(session2.getIdentifier(), BASIC_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache); clearResults(session1); clearResults(session2); @@ -451,11 +451,11 @@ void multipleKieSessions_updateBeforeFailover_shouldRecoverFromFailover(Persiste } @ParameterizedTest - @MethodSource("strategyProviderStoresOnlyWithExplicitSafepoints") // FULL fails with "ReliablePropagationList; no valid constructor" - void multipleKieSessions_deleteBeforeFailover_shouldRecoverFromFailover(PersistedSessionOption.PersistenceStrategy persistenceStrategy, PersistedSessionOption.SafepointStrategy safepointStrategy) { + @MethodSource("strategyProviderStoresOnlyWithExplicitSafepointsAndKieBaseCache") // FULL fails with "ReliablePropagationList; no valid constructor" + void multipleKieSessions_deleteBeforeFailover_shouldRecoverFromFailover(PersistedSessionOption.PersistenceStrategy persistenceStrategy, PersistedSessionOption.SafepointStrategy safepointStrategy, boolean useKieBaseCache) { - KieSession session1 = createSession(BASIC_RULE, persistenceStrategy, safepointStrategy); - KieSession session2 = createSession(BASIC_RULE, persistenceStrategy, safepointStrategy); + KieSession session1 = createSession(BASIC_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache); + KieSession session2 = createSession(BASIC_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache); FactHandle fhStringM = insert(session1,"M"); insertMatchingPerson(session1,"Matching Person One",37); @@ -471,8 +471,8 @@ void multipleKieSessions_deleteBeforeFailover_shouldRecoverFromFailover(Persiste failover(); - session1 = restoreSession(session1.getIdentifier(), BASIC_RULE, persistenceStrategy, safepointStrategy); - session2 = restoreSession(session2.getIdentifier(), BASIC_RULE, persistenceStrategy, safepointStrategy); + session1 = restoreSession(session1.getIdentifier(), BASIC_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache); + session2 = restoreSession(session2.getIdentifier(), BASIC_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache); clearResults(session1); clearResults(session2); @@ -487,8 +487,8 @@ void multipleKieSessions_deleteBeforeFailover_shouldRecoverFromFailover(Persiste insert(session1,"T"); failover(); - session1 = restoreSession(session1.getIdentifier(), BASIC_RULE, persistenceStrategy, safepointStrategy); - session2 = restoreSession(session2.getIdentifier(), BASIC_RULE, persistenceStrategy, safepointStrategy); + session1 = restoreSession(session1.getIdentifier(), BASIC_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache); + session2 = restoreSession(session2.getIdentifier(), BASIC_RULE, persistenceStrategy, safepointStrategy, useKieBaseCache); assertThat(fireAllRules(session1)).isEqualTo(1); assertThat(getResults(session1)).containsExactlyInAnyOrder("Toshiya"); diff --git a/drools-reliability/drools-reliability-infinispan/src/test/java/org/drools/reliability/infinispan/ReliabilityTestBasics.java b/drools-reliability/drools-reliability-infinispan/src/test/java/org/drools/reliability/infinispan/ReliabilityTestBasics.java index d389bc79daa..f1d84d813ab 100644 --- a/drools-reliability/drools-reliability-infinispan/src/test/java/org/drools/reliability/infinispan/ReliabilityTestBasics.java +++ b/drools-reliability/drools-reliability-infinispan/src/test/java/org/drools/reliability/infinispan/ReliabilityTestBasics.java @@ -68,6 +68,8 @@ public abstract class ReliabilityTestBasics { public static final String SYNTHETIC_RULE_TAG = "SYNTHETIC_RULE"; private static final Logger LOG = LoggerFactory.getLogger(ReliabilityTestBasics.class); + private final HashMap kieBaseCache = new HashMap<>(); + private InfinispanContainer container; protected final List sessions = new ArrayList<>(); @@ -90,6 +92,15 @@ static Stream strategyProviderStoresOnlyWithExplicitSafepoints() { ); } + static Stream strategyProviderStoresOnlyWithExplicitSafepointsAndKieBaseCache() { + return Stream.of( + arguments(PersistedSessionOption.PersistenceStrategy.STORES_ONLY, PersistedSessionOption.SafepointStrategy.ALWAYS, true), + arguments(PersistedSessionOption.PersistenceStrategy.STORES_ONLY, PersistedSessionOption.SafepointStrategy.ALWAYS, false), + arguments(PersistedSessionOption.PersistenceStrategy.STORES_ONLY, PersistedSessionOption.SafepointStrategy.EXPLICIT, true), + arguments(PersistedSessionOption.PersistenceStrategy.STORES_ONLY, PersistedSessionOption.SafepointStrategy.EXPLICIT, false) + ); + } + static Stream strategyProviderStoresOnlyWithAllSafepoints() { return Stream.of( arguments(PersistedSessionOption.PersistenceStrategy.STORES_ONLY, PersistedSessionOption.SafepointStrategy.ALWAYS), @@ -138,6 +149,7 @@ public void failover() { this.sessions.stream().map(ReliableKieSession.class::cast).forEach(ReliableKieSession::safepoint); } sessions.clear(); + kieBaseCache.clear(); if (((TestableStorageManager) StorageManagerFactory.get().getStorageManager()).isRemote()) { // fail-over means restarting Drools instance. Assuming remote infinispan keeps alive @@ -233,6 +245,10 @@ protected KieSession createSession(String drl, PersistedSessionOption.Persistenc return getKieSession(drl, persistenceStrategy != null ? PersistedSessionOption.newSession().withPersistenceStrategy(persistenceStrategy).withSafepointStrategy(safepointStrategy) : null, options); } + protected KieSession createSession(String drl, PersistedSessionOption.PersistenceStrategy persistenceStrategy, PersistedSessionOption.SafepointStrategy safepointStrategy, boolean useKieBaseCache, Option... options) { + return getKieSession(drl, persistenceStrategy != null ? PersistedSessionOption.newSession().withPersistenceStrategy(persistenceStrategy).withSafepointStrategy(safepointStrategy) : null, useKieBaseCache, options); + } + protected KieSession createSession(Model ruleModel, PersistedSessionOption.PersistenceStrategy persistenceStrategy, PersistedSessionOption.SafepointStrategy safepointStrategy, Option... options) { return getKieSession(ruleModel, persistenceStrategy != null ? PersistedSessionOption.newSession().withPersistenceStrategy(persistenceStrategy).withSafepointStrategy(safepointStrategy) : null, options); } @@ -251,6 +267,11 @@ protected KieSession restoreSession(Long sessionId, String drl, PersistedSession return getKieSession(drl, PersistedSessionOption.fromSession(sessionIdToRestoreFrom).withPersistenceStrategy(persistenceStrategy).withSafepointStrategy(safepointStrategy), options); } + protected KieSession restoreSession(Long sessionId, String drl, PersistedSessionOption.PersistenceStrategy persistenceStrategy, PersistedSessionOption.SafepointStrategy safepointStrategy, boolean useKieBaseCache, Option... options) { + Long sessionIdToRestoreFrom = this.persistedSessionIds.get(sessionId); + return getKieSession(drl, PersistedSessionOption.fromSession(sessionIdToRestoreFrom).withPersistenceStrategy(persistenceStrategy).withSafepointStrategy(safepointStrategy), useKieBaseCache, options); + } + protected int fireAllRules() { return fireAllRules(sessions.get(0)); } @@ -301,11 +322,24 @@ protected long getSessionIdentifier() { } protected KieSession getKieSession(String drl, PersistedSessionOption persistedSessionOption, Option... options) { + return getKieSession(drl, persistedSessionOption, true, options); + } + + protected KieSession getKieSession(String drl, PersistedSessionOption persistedSessionOption, boolean useKieBaseCache, Option... options) { OptionsFilter optionsFilter = new OptionsFilter(options); - KieBase kbase = new KieHelper().addContent(drl, ResourceType.DRL).build(ExecutableModelProject.class, optionsFilter.getKieBaseOptions()); + KieBase kbase; + if (useKieBaseCache) { + kbase = kieBaseCache.computeIfAbsent(drl, k -> createKieBase(drl, optionsFilter)); + } else { + kbase = createKieBase(drl, optionsFilter); + } return getKieSessionFromKieBase(kbase, persistedSessionOption, optionsFilter); } + private static KieBase createKieBase(String drl, OptionsFilter optionsFilter) { + return new KieHelper().addContent(drl, ResourceType.DRL).build(ExecutableModelProject.class, optionsFilter.getKieBaseOptions()); + } + protected KieSession getKieSession(Model ruleModel, PersistedSessionOption persistedSessionOption, Option... options) { OptionsFilter optionsFilter = new OptionsFilter(options); KieBase kbase = KieBaseBuilder.createKieBaseFromModel(ruleModel, optionsFilter.getKieBaseOptions());