Skip to content

Commit

Permalink
debug log
Browse files Browse the repository at this point in the history
  • Loading branch information
tkobayas committed Sep 20, 2024
1 parent 8dac313 commit 2ceb4e6
Showing 1 changed file with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ public void after() throws Exception {

@Test(timeout = 10000)
public void testTimerRuleFires() throws Exception {
System.out.println("### testTimerRuleFires");
long start = System.currentTimeMillis();
final String drl = "// fire once, for a String, create an Integer\n" +
"rule TimerRule\n" +
"timer(int:0 1000)\n" +
Expand All @@ -110,12 +112,16 @@ public void testTimerRuleFires() throws Exception {

activateRule();
advanceTimerOneSecond();


System.out.println(" -- before await : elapsed " + (System.currentTimeMillis() - start) + "ms");
await().until(ruleHasFired("TimerRule", 1));
System.out.println(" -- end : elapsed " + (System.currentTimeMillis() - start) + "ms");
}

@Test(timeout = 10000)
public void testTimerRuleHaltStopsFiring() throws Exception {
System.out.println("### testTimerRuleHaltStopsFiring");
long start = System.currentTimeMillis();
final String drl = "// fire once, for a String, create an Integer\n" +
"rule TimerRule\n" +
"timer(int:0 1000)\n" +
Expand All @@ -128,16 +134,22 @@ public void testTimerRuleHaltStopsFiring() throws Exception {
startEngine();
activateRule();
advanceTimerOneSecond();
System.out.println(" -- before await : elapsed " + (System.currentTimeMillis() - start) + "ms");
await().until(ruleHasFired("TimerRule", 1));

stopEngine();

advanceTimerOneSecond();

System.out.println(" -- before 2nd await : elapsed " + (System.currentTimeMillis() - start) + "ms");
await().during(Duration.ofSeconds(1)).atMost(Duration.ofSeconds(2)).until(ruleHasFired("TimerRule", 1));
System.out.println(" -- end : elapsed " + (System.currentTimeMillis() - start) + "ms");
}

@Test(timeout = 10000)
public void testTimerRuleRestartsAfterStop() throws Exception {
System.out.println("### testTimerRuleRestartsAfterStop");
long start = System.currentTimeMillis();
final String drl = "// fire once, for a String, create an Integer\n" +
"rule TimerRule\n" +
"timer(int:0 1000)\n" +
Expand All @@ -150,17 +162,23 @@ public void testTimerRuleRestartsAfterStop() throws Exception {
startEngine();
activateRule();
advanceTimerOneSecond();
System.out.println(" -- before await : elapsed " + (System.currentTimeMillis() - start) + "ms");
await().until(ruleHasFired("TimerRule", 1));

stopEngine();
startEngine();

advanceTimerOneSecond();

System.out.println(" -- before 2nd await : elapsed " + (System.currentTimeMillis() - start) + "ms");
await().during(Duration.ofSeconds(1)).atMost(Duration.ofSeconds(2)).until(ruleHasFired("TimerRule", 2));
System.out.println(" -- end : elapsed " + (System.currentTimeMillis() - start) + "ms");
}

@Test(timeout = 10000)
public void testTimerRuleDoesRestartsIfNoLongerHolds() throws Exception {
System.out.println("### testTimerRuleDoesRestartsIfNoLongerHolds");
long start = System.currentTimeMillis();
final String drl = "// fire once, for a String, create an Integer\n" +
"rule TimerRule\n" +
"timer(int:0 1000)\n" +
Expand All @@ -173,7 +191,8 @@ public void testTimerRuleDoesRestartsIfNoLongerHolds() throws Exception {
startEngine();
activateRule();
advanceTimerOneSecond();


System.out.println(" -- before await : elapsed " + (System.currentTimeMillis() - start) + "ms");
await().until(ruleHasFired("TimerRule", 1));

stopEngine();
Expand All @@ -182,17 +201,22 @@ public void testTimerRuleDoesRestartsIfNoLongerHolds() throws Exception {

advanceTimerOneSecond();

System.out.println(" -- before 2nd await : elapsed " + (System.currentTimeMillis() - start) + "ms");
await().during(Duration.ofSeconds(1)).atMost(Duration.ofSeconds(2)).until(ruleHasFired("TimerRule", 1));
System.out.println(" -- end : elapsed " + (System.currentTimeMillis() - start) + "ms");
}


private void setupKSessionFor(final String drl) {
System.out.println(" ** exec-model : " + kieBaseTestConfiguration.isExecutableModel());
long start = System.currentTimeMillis();
kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("timer-and-calendar-test", kieBaseTestConfiguration, drl);
KieSessionConfiguration kieSessionConfiguration = KieSessionTestConfiguration.STATEFUL_PSEUDO.getKieSessionConfiguration();
ksession = kbase.newKieSession(kieSessionConfiguration, null);
listener = new RecordingRulesListener();
ksession.addEventListener(listener);
timeService = ksession.getSessionClock();
System.out.println(" setupKSessionFor : " + (System.currentTimeMillis() - start) + "ms");
}

private void startEngine() throws InterruptedException {
Expand Down

0 comments on commit 2ceb4e6

Please sign in to comment.