Package javax.transaction

Examples of javax.transaction.TransactionManager


      assertEquals("value", cache1.get(fqn, "key"));
      assertNull("Should NOT have replicated!", cache2.getNode(fqn));

      // now make sure cache2 is in sync with cache1:
      // make sure this is in a tx
      TransactionManager txm = cache2.getTransactionManager();
      assertEquals("value", cache1.get(fqn, "key"));

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

      // since the node already exists even PL will not remove it - but will invalidate it's data
      Node n = cache1.getNode(fqn);
      CacheLoaderInvalidationTest.assertHasBeenInvalidated(n, "Should have been invalidated");
      assertEquals("value", cache2.get(fqn, "key"));

      // now test the invalidation again
      txm = cache1.getTransactionManager();
      assertEquals("value", cache2.get(fqn, "key"));

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

      assertEquals("value2", cache1.get(fqn, "key2"));
      // since the node already exists even PL will not remove it - but will invalidate it's data
      n = cache2.getNode(fqn);
      CacheLoaderInvalidationTest.assertHasBeenInvalidated(n, "Should have been invalidated");

      // test a rollback
      txm = cache2.getTransactionManager();
      assertEquals("value2", cache1.get(fqn, "key2"));

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

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


      cache1.put("/a/b", "key", "value");
      assertEquals("value", cache1.get(fqn, "key"));
      assertNull(cache2.getNode(fqn));

      // start a tx that cacahe1 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 failed!", false);
      }
      catch (RollbackException roll)
      {
         assertTrue("Ought to have failed!", true);
      }

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

      assertNull("Should be null", cache1.getNode(fqn));
      assertNull("Should be null", cache2.getNode(fqn));

      // OK, here's the real test
      TransactionManager tm = cache2.getTransactionManager();
      tm.begin();
      try
      {
         // Remove a node that doesn't exist in cache2
         cache2.removeNode(fqn);
         tm.commit();
      }
      catch (Exception e)
      {
         String msg = "Unable to remove non-existent node " + fqn;
         fail(msg + " -- " + e);
View Full Code Here

      assertEquals("value", cache1.getNode(fqn).get("key"));
      assertNull("Should be null", cache2.getNode(fqn));

      // OK, here's the real test
      TransactionManager tm = cache2.getTransactionManager();
      tm.begin();
      try
      {
         // Remove a node that doesn't exist in cache2
         cache2.removeNode(fqn);
         tm.commit();
      }
      catch (Exception e)
      {
         String msg = "Unable to remove non-existent node " + fqn;
         fail(msg + " -- " + e);
View Full Code Here

      List<CacheSPI<Object, Object>> caches = createCachesWithSharedCL(true);
      cache1 = caches.get(0);
      cache2 = caches.get(1);

      Fqn fqn = Fqn.fromString("/a/b");
      TransactionManager mgr = caches.get(0).getTransactionManager();
      assertNull("Should be null", caches.get(0).get(fqn, "key"));
      assertNull("Should be null", caches.get(1).get(fqn, "key"));
      mgr.begin();
      caches.get(0).put(fqn, "key", "value");
      assertEquals("value", caches.get(0).get(fqn, "key"));
      assertNull("Should be null", caches.get(1).get(fqn, "key"));
      mgr.commit();
      assertEquals("value", caches.get(1).get(fqn, "key"));
      assertEquals("value", caches.get(0).get(fqn, "key"));

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

      cache1.put("/a/b", "key", "value");
      assertEquals("value", cache1.get(fqn, "key"));
      assertNull(cache2.getNode(fqn));

      // start a tx that cacahe1 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 succeeded!", true);
      }
      catch (RollbackException roll)
      {
         assertTrue("Ought to have succeeded!", false);
View Full Code Here

      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

   }


   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

      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

   }


   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

TOP

Related Classes of javax.transaction.TransactionManager

Copyright © 2018 www.massapicom. 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.