Skip to content

Commit

Permalink
delete after failover, a candidate fix (#5373)
Browse files Browse the repository at this point in the history
  • Loading branch information
nprentza authored Jul 10, 2023
1 parent 117686c commit ef6a7bd
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@

package org.drools.reliability.core;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.drools.core.SessionConfiguration;
import org.drools.core.WorkingMemoryEntryPoint;
import org.drools.core.common.InternalFactHandle;
Expand All @@ -33,6 +29,10 @@
import org.kie.api.runtime.conf.PersistedSessionOption;
import org.kie.api.runtime.rule.EntryPoint;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.drools.reliability.core.ReliablePropagationList.PROPAGATION_LIST;

public class ReliableSessionInitializer {
Expand Down Expand Up @@ -68,8 +68,10 @@ public InternalWorkingMemory init(InternalWorkingMemory session, PersistedSessio
private void onWorkingMemoryAction(InternalWorkingMemory session, PropagationEntry entry) {
if (entry instanceof PropagationEntry.Insert) {
InternalFactHandle fh = ((PropagationEntry.Insert) entry).getHandle();
WorkingMemoryEntryPoint ep = fh.getEntryPoint(session);
((SimpleReliableObjectStore) ep.getObjectStore()).putIntoPersistedStorage(fh, true);
if (fh.isValid()) {
WorkingMemoryEntryPoint ep = fh.getEntryPoint(session);
((SimpleReliableObjectStore) ep.getObjectStore()).putIntoPersistedStorage(fh, true);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.kie.api.runtime.rule.FactHandle;
import org.test.domain.Person;

import java.util.Optional;

import static org.assertj.core.api.Assertions.assertThat;

@ExtendWith(BeforeAllMethodExtension.class)
Expand Down Expand Up @@ -215,6 +217,45 @@ void deleteBeforeFailover_shouldRecoverFromFailover(PersistedSessionOption.Persi
assertThat(getResults()).containsExactlyInAnyOrder("Toshiya");
}

@ParameterizedTest
@MethodSource("strategyProviderStoresOnlyWithExplicitSafepoints")
void deleteAfterFailover_shouldNotMatch(PersistedSessionOption.PersistenceStrategy persistenceStrategy, PersistedSessionOption.SafepointStrategy safepointStrategy){
createSession(BASIC_RULE, persistenceStrategy, safepointStrategy);

insert("M");
Person pMike = new Person("Mike", 23);
insert(pMike);

failover();
restoreSession(BASIC_RULE, persistenceStrategy, safepointStrategy);
clearResults();

Optional<FactHandle> getFactHandleForPerson = getFactHandleForPerson(pMike);
if (!getFactHandleForPerson.isEmpty()){
delete(getFactHandleForPerson.get());
}

assertThat(fireAllRules()).isEqualTo(0);
}

@ParameterizedTest
@MethodSource("strategyProviderStoresOnlyWithExplicitSafepoints")
void deleteBeforeFailover_shouldNotMatch(PersistedSessionOption.PersistenceStrategy persistenceStrategy, PersistedSessionOption.SafepointStrategy safepointStrategy){
createSession(BASIC_RULE, persistenceStrategy, safepointStrategy);

insert("M");
Person pMike = new Person("Mike", 23);
FactHandle fhMike = insert(pMike);

delete(fhMike);

failover();
restoreSession(BASIC_RULE, persistenceStrategy, safepointStrategy);
clearResults();

assertThat(fireAllRules()).isEqualTo(0);
}

@ParameterizedTest
@MethodSource("strategyProviderStoresOnlyWithExplicitSafepoints")
void updateByObjectBeforeFailover_shouldMatchUpdatedFact(PersistedSessionOption.PersistenceStrategy persistenceStrategy, PersistedSessionOption.SafepointStrategy safepointStrategy){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,18 @@ protected Optional<Person> getPersonByName(KieSession kieSession, String name) {
.filter(p -> p.getName().equals(name) ).findFirst();
}

protected Optional<FactHandle> getFactHandleForPerson(Person person){
return getFactHandleForPerson(sessions.get(0), person);
}

protected Optional<FactHandle> getFactHandleForPerson(KieSession kieSession, Person person){
return kieSession.getFactHandles()
.stream()
.filter(p -> p.getObject() instanceof Person)
.filter(p -> ( (Person) p.getObject()).getName().equals(person.getName()) )
.filter(p -> ( (Person) p.getObject()).getAge()==person.getAge() ).findFirst();
}

private static class OptionsFilter {
private final Option[] options;

Expand Down

0 comments on commit ef6a7bd

Please sign in to comment.