@Test
  public void testLogger3() {
    long processInstanceId = startProcess("com.sample.ruleflow2").getId();

    logger.debug("Checking process instances for process 'com.sample.ruleflow2'");
    List<ProcessInstanceLog> processInstances =
        logService.findProcessInstances("com.sample.ruleflow2");
    assertEquals(1, processInstances.size());
    ProcessInstanceLog processInstance = processInstances.get(0);
    logger.debug("{}", processInstance);
    logger.debug(" -> {} - {} ", processInstance.getStart(), processInstance.getEnd());
    assertNotNull(processInstance.getStart());
    assertNotNull(processInstance.getEnd());
    assertEquals(processInstanceId, processInstance.getProcessInstanceId().longValue());
    assertEquals("com.sample.ruleflow2", processInstance.getProcessId());
    List<NodeInstanceLog> nodeInstances = logService.findNodeInstances(processInstanceId);
    for (NodeInstanceLog nodeInstance : nodeInstances) {
      logger.debug("{}", nodeInstance);
      logger.debug(" -> {}", nodeInstance.getDate());
      assertEquals(processInstanceId, processInstance.getProcessInstanceId().longValue());
      assertEquals("com.sample.ruleflow2", processInstance.getProcessId());
      assertNotNull(nodeInstance.getDate());
    }
    assertEquals(14, nodeInstances.size());
    logService.clear();
  }
  public void testLogger3() {
    // load the process
    KnowledgeBase kbase = createKnowledgeBase();
    // create a new session
    Environment env = KnowledgeBaseFactory.newEnvironment();
    env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
    env.set(
        EnvironmentName.TRANSACTION_MANAGER, TransactionManagerServices.getTransactionManager());
    Properties properties = new Properties();
    properties.put(
        "drools.processInstanceManagerFactory",
        "org.jbpm.persistence.processinstance.JPAProcessInstanceManagerFactory");
    properties.put(
        "drools.processSignalManagerFactory",
        "org.jbpm.persistence.processinstance.JPASignalManagerFactory");
    KnowledgeSessionConfiguration config =
        KnowledgeBaseFactory.newKnowledgeSessionConfiguration(properties);
    StatefulKnowledgeSession session =
        JPAKnowledgeService.newStatefulKnowledgeSession(kbase, config, env);
    new JPAWorkingMemoryDbLogger(session);
    JPAProcessInstanceDbLog log = new JPAProcessInstanceDbLog(env);
    session
        .getWorkItemManager()
        .registerWorkItemHandler("Human Task", new SystemOutWorkItemHandler());

    // record the initial count to compare to later
    List<ProcessInstanceLog> processInstances = log.findProcessInstances("com.sample.ruleflow");
    int initialProcessInstanceSize = processInstances.size();

    // start process instance
    long processInstanceId = session.startProcess("com.sample.ruleflow2").getId();

    System.out.println("Checking process instances for process 'com.sample.ruleflow2'");
    processInstances = log.findProcessInstances("com.sample.ruleflow2");
    assertEquals(initialProcessInstanceSize + 1, processInstances.size());
    ProcessInstanceLog processInstance = processInstances.get(0);
    System.out.print(processInstance);
    System.out.println(" -> " + processInstance.getStart() + " - " + processInstance.getEnd());
    assertNotNull(processInstance.getStart());
    assertNotNull(processInstance.getEnd());
    assertEquals(processInstanceId, processInstance.getProcessInstanceId());
    assertEquals("com.sample.ruleflow2", processInstance.getProcessId());
    List<NodeInstanceLog> nodeInstances = log.findNodeInstances(processInstanceId);
    for (NodeInstanceLog nodeInstance : nodeInstances) {
      System.out.print(nodeInstance);
      System.out.println(" -> " + nodeInstance.getDate());
      assertEquals(processInstanceId, processInstance.getProcessInstanceId());
      assertEquals("com.sample.ruleflow2", processInstance.getProcessId());
      assertNotNull(nodeInstance.getDate());
    }
    assertEquals(14, nodeInstances.size());
    log.clear();
    log.dispose();
  }
  @Test
  public void testLogger2() {
    // start process instance
    startProcess("com.sample.ruleflow");
    startProcess("com.sample.ruleflow");

    logger.debug("Checking process instances for process 'com.sample.ruleflow'");
    List<ProcessInstanceLog> processInstances =
        logService.findProcessInstances("com.sample.ruleflow");
    assertEquals(2, processInstances.size());
    for (ProcessInstanceLog processInstance : processInstances) {
      logger.debug("{}", processInstance);
      logger.debug(" -> {} - {}", processInstance.getStart(), processInstance.getEnd());
      List<NodeInstanceLog> nodeInstances =
          logService.findNodeInstances(processInstance.getProcessInstanceId());
      for (NodeInstanceLog nodeInstance : nodeInstances) {
        logger.debug("{}", nodeInstance);
        logger.debug(" -> {}", nodeInstance.getDate());
      }
      assertEquals(6, nodeInstances.size());
    }
    logService.clear();
  }