use of org.drools.compiler.StockTickInterface in project drools by kiegroup.
the class CepEspTest method testIdleTime.
// @Test(timeout=10000) @Ignore
// public void testTransactionCorrelation() throws Exception {
// // read in the source
// final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_TransactionCorrelation.drl" ) );
// final RuleBase ruleBase = loadRuleBase( reader );
//
// final WorkingMemory wm = ruleBase.newStatefulSession();
// final List results = new ArrayList();
//
// wm.setGlobal( "results",
// results );
//
//
// }
@Test(timeout = 10000)
public void testIdleTime() throws Exception {
// read in the source
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newInputStreamResource(getClass().getResourceAsStream("test_CEP_SimpleEventAssertion.drl")), ResourceType.DRL);
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
KieSessionConfiguration conf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
conf.setOption(ClockTypeOption.get("pseudo"));
StatefulKnowledgeSessionImpl session = (StatefulKnowledgeSessionImpl) createKnowledgeSession(kbase, conf);
SessionPseudoClock clock = (SessionPseudoClock) session.getSessionClock();
final List results = new ArrayList();
session.setGlobal("results", results);
StockTickInterface tick1 = new StockTick(1, "DROO", 50, 10000);
StockTickInterface tick2 = new StockTick(2, "ACME", 10, 10010);
StockTickInterface tick3 = new StockTick(3, "ACME", 10, 10100);
StockTickInterface tick4 = new StockTick(4, "DROO", 50, 11000);
assertEquals(0, session.getIdleTime());
InternalFactHandle handle1 = (InternalFactHandle) session.insert(tick1);
clock.advanceTime(10, TimeUnit.SECONDS);
assertEquals(10000, session.getIdleTime());
InternalFactHandle handle2 = (InternalFactHandle) session.insert(tick2);
assertEquals(0, session.getIdleTime());
clock.advanceTime(15, TimeUnit.SECONDS);
assertEquals(15000, session.getIdleTime());
clock.advanceTime(15, TimeUnit.SECONDS);
assertEquals(30000, session.getIdleTime());
InternalFactHandle handle3 = (InternalFactHandle) session.insert(tick3);
assertEquals(0, session.getIdleTime());
clock.advanceTime(20, TimeUnit.SECONDS);
InternalFactHandle handle4 = (InternalFactHandle) session.insert(tick4);
clock.advanceTime(10, TimeUnit.SECONDS);
assertNotNull(handle1);
assertNotNull(handle2);
assertNotNull(handle3);
assertNotNull(handle4);
assertTrue(handle1.isEvent());
assertTrue(handle2.isEvent());
assertTrue(handle3.isEvent());
assertTrue(handle4.isEvent());
assertEquals(10000, session.getIdleTime());
session.fireAllRules();
assertEquals(0, session.getIdleTime());
assertEquals(2, ((List) session.getGlobal("results")).size());
}
use of org.drools.compiler.StockTickInterface in project drools by kiegroup.
the class CepEspTest method testAnnotatedEventAssertion.
@Test(timeout = 10000)
public void testAnnotatedEventAssertion() throws Exception {
KieBase kbase = loadKnowledgeBase("test_CEP_SimpleAnnotatedEventAssertion.drl");
KieSessionConfiguration conf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
conf.setOption(ClockTypeOption.get("pseudo"));
KieSession session = createKnowledgeSession(kbase, conf);
SessionPseudoClock clock = (SessionPseudoClock) session.<SessionClock>getSessionClock();
final List results = new ArrayList();
session.setGlobal("results", results);
StockTickInterface tick1 = new StockTickEvent(1, "DROO", 50, 10000);
StockTickInterface tick2 = new StockTickEvent(2, "ACME", 10, 10010);
StockTickInterface tick3 = new StockTickEvent(3, "ACME", 10, 10100);
StockTickInterface tick4 = new StockTickEvent(4, "DROO", 50, 11000);
InternalFactHandle handle1 = (InternalFactHandle) session.insert(tick1);
clock.advanceTime(10, TimeUnit.SECONDS);
InternalFactHandle handle2 = (InternalFactHandle) session.insert(tick2);
clock.advanceTime(30, TimeUnit.SECONDS);
InternalFactHandle handle3 = (InternalFactHandle) session.insert(tick3);
clock.advanceTime(20, TimeUnit.SECONDS);
InternalFactHandle handle4 = (InternalFactHandle) session.insert(tick4);
clock.advanceTime(10, TimeUnit.SECONDS);
assertNotNull(handle1);
assertNotNull(handle2);
assertNotNull(handle3);
assertNotNull(handle4);
assertTrue(handle1.isEvent());
assertTrue(handle2.isEvent());
assertTrue(handle3.isEvent());
assertTrue(handle4.isEvent());
session.fireAllRules();
assertEquals(2, ((List) session.getGlobal("results")).size());
}
use of org.drools.compiler.StockTickInterface in project drools by kiegroup.
the class CepEspTest method testEventAssertionWithDuration.
@Test(timeout = 10000)
public void testEventAssertionWithDuration() throws Exception {
KieBase kbase = loadKnowledgeBase("test_CEP_SimpleEventAssertionWithDuration.drl");
KieSessionConfiguration conf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
conf.setOption(ClockTypeOption.get(ClockType.PSEUDO_CLOCK.getId()));
KieSession session = createKnowledgeSession(kbase, conf);
final List results = new ArrayList();
session.setGlobal("results", results);
StockTickInterface tick1 = new StockTick(1, "DROO", 50, 10000, 5);
StockTickInterface tick2 = new StockTick(2, "ACME", 10, 11000, 10);
StockTickInterface tick3 = new StockTick(3, "ACME", 10, 12000, 8);
StockTickInterface tick4 = new StockTick(4, "DROO", 50, 13000, 7);
InternalFactHandle handle1 = (InternalFactHandle) session.insert(tick1);
InternalFactHandle handle2 = (InternalFactHandle) session.insert(tick2);
InternalFactHandle handle3 = (InternalFactHandle) session.insert(tick3);
InternalFactHandle handle4 = (InternalFactHandle) session.insert(tick4);
assertNotNull(handle1);
assertNotNull(handle2);
assertNotNull(handle3);
assertNotNull(handle4);
assertTrue(handle1.isEvent());
assertTrue(handle2.isEvent());
assertTrue(handle3.isEvent());
assertTrue(handle4.isEvent());
EventFactHandle eh1 = (EventFactHandle) handle1;
EventFactHandle eh2 = (EventFactHandle) handle2;
EventFactHandle eh3 = (EventFactHandle) handle3;
EventFactHandle eh4 = (EventFactHandle) handle4;
assertEquals(tick1.getTime(), eh1.getStartTimestamp());
assertEquals(tick2.getTime(), eh2.getStartTimestamp());
assertEquals(tick3.getTime(), eh3.getStartTimestamp());
assertEquals(tick4.getTime(), eh4.getStartTimestamp());
assertEquals(tick1.getDuration(), eh1.getDuration());
assertEquals(tick2.getDuration(), eh2.getDuration());
assertEquals(tick3.getDuration(), eh3.getDuration());
assertEquals(tick4.getDuration(), eh4.getDuration());
session.fireAllRules();
assertEquals(2, results.size());
}
use of org.drools.compiler.StockTickInterface in project drools by kiegroup.
the class CepEspTest method testCoincidesOnArbitraryDates.
@Test(timeout = 10000)
public void testCoincidesOnArbitraryDates() throws Exception {
// read in the source
KieBaseConfiguration conf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
conf.setOption(EventProcessingOption.STREAM);
final KieBase kbase = loadKnowledgeBase(conf, "test_CEP_CoincidesOperatorDates.drl");
KieSessionConfiguration sconf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
sconf.setOption(ClockTypeOption.get(ClockType.PSEUDO_CLOCK.getId()));
KieSession wm = createKnowledgeSession(kbase, sconf);
final List<?> results = new ArrayList<Object>();
wm.setGlobal("results", results);
StockTickInterface tick1 = new StockTick(1, "DROO", 50, // arbitrary timestamp
100000, 3);
StockTickInterface tick2 = new StockTick(2, "ACME", 10, // 50 milliseconds after DROO
100050, 3);
InternalFactHandle handle1 = (InternalFactHandle) wm.insert(tick1);
InternalFactHandle handle2 = (InternalFactHandle) wm.insert(tick2);
assertNotNull(handle1);
assertNotNull(handle2);
assertTrue(handle1.isEvent());
assertTrue(handle2.isEvent());
// wm = SerializationHelper.serializeObject(wm);
wm.fireAllRules();
assertEquals(4, results.size());
assertEquals(tick1, results.get(0));
assertEquals(tick2, results.get(1));
assertEquals(tick1, results.get(2));
assertEquals(tick2, results.get(3));
}
use of org.drools.compiler.StockTickInterface in project drools by kiegroup.
the class CepEspTest method testEventDeclarationForInterfaces.
@Test(timeout = 10000)
public void testEventDeclarationForInterfaces() throws Exception {
// read in the source
final KieBase kbase = loadKnowledgeBase("test_CEP_EventInterfaces.drl");
KieSession session = createKnowledgeSession(kbase);
StockTickInterface tick1 = new StockTick(1, "DROO", 50, 10000);
StockTickInterface tick2 = new StockTick(2, "ACME", 10, 10010);
StockTickInterface tick3 = new StockTick(3, "ACME", 10, 10100);
StockTickInterface tick4 = new StockTick(4, "DROO", 50, 11000);
InternalFactHandle handle1 = (InternalFactHandle) session.insert(tick1);
InternalFactHandle handle2 = (InternalFactHandle) session.insert(tick2);
InternalFactHandle handle3 = (InternalFactHandle) session.insert(tick3);
InternalFactHandle handle4 = (InternalFactHandle) session.insert(tick4);
assertTrue(handle1.isEvent());
assertTrue(handle2.isEvent());
assertTrue(handle3.isEvent());
assertTrue(handle4.isEvent());
}
Aggregations