Package org.jboss.cache

Examples of org.jboss.cache.TreeCache


      return tx;
   }

   void initCaches(int caching_mode) throws Exception {
      this.caching_mode=caching_mode;
      cache1=new TreeCache();
      cache2=new TreeCache();
      cache1.setCacheMode(caching_mode);
      cache2.setCacheMode(caching_mode);
      cache1.setIsolationLevel(IsolationLevel.SERIALIZABLE);
      cache2.setIsolationLevel(IsolationLevel.SERIALIZABLE);
View Full Code Here


    * Should reproduce JBCACHE-32 problem (http://jira.jboss.com/jira/browse/JBCACHE-32)
    */
   private void _testConcurrentCommits(int num_threads) throws Exception {
      Object myMutex=new Object();

      final TreeCache c1=new TreeCache();
      final TreeCache c2=new TreeCache();
      c1.setClusterName("TempCluster");
      c2.setClusterName("TempCluster");
      c1.setCacheMode(TreeCache.REPL_SYNC);
      c2.setCacheMode(TreeCache.REPL_SYNC);
      c1.setSyncCommitPhase(true);
      c2.setSyncCommitPhase(true);
      c1.setSyncRollbackPhase(true);
      c2.setSyncRollbackPhase(true);
      c1.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
      c2.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
      c1.setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
      c2.setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
      c1.setLockAcquisitionTimeout(5000);
      c2.setLockAcquisitionTimeout(5000);
      c1.start();
      c2.start();
      final List exceptions = new ArrayList();

      class MyThread extends Thread {
         Object mutex;

         public MyThread(String name, Object mutex) {
            super(name);
            this.mutex=mutex;
         }

         public void run() {
            Transaction tx = null;

            try {
               tx=beginTransaction();
               c1.put("/thread/" + getName(), null);
               System.out.println("Thread " + getName() + " after put(): " + c1.toString());
               System.out.println("Thread " + getName() + " waiting on mutex");
               synchronized(mutex) {
                  mutex.wait();
               }
               System.out.println("Thread " + getName() + " committing");
               tx.commit();
               System.out.println("Thread " + getName() + " committed successfully");
            }
            catch(Exception e) {
               exceptions.add(e);
            }
            finally {
               try
               {
                  if (tx != null) tx.rollback();
               }
               catch (Exception e)
               {

               }
            }
         }
      }

      MyThread[] threads=new MyThread[num_threads];
      for(int i=0; i < threads.length; i++) {
         threads[i]=new MyThread("#" + i, myMutex);
      }
      for(int i=0; i < threads.length; i++) {
         MyThread thread=threads[i];
         System.out.println("starting thread #" + i);
         thread.start();
      }

      _pause(6000);
      synchronized(myMutex) {
         System.out.println("cache is " + c1.printLockInfo());
         System.out.println("******************* SIGNALLING THREADS ********************");
         myMutex.notifyAll();
      }

      for(int i=0; i < threads.length; i++) {
         MyThread thread=threads[i];
         try {
            thread.join();
            System.out.println("Joined thread " + thread.getName());
         }
         catch(InterruptedException e) {
            e.printStackTrace();
         }
      }

      System.out.println("FINAL c1:\n" + c1.printDetails() + "\nlocks:\n" + c1.printLockInfo());

      assertEquals(0, c1.getNumberOfLocksHeld());
      assertEquals(0, c2.getNumberOfLocksHeld());

      c1.stop();
      c2.stop();

//      if(ex != null)
//      {
//         ex.printStackTrace();
//         fail("Thread failed: " + ex);
View Full Code Here

      readerFailed = false;

      writerError = null;
      readerError = null;

      cache = new TreeCache();
      cache.setCacheMode(TreeCache.LOCAL);
      cache.setIsolationLevel(IsolationLevel.READ_COMMITTED);
      cache.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
      cache.startService();
   }
View Full Code Here

   /**
    * Conncurrent put on 2 different instances.
    */
   public void testConcurrentPutsOnTwoInstances() throws Exception {
      initCaches(TreeCache.REPL_SYNC);
      final TreeCache c1=this.cache1;
      final TreeCache c2=this.cache2;

      Thread t1=new Thread() {
         Transaction tx;

         public void run() {
            try {
               tx=beginTransaction();
               c1.put("/ben/wang", "name", "Ben Wang");
               _pause(8000);
               tx.commit(); // This should go thru
            }
            catch(Throwable ex) {
               ex.printStackTrace();
               t1_ex=ex;
            }
         }
      };

      Thread t2=new Thread() {
         Transaction tx;

         public void run() {
            try {
               _pause(1000); // give Thread1 time to acquire the lock
               tx=beginTransaction();
               c2.put("/ben/wang", "name", "Ben Jr.");
               tx.commit(); // This will time out and rollback first because Thread1 has a tx going as well.
            }
            catch(RollbackException rollback_ex) {
               System.out.println("received rollback exception as expected");
            }
View Full Code Here

   }


   public void testPut() throws Exception {
      initCaches(TreeCache.REPL_SYNC);
      final TreeCache c1=this.cache1;


      Thread t1=new Thread() {
         public void run() {
            try {
               lock.acquire();
               System.out.println("-- t1 has lock");
               c1.put("/a/b/c", "age", new Integer(38));
               System.out.println("[Thread1] set value to 38");

               System.out.println("-- t1 releases lock");
               lock.release();
               _pause(300);
               Thread.yield();

               lock.acquire();
               System.out.println("-- t1 has lock");
               c1.put("/a/b/c", "age", new Integer(39));
               System.out.println("[Thread1] set value to 39");

               System.out.println("-- t1 releases lock");
               lock.release();
               assertEquals(new Integer(39), c1.get("/a/b/c", "age"));
            }
            catch(Throwable ex) {
               ex.printStackTrace();
               t1_ex=ex;
            }
View Full Code Here

    * cache2 commit will succeed since now that cache1 is rollbacked and lock is
    * released.
    */
   public void testPutTx1() throws Exception {
      initCaches(TreeCache.REPL_SYNC);
      final TreeCache c1=this.cache1;
      Thread t1=new Thread() {
         public void run() {
            Transaction tx=null;

            try {
               lock.acquire();
               tx=beginTransaction();
               c1.put("/a/b/c", "age", new Integer(38));
               c1.put("/a/b/c", "age", new Integer(39));
               lock.release();

               _pause(300);
               lock.acquire();
               try {
View Full Code Here



   public void testPutTxWithRollback() throws Exception {
      initCaches(TreeCache.REPL_SYNC);
      final TreeCache c2=this.cache1;
      Thread t1=new Thread() {
         public void run() {
            Transaction tx=null;

            try {
               lock.acquire();
               tx=beginTransaction();
               c2.put("/a/b/c", "age", new Integer(38));
               c2.put("/a/b/c", "age", new Integer(39));
               lock.release();

               _pause(100);
               lock.acquire();
               tx.rollback();
View Full Code Here

      writerFailed = false;

      writerError = null;

      cache = new TreeCache();
      cache.setCacheMode(TreeCache.LOCAL);
      cache.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
      cache.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
      cache.setLockAcquisitionTimeout(1000);
      cache.startService();
View Full Code Here

   }



   public void testWithoutTransactions() throws Exception {
      cache=new TreeCache();
      cache.setCacheMode(TreeCache.LOCAL);
      cache.setIsolationLevel(IsolationLevel.NONE);
      cache.startService();
      cache.put(FQN, KEY, VALUE);
      cache.put(FQN + "/d", KEY, VALUE);
View Full Code Here

      System.out.println("cache: " + cache.toString(true) + ", locks: " + cache.printLockInfo());
      assertEquals(0, cache.getNumberOfLocksHeld());
   }

   public void testWithTransactions() throws Exception {
      cache=new TreeCache();
      cache.setCacheMode(TreeCache.LOCAL);
      cache.setIsolationLevel(IsolationLevel.NONE);
      cache.setTransactionManagerLookup(new DummyTransactionManagerLookup());
      cache.startService();
      tx=startTransaction();
View Full Code Here

TOP

Related Classes of org.jboss.cache.TreeCache

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.