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-7494] delete after failover #5373

Merged
merged 1 commit into from
Jul 10, 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 @@ -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