@Test
  public void testKSessionModified() {
    KProject kproj = new KProjectImpl();

    KProjectChangeLog dirtyLog = new KProjectChangeLog();
    kproj.setListener(dirtyLog);

    assertFalse(dirtyLog.isKProjectDirty());

    KBase kbase1 = kproj.newKBase("org.test1", "KBase1");

    KSession kSession = kbase1.newKSession("org.test1", "KSession1");
    kSession.setClockType(ClockTypeOption.get("pseudo"));
    kSession.setType("stateless");

    kSession.setClockType(ClockTypeOption.get("realtime"));
    assertTrue(dirtyLog.getAddedKSessions().contains("org.test1.KSession1"));

    dirtyLog.reset();

    kSession.setType("stateful");
    assertTrue(dirtyLog.getAddedKSessions().contains("org.test1.KSession1"));

    kbase1.removeKSession(kSession.getQName());
    assertFalse(dirtyLog.getAddedKSessions().contains("org.test1.KSession1"));
    assertTrue(dirtyLog.getRemovedKSessions().contains("org.test1.KSession1"));
  }
 private StatefulKnowledgeSession createSession(KnowledgeBase kbase) {
   final KnowledgeSessionConfiguration conf =
       KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
   conf.setOption(ClockTypeOption.get(ClockType.PSEUDO_CLOCK.getId()));
   StatefulKnowledgeSession ksession =
       JPAKnowledgeService.newStatefulKnowledgeSession(kbase, conf, createEnvironment());
   return ksession;
 }
  private StatefulKnowledgeSession disposeAndReloadSession(
      StatefulKnowledgeSession ksession, KnowledgeBase kbase) {
    int ksessionId = ksession.getId();
    ksession.dispose();

    final KnowledgeSessionConfiguration conf =
        KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
    conf.setOption(ClockTypeOption.get(ClockType.PSEUDO_CLOCK.getId()));

    StatefulKnowledgeSession newksession =
        JPAKnowledgeService.loadStatefulKnowledgeSession(
            ksessionId, kbase, conf, createEnvironment());
    return newksession;
  }
Ejemplo n.º 4
0
  @Before
  public void setUp() {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(
        new ClassPathResource("imports-and-declarations.drl", getClass()), ResourceType.DRL);
    kbuilder.add(new ClassPathResource("discussion.drl", getClass()), ResourceType.DRL);
    Assert.assertFalse(kbuilder.getErrors().toString(), kbuilder.hasErrors());

    KnowledgeBaseConfiguration config = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
    config.setOption(EventProcessingOption.STREAM);

    kbase = KnowledgeBaseFactory.newKnowledgeBase(config);
    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());

    KnowledgeSessionConfiguration conf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
    conf.setOption(ClockTypeOption.get("pseudo"));
    ksession = kbase.newStatefulKnowledgeSession(conf, null);

    firedRules = new FiredRulesListener();
    ksession.addEventListener(firedRules);

    notificationsGeneral = new NotificationsGeneralChannelMock();
    ksession.registerChannel("notificationsGeneral", notificationsGeneral);
  }