Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DROOLS-7491 - updateStorage after clearResults #5364

Merged
merged 2 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -220,6 +222,7 @@ protected void clearResults() {

protected void clearResults(KieSession session) {
((List<Object>) session.getGlobal("results")).clear();
((ReliableGlobalResolver)((StatefulKnowledgeSessionImpl) session).getGlobalResolver()).updateStorage();
}

protected KieSession createSession(String drl, PersistedSessionOption.PersistenceStrategy persistenceStrategy, Option... options) {
Expand Down
Loading