1 Reply Latest reply on Jul 3, 2015 4:52 AM by swiderski.maciej

    ProcessInstanceInfo wont save correctly on JUnit Test environment

    diaguirr

      I am working on some project that involves the use of JBPM6 as a process engine.

      We have tested it  via core API and RuntimeManager API, with JBPM 6.1 and 6.2.

      In the application environment (Web application using spring on Jboss 7) it works just fine, with process persistance, resuming, events and everything.

      The problem is in our Unit Tests. In JBPM 6.1 they work just fine, but in JBPM 6.2, when we test the correct persistence and reumption of processes, we get error due the fact that the processInstanceInfo bytes are never saved (or generetad in any way as far as we could debug).

       

      As we are going to use this on an web environment,so we are trying to emulate it with JNDI an Transaction Manager.

      The relevant part of the code is:

       

      JNDI, TM AND DATASOURCE INITIALIZATION

      InitialContext ctxt = new InitialContext();
        tm=new UserTransactionManager();
        tm.init();
        ctxt.bind(SUBCONTEXT_NAME+TM_NAME,tm);
        ds = new AtomikosNonXADataSourceBean();
        ds.setUniqueResourceName("psql");
        ds.setDriverClassName("org.postgresql.Driver");
        ds.setUrl("jdbc:postgresql://localhost:5432/test");
        ds.setUser("test");
        ds.setPassword("test");
        ds.setPoolSize(10);
        ctxt.bind(SUBCONTEXT_NAME + DS_NAME, ds);
        ut=new UserTransactionImp();
        ut.setTransactionTimeout(300);
        ctxt.bind(USER_TRANSACTION_NAME,ut);
        ctxt.bind(JtaTransactionManager.DEFAULT_USER_TRANSACTION_NAME, ut);
      
      

      (this uses SimpleJNDI and Atomikos as a Transaction Manager, we also tested it with bitronix and H2 with same results)

       

      ACTUAL TEST

       

      System.setProperty("jbpm.ut.jndi.lookup",
        JtaTransactionManager.DEFAULT_USER_TRANSACTION_NAME);
        builder = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder()
        .entityManagerFactory(this.getEntityManagerFactory());
        if (getUserGroupCallback() != null)
        builder.userGroupCallback(this.getUserGroupCallback());
        builder.persistence(true);
        builder.addEnvironmentEntry(EnvironmentName.TRANSACTION_MANAGER,
        this.getTransactionManager());
      
      RuntimeEnvironment environment = builder.get();
        manager = RuntimeManagerFactory.Factory.get()
        .newSingletonRuntimeManager(environment);
      manager.loadProcess(TEST_FILE);
      ksession=manager.
      .getRuntimeEngine(EmptyContext.get())
        .getKieSession();
      ksession.
      .startProcess(TEST_FILE_PROCESS_ID, new HashMap<String, Object>());
      
      
      
      

      (This get the transaction manager from jndi and creates the EntityManagerFactory form the persistence unit)

       

      This would result in a single register on the table processInstanceInfor with null on processInstanceInfobytearray column, hence unusable. If we begin and commit the transaction manually (for example before and after the start process call), nothing change at all.

       

      If the test code is run inside a controller , noted with the spring @Transactional notation and deployed as a regultar controller, this works just fine.

       

      We really need to set a proper test enviroment so i am really troubled with this issue.

       

      Note that all this works perfectly with jbpm 6.1

        • 1. Re: ProcessInstanceInfo wont save correctly on JUnit Test environment
          swiderski.maciej

          the change that was introduced in 6.2 was to move serialization to bytes of process instance into transaction completion (beforeCompletion) invoked via transaction synchronization registry. So please check if TransactionSynchronizationRegistry is available in your unit test environment. It should be as long as JTA 1.1 transaction manager is used. Though some spring things might get in the way.

           

          Reason why it was changed is to allow auto flush to be used for queries within active transaction to be able to query for items that are created within transaction. Prior 6.2 it was causing too early serialization to bytes and by that corrupting process instance data.

           

          HTH