-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
D7507 structured data persistency #5392
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
...iability-tests/src/test/java/org/drools/reliability/test/ReliabilityFireAndAlarmTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package org.drools.reliability.test; | ||
|
||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
import org.kie.api.runtime.conf.PersistedSessionOption; | ||
import org.kie.api.runtime.rule.FactHandle; | ||
import org.test.domain.fireandalarm.Alarm; | ||
import org.test.domain.fireandalarm.Fire; | ||
import org.test.domain.fireandalarm.Room; | ||
import org.test.domain.fireandalarm.Sprinkler; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class ReliabilityFireAndAlarmTest extends ReliabilityTestBasics{ | ||
private static final String FIRE_AND_ALARM = | ||
"import " + Alarm.class.getCanonicalName() + ";" + | ||
"import " + Fire.class.getCanonicalName() + ";" + | ||
"import " + Sprinkler.class.getCanonicalName() + ";" + | ||
"import " + Room.class.getCanonicalName() + ";" + | ||
"global java.util.List results;" + | ||
"rule 'When there is a fire turn on the sprinkler' when\n" + | ||
" Fire($room : room) \n" + | ||
" $sprinkler: Sprinkler( room == $room, on == false ) \n" + | ||
"then\n" + | ||
" modify($sprinkler) { setOn(true); } \n" + | ||
" System.out.println(\"Turn on the sprinkler for room\" + $room.getName()); \n" + | ||
"end\n" + | ||
"rule 'Raise the alarm when we have one or more firs' when\n" + | ||
" exists Fire() \n" + | ||
"then\n" + | ||
" insert( new Alarm() );\n" + | ||
" System.out.println(\"Raise the alarm\");\n" + | ||
"end\n"+ | ||
"rule 'Cancel the alarm when all the fires have gone' when \n" + | ||
" not Fire() \n" + | ||
" $alarm : Alarm() \n" + | ||
"then\n" + | ||
" delete ( $alarm ); \n" + | ||
" System.out.println(\"Cancel the alarm\"); \n" + | ||
"end\n" + | ||
"rule 'Status output when things are ok' when\n" + | ||
" not Alarm() \n" + | ||
" not Sprinkler ( on == true ) \n" + | ||
"then \n" + | ||
" System.out.println(\"Everything is ok\"); \n" + | ||
"end"; | ||
|
||
@ParameterizedTest | ||
@MethodSource("strategyProviderStoresOnlyWithExplicitSafepoints") | ||
void testNoFailover(PersistedSessionOption.PersistenceStrategy persistenceStrategy, PersistedSessionOption.SafepointStrategy safepointStrategy){ | ||
createSession(FIRE_AND_ALARM, persistenceStrategy, safepointStrategy); | ||
|
||
// phase 1 | ||
Room room1 = new Room("Room 1"); | ||
insert(room1); | ||
FactHandle fireFact1 = insert(new Fire(room1)); | ||
fireAllRules(); | ||
|
||
// phase 2 | ||
Sprinkler sprinkler1 = new Sprinkler(room1); | ||
insert(sprinkler1); | ||
fireAllRules(); | ||
|
||
assertThat(sprinkler1.isOn()).isTrue(); | ||
|
||
// phase 3 | ||
delete(fireFact1); | ||
fireAllRules(); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("strategyProviderStoresOnlyWithExplicitSafepoints") | ||
void testInsertFailover_ShouldFireRules(PersistedSessionOption.PersistenceStrategy persistenceStrategy, PersistedSessionOption.SafepointStrategy safepointStrategy){ | ||
createSession(FIRE_AND_ALARM, persistenceStrategy, safepointStrategy); | ||
|
||
Room room1 = new Room("Room 1"); | ||
insert(room1); | ||
insert(new Fire(room1)); | ||
insert(new Sprinkler(room1)); | ||
|
||
failover(); | ||
restoreSession(FIRE_AND_ALARM, persistenceStrategy,safepointStrategy); | ||
|
||
assertThat(fireAllRules()).isEqualTo(2); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...eliability/drools-reliability-tests/src/test/java/org/test/domain/fireandalarm/Alarm.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.test.domain.fireandalarm; | ||
|
||
import java.io.Serializable; | ||
|
||
public class Alarm implements Serializable { | ||
} |
21 changes: 21 additions & 0 deletions
21
...reliability/drools-reliability-tests/src/test/java/org/test/domain/fireandalarm/Fire.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.test.domain.fireandalarm; | ||
|
||
import java.io.Serializable; | ||
|
||
public class Fire implements Serializable { | ||
private Room room; | ||
|
||
public Fire() { } | ||
|
||
public Fire(Room room) { | ||
this.room = room; | ||
} | ||
|
||
public Room getRoom() { | ||
return room; | ||
} | ||
|
||
public void setRoom(Room room) { | ||
this.room = room; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...reliability/drools-reliability-tests/src/test/java/org/test/domain/fireandalarm/Room.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.test.domain.fireandalarm; | ||
|
||
import java.io.Serializable; | ||
|
||
public class Room implements Serializable { | ||
private String name; | ||
|
||
public Room() { } | ||
|
||
public Room(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return name; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...bility/drools-reliability-tests/src/test/java/org/test/domain/fireandalarm/Sprinkler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.test.domain.fireandalarm; | ||
|
||
import java.io.Serializable; | ||
|
||
public class Sprinkler implements Serializable { | ||
private Room room; | ||
private boolean on = false; | ||
|
||
public Sprinkler() { } | ||
|
||
public Sprinkler(Room room) { | ||
this.room = room; | ||
} | ||
|
||
public Room getRoom() { | ||
return room; | ||
} | ||
|
||
public void setRoom(Room room) { | ||
this.room = room; | ||
} | ||
|
||
public boolean isOn() { | ||
return on; | ||
} | ||
|
||
public void setOn(boolean on) { | ||
this.on = on; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Sprinkler for " + room; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cast to
SerializableStoredObject
causesClassCastException
in ReliabilityCepTimedOutTest etc. becauseSerializableStoredEvent
is not a sub-class ofSerializableStoredObject
It's a little hard to change the inheritance structure because it's a kind of multi-inheritance. I'll review in a separate JIRA https://issues.redhat.com/browse/DROOLS-7511.At the moment, we skip the feature for Event so that tests can pass.