Examples of TransactionManager


Examples of javax.transaction.TransactionManager

      Node n = cache1.getNode(fqn);
      CacheLoaderInvalidationTest.assertHasBeenInvalidated(n, "Should have been invalidated");
      CacheLoaderInvalidationTest.assertHasBeenInvalidated(cache1.peek(fqn, true, true), "Should have been invalidated");

      // start a tx that cache1 will have to send out an evict ...
      TransactionManager mgr1 = cache1.getTransactionManager();
      TransactionManager mgr2 = cache2.getTransactionManager();

      mgr1.begin();
      cache1.put(fqn, "key2", "value2");
      Transaction tx1 = mgr1.suspend();
      mgr2.begin();
      cache2.put(fqn, "key3", "value3");
      Transaction tx2 = mgr2.suspend();
      mgr1.resume(tx1);
      // this oughtta fail
      try
      {
         mgr1.commit();
         assertTrue("Ought to have succeeded!", true);
      }
      catch (RollbackException roll)
      {
         assertTrue("Ought to have succeeded!", false);
      }

      mgr2.resume(tx2);
      try
      {
         mgr2.commit();
         assertTrue("Ought to have failed!", false);
      }
      catch (RollbackException roll)
      {
         assertTrue("Ought to have failed!", true);
View Full Code Here

Examples of javax.transaction.TransactionManager

   }


   public void testTxPutCommit() throws Exception
   {
      TransactionManager mgr = cache1.getConfiguration().getRuntimeConfig().getTransactionManager();
      mgr.begin();


      cache1.put(fqn, "key1", "val1");
      cache1.put("/one/two/three/four", "key2", "val2");
      assertNull(cache2.get(fqn, "key1"));
      assertNull(cache2.get("/one/two/three/four", "key2"));
      mgr.commit();
      assertNotNull(cache1.getNode(fqn).getKeys());
      Set<?> children = cache1.getNode("/one").getChildrenNames();
      assertEquals(1, children.size());
      TestingUtil.sleepThread(2000);
      assertEquals("val1", cache2.get(fqn, "key1"));
View Full Code Here

Examples of javax.transaction.TransactionManager

      n2 = cache2.getNode(fqn);
      CacheLoaderInvalidationTest.assertHasBeenInvalidated(n2, "Should have been invalidated");
      CacheLoaderInvalidationTest.assertHasBeenInvalidated(cache2.peek(fqn, false, false), "Should have been invalidated");

      // with tx's
      TransactionManager txm = cache2.getTransactionManager();

      txm.begin();
      cache2.put(fqn, "key", "value");
      assertEquals("value", cache2.get(fqn, "key"));
      assertEquals("value2", cache1.get(fqn, "key2"));
      txm.commit();

      n1 = cache1.getNode(fqn);
      CacheLoaderInvalidationTest.assertHasBeenInvalidated(n1, "Should have been invalidated");
      CacheLoaderInvalidationTest.assertHasBeenInvalidated(cache1.peek(fqn, false, false), "Should have been invalidated");
      assertEquals("value", cache2.get(fqn, "key"));

      // now test the invalidation again
      txm = cache1.getTransactionManager();

      txm.begin();
      cache1.put(fqn, "key2", "value2");
      assertEquals("value", cache2.get(fqn, "key"));
      assertEquals("value2", cache1.get(fqn, "key2"));
      txm.commit();

      assertEquals("value2", cache1.get(fqn, "key2"));
      n2 = cache2.getNode(fqn);
      CacheLoaderInvalidationTest.assertHasBeenInvalidated(n2, "Should have been invalidated");
      CacheLoaderInvalidationTest.assertHasBeenInvalidated(cache2.peek(fqn, false, false), "Should have been invalidated");

      // test a rollback
      txm = cache2.getTransactionManager();

      txm.begin();
      cache2.put(fqn, "key", "value");
      assertEquals("value2", cache1.get(fqn, "key2"));
      assertEquals("value", cache2.get(fqn, "key"));
      txm.rollback();

      assertEquals("value2", cache1.get(fqn, "key2"));
      n2 = cache2.getNode(fqn);
      CacheLoaderInvalidationTest.assertHasBeenInvalidated(n2, "Should have been invalidated");
      CacheLoaderInvalidationTest.assertHasBeenInvalidated(cache2.peek(fqn, false, false), "Should have been invalidated");
View Full Code Here

Examples of javax.transaction.TransactionManager

   }


   public void testTxPrepareAndRollback() throws Exception
   {
      final TransactionManager mgr = cache1.getConfiguration().getRuntimeConfig().getTransactionManager();
      mgr.begin();

      cache1.getConfiguration().setLockAcquisitionTimeout(1500);
      cache2.getConfiguration().setLockAcquisitionTimeout(1500);


      Thread locker = new Thread()
      {
         Transaction tx2 = null;

         public void run()
         {
            try
            {
               mgr.begin();
               tx2 = mgr.getTransaction();
               cache2.put(fqn, "block-key1", "block-val1");// acquires a lock on cache2./one/two/three
               TestingUtil.sleepThread(5000);
            }
            catch (Exception e)
            {
               e.printStackTrace();
            }
            finally
            {
               if (tx2 != null)
               {
                  try
                  {
                     mgr.rollback();
                  }
                  catch (SystemException e)
                  {
                     e.printStackTrace();
                  }
               }
            }
         }
      };

      locker.start();
      TestingUtil.sleepThread(1000);

      cache1.put(fqn, "key1", "val1");
      cache1.put("/one/two/three/four", "key2", "val2");

      try
      {
         mgr.commit();// prepare() on cache2 will fail due to lock held by locker thread
         fail("commit() should fail because we cannot acquire the lock on cache2");
      }
      catch (RollbackException rollback)
      {
         assertTrue(true);
View Full Code Here

Examples of javax.transaction.TransactionManager

   }

   public void dataInconsistency() throws Exception
   {
      Fqn node = Fqn.fromString("/a");
      TransactionManager tm1 = cache1.getConfiguration().getRuntimeConfig().getTransactionManager();
      TransactionManager tm2 = cache2.getConfiguration().getRuntimeConfig().getTransactionManager();
      tm1.begin();
      cache1.put(node, "k", "v-older");
      Transaction t1 = tm1.suspend();

      tm2.begin();
      cache2.put(node, "k", "v-newer");
      tm2.commit();

      tm1.resume(t1);
      try
      {
         tm1.commit();
View Full Code Here

Examples of javax.transaction.TransactionManager

   }


   public void testPutAfterTxCommit() throws Exception
   {
      TransactionManager mgr = cache1.getConfiguration().getRuntimeConfig().getTransactionManager();
      mgr.begin();

      cache1.put(fqn, "key1", "val1");
      assertTrue(cache1.exists(fqn));
      mgr.commit();
      assertTrue(cache1.exists(fqn));
      cache1.put("/a/b/c", null);// should be run outside a TX !
      assertTrue(cache1.exists("/a/b/c"));
   }
View Full Code Here

Examples of javax.transaction.TransactionManager

      assertTrue(cache1.exists("/a/b/c"));
   }

   public void testPutAfterTxRollback() throws Exception
   {
      TransactionManager mgr = cache1.getConfiguration().getRuntimeConfig().getTransactionManager();
      mgr.begin();

      cache1.put(fqn, "key1", "val1");
      assertTrue(cache1.exists(fqn));
      mgr.rollback();
      assertFalse(cache1.getCacheLoaderManager().getCacheLoader().exists(fqn));
      assertFalse(cache1.exists(fqn));
      cache1.put("/a/b/c", null);// should be run outside a TX !
      assertTrue(cache1.exists("/a/b/c"));
   }
View Full Code Here

Examples of javax.transaction.TransactionManager

   }

   public void testPessimisticTransactionalWithCacheLoader() throws Exception
   {
      Fqn fqn = Fqn.fromString("/a/b");
      TransactionManager mgr = cache1.getTransactionManager();
      assertNull("Should be null", cache1.get(fqn, "key"));
      assertNull("Should be null", cache2.get(fqn, "key"));
      mgr.begin();
      cache1.put(fqn, "key", "value");
      assertEquals("value", cache1.get(fqn, "key"));
      mgr.commit();
      assertEquals("value", cache2.get(fqn, "key"));
      assertEquals("value", cache1.get(fqn, "key"));

      mgr.begin();
      cache1.put(fqn, "key2", "value2");
      assertEquals("value2", cache1.get(fqn, "key2"));
      mgr.rollback();
      assertEquals("value", cache2.get(fqn, "key"));
      assertEquals("value", cache1.get(fqn, "key"));
      assertNull("Should be null", cache1.get(fqn, "key2"));
      assertNull("Should be null", cache2.get(fqn, "key2"));
   }
View Full Code Here

Examples of javax.transaction.TransactionManager

         Region r2 = cache2.getRegion(aop, false) == null ? cache2.getRegion(aop, true) : cache2.getRegion(aop, false);
         r2.registerContextClassLoader(clb);
      }

      if (useMarshalledValues) Thread.currentThread().setContextClassLoader(cla);
      TransactionManager tm = beginTransaction();
      cache1.put(Fqn.fromString("/aop/1"), "person", srtl.ben_);
      cache1.remove(Fqn.fromString("/aop/1"), "person");
      HashMap<Object, Object> map = new HashMap<Object, Object>();
      map.put("1", "1");
      map.put("2", "2");
      cache1.put(Fqn.fromString("/aop/2"), map);
      cache1.removeNode(Fqn.fromString("/aop/2"));
      tm.commit();

//      TestingUtil.sleepThread(1000);
      if (useMarshalledValues) resetContextClassLoader();
   }
View Full Code Here

Examples of javax.transaction.TransactionManager

      {
         Region r2 = cache2.getRegion(aop, false) == null ? cache2.getRegion(aop, true) : cache2.getRegion(aop, false);
         r2.registerContextClassLoader(clb);
      }

      TransactionManager tm = beginTransaction();
      if (useMarshalledValues) Thread.currentThread().setContextClassLoader(cla);
      cache1.put(aop, "person", srtl.ben_);
      tm.commit();
      if (useMarshalledValues) resetContextClassLoader();

      Object ben2;
      // Can't cast it to Person. CCE will resutl.
      if (useMarshalledValues) Thread.currentThread().setContextClassLoader(clb);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.