Package org.infinispan.test

Examples of org.infinispan.test.ValueFuture


      AtomicMap<Integer, String> atomicMap = AtomicMapLookup.getAtomicMap(cache, KEY);
      atomicMap.put(1, "existing");
      tm.begin();
      atomicMap.put(1, "newVal");

      final ValueFuture responseBeforeCommit = new ValueFuture();
      final ValueFuture responseAfterCommit = new ValueFuture();
      final CountDownLatch commitLatch = new CountDownLatch(1);

      Thread ot = fork(new Runnable() {
         @Override
         public void run() {
            try {
               tm.begin();

               try {
                  AtomicMap<Integer, String> otMap = AtomicMapLookup.getAtomicMap(cache, KEY);

                  responseBeforeCommit.set(otMap.get(1));

                  // wait until the main thread commits the transaction
                  commitLatch.await();

                  responseAfterCommit.set(otMap.get(1));
               } finally {
                  tm.rollback();
               }
            } catch (Exception e) {
               log.error("Unexpected error performing transaction", e);
            }
         }
      }, false);

      assertEquals(responseBeforeCommit.get(), "existing");

      tm.commit();
      commitLatch.countDown();

      assertEquals(atomicMap.get(1), "newVal");
      assertEquals(responseAfterCommit.get(), "newVal");
   }
View Full Code Here


      AtomicMap<Integer, String> atomicMap = AtomicMapLookup.getAtomicMap(cache, KEY);
      atomicMap.put(1, "existing");
      tm().begin();
      atomicMap.put(1, "newVal");

      final ValueFuture responseBeforeCommit = new ValueFuture();
      final ValueFuture responseAfterCommit = new ValueFuture();
      final CountDownLatch commitLatch = new CountDownLatch(1);

      Future<Object> future = fork(new Callable<Object>() {
         @Override
         public Object call() throws Exception {
            tm().begin();

            try {
               AtomicMap<Integer, String> otMap = AtomicMapLookup.getAtomicMap(cache, KEY);

               responseBeforeCommit.set(otMap.get(1));

               // wait until the main thread commits the transaction
               commitLatch.await();

               responseAfterCommit.set(otMap.get(1));
            } finally {
               tm().rollback();
            }
            return null;
         }
      });

      assertEquals(responseBeforeCommit.get(), "existing");

      tm().commit();
      commitLatch.countDown();

      future.get(10, TimeUnit.SECONDS);
      assertEquals(atomicMap.get(1), "newVal");
      assertEquals(responseAfterCommit.get(), "newVal");
   }
View Full Code Here

      AtomicMap<Integer, String> atomicMap = AtomicMapLookup.getAtomicMap(cache, KEY);
      atomicMap.put(1, "existing");
      tm().begin();
      atomicMap.put(1, "newVal");

      final ValueFuture responseBeforeCommit = new ValueFuture();
      final ValueFuture responseAfterCommit = new ValueFuture();
      final CountDownLatch commitLatch = new CountDownLatch(1);

      Future<Object> future = fork(new Callable<Object>() {
         @Override
         public Object call() throws Exception {
            tm().begin();

            try {
               AtomicMap<Integer, String> otMap = AtomicMapLookup.getAtomicMap(cache, KEY);

               responseBeforeCommit.set(otMap.get(1));

               // wait until the main thread commits the transaction
               commitLatch.await();

               responseAfterCommit.set(otMap.get(1));
            } finally {
               tm().rollback();
            }
            return null;
         }
      });

      assertEquals("existing", responseBeforeCommit.get());

      tm().commit();
      commitLatch.countDown();

      future.get(10, TimeUnit.SECONDS);
      assertEquals("newVal", atomicMap.get(1));
      assertEquals("newVal", responseAfterCommit.get());
   }
View Full Code Here

      AtomicMap<Integer, String> atomicMap = AtomicMapLookup.getAtomicMap(cache, KEY);
      atomicMap.put(1, "existing");
      tm().begin();
      atomicMap.put(1, "newVal");

      final ValueFuture responseBeforeCommit = new ValueFuture();
      final ValueFuture responseAfterCommit = new ValueFuture();
      final CountDownLatch commitLatch = new CountDownLatch(1);

      Future<Object> future = fork(new Callable<Object>() {
         @Override
         public Object call() throws Exception {
            tm().begin();

            try {
               AtomicMap<Integer, String> otMap = AtomicMapLookup.getAtomicMap(cache, KEY);

               responseBeforeCommit.set(otMap.get(1));

               // wait until the main thread commits the transaction
               commitLatch.await();

               responseAfterCommit.set(otMap.get(1));
            } finally {
               tm().rollback();
            }
            return null;
         }
      });

      assertEquals(responseBeforeCommit.get(), "existing");

      tm().commit();
      commitLatch.countDown();

      future.get(10, TimeUnit.SECONDS);
      assertEquals(atomicMap.get(1), "newVal");
      assertEquals(responseAfterCommit.get(), "newVal");
   }
View Full Code Here

TOP

Related Classes of org.infinispan.test.ValueFuture

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.