Package javax.transaction

Examples of javax.transaction.TransactionManager


      */
   }

   private TransactionManager beginTransaction() throws SystemException, NotSupportedException
   {
      TransactionManager mgr = cache1.getConfiguration().getRuntimeConfig().getTransactionManager();
      mgr.begin();
      return mgr;
   }
View Full Code Here


      }
   }

   public void testNonSerializableReplWithTx() throws Exception
   {
      TransactionManager tm;

      try
      {
         initCaches(Configuration.CacheMode.REPL_SYNC);

         tm = beginTransaction();
         cache1.put("/a/b/c", "test", new ContainerData());
         tm.commit();

         // We should not come here.
         assertNotNull("NonSerializableData should not be null on cache2", cache2.get("/a/b/c", "test"));
      }
      catch (RollbackException rollback)
View Full Code Here

//      wrapper.setManageCacheLifecycle(true);
      wrapper.create();
      wrapper.start();

      TransactionManager tm = config.getRuntimeConfig().getTransactionManager();

      tm.begin();
      try
      {
         Fqn fqn = Fqn.fromString("/testing/jmx");
         cache.put(fqn, "foobar", "barfoo");

         String locks = html ? wrapper.printLockInfoAsHtml() : wrapper.printLockInfo();

         assertTrue("Details include testing", locks.contains("testing"));
         assertTrue("Details include jmx", locks.contains("jmx"));

         return locks;
      }
      catch (Exception e)
      {
         tm.setRollbackOnly();
         throw e;
      }
      finally
      {
         tm.commit();
      }

   }
View Full Code Here

      m = null;
   }

   public void testSuppressionOfWriteLocks() throws Exception
   {
      TransactionManager m = cache.getTransactionManager();

      m.begin();
      assertFalse(cache.getInvocationContext().getOptionOverrides().isSuppressLocking());
      cache.put(fqn, "x", "1");
      assertFalse(cache.getInvocationContext().getOptionOverrides().isSuppressLocking());
      assertEquals(2, cache.getNumberOfLocksHeld());
      m.commit();
      assertEquals(0, cache.getNumberOfLocksHeld());

      cache.removeNode(fqn);

      m.begin();
      cache.getInvocationContext().getOptionOverrides().setSuppressLocking(true);
      assertTrue(cache.getInvocationContext().getOptionOverrides().isSuppressLocking());
      cache.put(fqn, "x", "2");
      assertFalse(cache.getInvocationContext().getOptionOverrides().isSuppressLocking());
      assertEquals(0, cache.getNumberOfLocksHeld());
      m.commit();
      assertEquals(0, cache.getNumberOfLocksHeld());

      // test normal operation again
      cache.removeNode(fqn);

      m.begin();
      assertFalse(cache.getInvocationContext().getOptionOverrides().isSuppressLocking());
      cache.put(fqn, "x", "3");
      assertFalse(cache.getInvocationContext().getOptionOverrides().isSuppressLocking());
      assertEquals(2, cache.getNumberOfLocksHeld());
      m.commit();
      assertEquals(0, cache.getNumberOfLocksHeld());
   }
View Full Code Here

    *
    * @throws Exception
    */
   public void testSuppressionOf2WriteLocks() throws Exception
   {
      TransactionManager m = cache.getTransactionManager();

      m.begin();
      cache.put(fqn, "x", "1");
      assertEquals(2, cache.getNumberOfLocksHeld());
      m.commit();
      assertEquals(0, cache.getNumberOfLocksHeld());

      cache.removeNode(fqn);

      m.begin();
      cache.getInvocationContext().getOptionOverrides().setSuppressLocking(true);
      cache.put(fqn, "x", "2");
      cache.getInvocationContext().getOptionOverrides().setSuppressLocking(true);
      cache.put(fqn1, "y", "3");
      assertEquals(0, cache.getNumberOfLocksHeld());
      m.commit();
      assertEquals(0, cache.getNumberOfLocksHeld());

      Map<String, String> map = new HashMap<String, String>();
      map.put("x", "1");
      m.begin();
      cache.getInvocationContext().getOptionOverrides().setSuppressLocking(true);
      cache.put(fqn, map);
      cache.getInvocationContext().getOptionOverrides().setSuppressLocking(true);
      cache.put(fqn1, map);
      assertEquals(0, cache.getNumberOfLocksHeld());
      m.commit();
      assertEquals(0, cache.getNumberOfLocksHeld());

      // test normal operation again
      cache.removeNode(fqn);

      m.begin();
      cache.put(fqn, "x", "3");
      assertEquals(2, cache.getNumberOfLocksHeld());
      m.commit();
      assertEquals(0, cache.getNumberOfLocksHeld());
   }
View Full Code Here

      cache2.start();

      TestingUtil.blockUntilViewsReceived(10000, cache1, cache2);

      // get a lock on cache 2 and hold on to it.
      TransactionManager tm = cache2.getConfiguration().getRuntimeConfig().getTransactionManager();
      tm.begin();
      cache2.put(fqn, "block", "block");
      Transaction t = tm.suspend();

      cache1.put(fqn, "k", "v");
   }
View Full Code Here

   }

   public void testIgnoreModsTransactional() throws Exception
   {
      startCache(false, true);
      TransactionManager mgr = cache.getTransactionManager();

      // initialise the loaders
      loader1.put(fqn, key, value);
      loader2.put(fqn, key, value);

      // check contents
      assertEquals(value, cache.get(fqn, key));
      assertEquals(value, chainingCacheLoader.get(fqn).get(key));
      assertEquals(value, loader1.get(fqn).get(key));
      assertEquals(value, loader2.get(fqn).get(key));

      // do a put
      mgr.begin();
      cache.put(fqn, key, value + 2);
      assertEquals(value + 2, cache.get(fqn, key));
      assertEquals(value, chainingCacheLoader.get(fqn).get(key));
      assertEquals(value, loader1.get(fqn).get(key));
      assertEquals(value, loader2.get(fqn).get(key));
      mgr.commit();
      assertEquals(value + 2, cache.get(fqn, key));
      assertEquals(value + 2, chainingCacheLoader.get(fqn).get(key));
      assertEquals(value + 2, loader1.get(fqn).get(key));
      assertEquals(value, loader2.get(fqn).get(key));
View Full Code Here

   }

   public void testCrudsTransactional() throws Exception
   {
      startCache(false, false);
      TransactionManager mgr = cache.getTransactionManager();

      // assert that the loaders ae empty
      chainingCacheLoader.remove(cache.getRoot().getFqn());
      assertNull(loader1.get(fqn));
      assertNull(loader2.get(fqn));
      assertNull(chainingCacheLoader.get(fqn));

      // put something in the cache.
      mgr.begin();
      cache.put(fqn, key, value);
      assertEquals(value, cache.get(fqn, key));
      assertNull(chainingCacheLoader.get(fqn));
      assertNull(loader1.get(fqn));
      assertNull(loader2.get(fqn));
      mgr.commit();
      assertEquals(value, cache.get(fqn, key));
      assertEquals(value, chainingCacheLoader.get(fqn).get(key));
      assertEquals(value, loader1.get(fqn).get(key));
      assertEquals(value, loader2.get(fqn).get(key));
View Full Code Here

   }

   public void testSyncTxRepl() throws Exception
   {
      Integer age;
      TransactionManager tm = cache1.getTransactionManager();

      tm.begin();
      Transaction tx = tm.getTransaction();
      Listener lis = new Listener();
      cache1.getNotifier().addCacheListener(lis);
      lis.put("/a/b/c", "age", 38);

      tm.suspend();
      assertNull("age on cache2 must be null as the TX has not yet been committed", cache2.get("/a/b/c", "age"));
      tm.resume(tx);
      tm.commit();

      // value on cache2 must be 38
      age = (Integer) cache2.get("/a/b/c", "age");
      assertNotNull("\"age\" obtained from cache2 must be non-null ", age);
      assertTrue("\"age\" must be 38", age == 38);
View Full Code Here

   }

   public void testSyncTxReplMap() throws Exception
   {
      Integer age;
      TransactionManager tm = cache1.getConfiguration().getRuntimeConfig().getTransactionManager();
      tm.begin();
      Transaction tx = tm.getTransaction();
      Listener lis = new Listener();
      cache1.getNotifier().addCacheListener(lis);
      Map<String, Comparable> map = new HashMap<String, Comparable>();
      map.put("age", 38);
      map.put("name", "Ben");
      lis.put("/a/b/c", map);
      tm.suspend();
      assertNull("age on cache2 must be null as the TX has not yet been committed", cache2.get("/a/b/c", "age"));
      tm.resume(tx);
      tm.commit();

      // value on cache2 must be 38
      age = (Integer) cache2.get("/a/b/c", "age");
      assertNotNull("\"age\" obtained from cache2 must be non-null ", age);
      assertTrue("\"age\" must be 38", age == 38);
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.