@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 testLogger1() throws Exception {

    // 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.ruleflow").getId();

    System.out.println("Checking process instances for process 'com.sample.ruleflow'");
    processInstances = log.findProcessInstances("com.sample.ruleflow");
    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.ruleflow", processInstance.getProcessId());
    List<NodeInstanceLog> nodeInstances = log.findNodeInstances(processInstanceId);
    assertEquals(6, nodeInstances.size());
    for (NodeInstanceLog nodeInstance : nodeInstances) {
      System.out.println(nodeInstance);
      assertEquals(processInstanceId, processInstance.getProcessInstanceId());
      assertEquals("com.sample.ruleflow", processInstance.getProcessId());
      assertNotNull(nodeInstance.getDate());
    }
    log.clear();
    processInstances = log.findProcessInstances("com.sample.ruleflow");
    assertEquals(0, processInstances.size());
    log.dispose();
  }
  public void testLogger4LargeVariable() throws Exception {
    // 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 WorkItemHandler() {
              public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
                Map<String, Object> results = new HashMap<String, Object>();
                results.put("Result", "ResultValue");
                manager.completeWorkItem(workItem.getId(), results);
              }

              public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {}
            });

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

    // start process instance
    Map<String, Object> params = new HashMap<String, Object>();
    List<String> list = new ArrayList<String>();
    list.add("One");
    list.add("Two");
    String three = "";
    for (int i = 0; i < 1024; i++) {
      three += "*";
    }
    list.add(three);
    params.put("list", list);
    long processInstanceId = session.startProcess("com.sample.ruleflow3", params).getId();

    System.out.println("Checking process instances for process 'com.sample.ruleflow3'");
    processInstances = log.findProcessInstances("com.sample.ruleflow3");
    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.ruleflow3", processInstance.getProcessId());
    List<VariableInstanceLog> variableInstances = log.findVariableInstances(processInstanceId);
    assertEquals(6, variableInstances.size());
    for (VariableInstanceLog variableInstance : variableInstances) {
      System.out.println(variableInstance);
      assertEquals(processInstanceId, processInstance.getProcessInstanceId());
      assertEquals("com.sample.ruleflow3", processInstance.getProcessId());
      assertNotNull(variableInstance.getDate());
    }
    log.clear();
    processInstances = log.findProcessInstances("com.sample.ruleflow3");
    assertEquals(0, processInstances.size());
    log.dispose();
  }