1 Reply Latest reply on Nov 15, 2005 7:17 AM by rino_salvade

    remove & put in the same transaction

    rino_salvade

      We're currently using JBossCache 1.2.3. When running the following test code we experienced that the last test case marked with THIS FAILS causes a problem.

      public void testSimpleRollbackTransactions() throws Exception {
       TreeCache firstCache = new TreeCache();
       firstCache.setTransactionManagerLookup(new DummyTransactionManagerLookup());
       firstCache.start();
       UserTransaction tx = new DummyUserTransaction(DummyTransactionManager.getInstance());
       tx.begin();
      
       firstCache.put("/testNode/node1/first", "entry", "commit");
      
       tx.commit();
      
       tx = new DummyUserTransaction(DummyTransactionManager.getInstance());
       tx.begin();
      
       firstCache.put("/testNode/node1/first", "entry", "rollback");
       firstCache.remove("/testNode/node1/first");
      
       tx.rollback();
      
       assertEquals("Node should keep the commited value", "commit", firstCache.get("/testNode/node1/first").get("entry"));
      
       tx = new DummyUserTransaction(DummyTransactionManager.getInstance());
       tx.begin();
      
       firstCache.remove("/testNode/node1/first");
       firstCache.put("/testNode/node1/first", "entry", "rollback");
      
       tx.rollback();
      
       assertEquals("Node should keep the commited value", "commit", firstCache.get("/testNode/node1/first").get("entry")); // THIS FAILS
       }
      


      After having a look at the source code the problem seems to be that the put creates the node from new and it gets therefore added to the node list of the transaction entry. In the rollback case the LockInterceptor removes all these temporay nodes and it therefore vanishes from the cache which is not what we expected. The question is now is there any workaround for this or does the 1.2.4 relase fix this problem (I haven't found it in the release notes so I assumed it does not fix it).