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 2eceb3057ec..8851527e2ca 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 @@ -20,6 +20,7 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.conf.EventProcessingOption; +import org.kie.api.runtime.KieSession; import org.kie.api.runtime.conf.ClockTypeOption; import org.kie.api.runtime.conf.PersistedSessionOption; import org.kie.api.time.SessionPseudoClock; @@ -79,6 +80,41 @@ void insertAdvanceInsertFailoverFire_shouldRecoverFromFailover(PersistedSessionO assertThat(getResults()).isEmpty(); } + @ParameterizedTest + @MethodSource("strategyProviderStoresOnlyWithExplicitSafepoints") // FULL fails with "ReliablePropagationList; no valid constructor" + void insertAdvanceInsertFailoverFireTwice_shouldRecoverFromFailover(PersistedSessionOption.PersistenceStrategy persistenceStrategy, PersistedSessionOption.SafepointStrategy safepointStrategy) { + + KieSession session1 = createSession(CEP_RULE, persistenceStrategy, safepointStrategy, EventProcessingOption.STREAM, ClockTypeOption.PSEUDO); + + SessionPseudoClock clock = getSessionClock(session1); + + insert(session1, new StockTick("DROO")); + clock.advanceTime(6, TimeUnit.SECONDS); + insert(session1, new StockTick("ACME")); + + //-- 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); + clock = getSessionClock(session1); + + assertThat(fireAllRules(session1)).isEqualTo(1); + assertThat(getResults(session1)).containsExactlyInAnyOrder("fired"); + clearResults(session1); + + clock.advanceTime(3, TimeUnit.SECONDS); + insert(session1, new StockTick("ACME")); + + //-- 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); + clock = getSessionClock(session1); + + assertThat(fireAllRules(session1)).isZero(); + assertThat(getResults(session1)).isEmpty(); + } + @ParameterizedTest @MethodSource("strategyProviderStoresOnlyWithExplicitSafepoints") void insertAdvanceFailoverExpireFire_shouldExpireAfterFailover(PersistedSessionOption.PersistenceStrategy persistenceStrategy, PersistedSessionOption.SafepointStrategy safepointStrategy) { 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 3612104b4e1..757e8bba433 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 @@ -17,9 +17,11 @@ import org.drools.base.facttemplates.Event; import org.drools.core.ClassObjectFilter; +import org.drools.kiesession.session.StatefulKnowledgeSessionImpl; import org.drools.model.Model; import org.drools.model.codegen.ExecutableModelProject; import org.drools.modelcompiler.KieBaseBuilder; +import org.drools.reliability.core.ReliableGlobalResolver; import org.drools.reliability.core.ReliableKieSession; import org.drools.reliability.core.ReliableRuntimeComponentFactoryImpl; import org.drools.reliability.core.StorageManagerFactory; @@ -220,6 +222,7 @@ protected void clearResults() { protected void clearResults(KieSession session) { ((List) session.getGlobal("results")).clear(); + ((ReliableGlobalResolver)((StatefulKnowledgeSessionImpl) session).getGlobalResolver()).updateStorage(); } protected KieSession createSession(String drl, PersistedSessionOption.PersistenceStrategy persistenceStrategy, Option... options) {