Package org.jboss.cache

Examples of org.jboss.cache.CacheSPI


      }
   }

   public void testExistenceOfTombstones()
   {
      CacheSPI modifierImpl = (CacheSPI) modifier;
      CacheSPI observerImpl = (CacheSPI) observer;

      modifier.put(parent, K, V);
      modifier.removeNode(parent);

      if (optimistic && invalidation)
      {
         // if we are using optimistic invalidation then we should see tombstones.  NOT otherwise.
         NodeSPI modifierTombstone = modifierImpl.peek(parent, true, true);
         NodeSPI observerTombstone = observerImpl.peek(parent, true, true);

         assert modifierTombstone != null : "Modifier tombstone should not be null";
         assert observerTombstone != null : "Observer tombstone should not be null";

         assert !modifierTombstone.isValid() : "Should not be valid";
         assert !observerTombstone.isValid() : "Should not be valid";

         assert ((DefaultDataVersion) modifierTombstone.getVersion()).getRawVersion() == 2 : "Tombstone should be versioned";
         assert ((DefaultDataVersion) observerTombstone.getVersion()).getRawVersion() == 2 : "Tombstone should be versioned";

      }
      else
      {
         // if we are using pess locking there should be NO tombstones, regardless of replication/invalidation!
         assert modifierImpl.peek(parent, true, true) == null : "Tombstone should not exist";
         assert observerImpl.peek(parent, true, true) == null : "Tombstone should not exist";
      }
   }
View Full Code Here


      }
   }

   public void testExistenceOfTombstonesWithChildren()
   {
      CacheSPI modifierImpl = (CacheSPI) modifier;
      CacheSPI observerImpl = (CacheSPI) observer;

      modifier.put(child, K, V);
      modifier.removeNode(parent);

      if (optimistic && invalidation)
      {
         // if we are using optimistic invalidation then we should see tombstones.  NOT otherwise.
         NodeSPI modifierParentTombstone = modifierImpl.peek(parent, true, true);
         NodeSPI observerParentTombstone = observerImpl.peek(parent, true, true);
         NodeSPI modifierChildTombstone = modifierImpl.peek(child, true, true);
         NodeSPI observerChildTombstone = observerImpl.peek(child, true, true);

         assert modifierParentTombstone != null : "Modifier parent tombstone should not be null";
         assert observerParentTombstone != null : "Observer parent tombstone should not be null";
         assert modifierChildTombstone != null : "Modifier child tombstone should not be null";
         assert observerChildTombstone != null : "Observer child tombstone should not be null";

         assert !modifierParentTombstone.isValid() : "Should not be valid";
         assert !observerParentTombstone.isValid() : "Should not be valid";
         assert !modifierChildTombstone.isValid() : "Should not be valid";
         assert !observerChildTombstone.isValid() : "Should not be valid";

         assert ((DefaultDataVersion) modifierParentTombstone.getVersion()).getRawVersion() == 1 : "Tombstone should be versioned";
         assert ((DefaultDataVersion) observerParentTombstone.getVersion()).getRawVersion() == 1 : "Tombstone should be versioned";

         // note that versions on children cannot be incremented/updated since the remove operation was
         // performed on the parent.
         assert ((DefaultDataVersion) modifierChildTombstone.getVersion()).getRawVersion() == 1 : "Tombstone should be versioned";
         assert ((DefaultDataVersion) observerChildTombstone.getVersion()).getRawVersion() == 1 : "Tombstone should be versioned";

      }
      else
      {
         // if we are using pess locking there should be NO tombstones, regardless of replication/invalidation!
         assert modifierImpl.peek(parent, true, true) == null : "Tombstone should not exist";
         assert observerImpl.peek(parent, true, true) == null : "Tombstone should not exist";
         assert modifierImpl.peek(child, true, true) == null : "Tombstone should not exist";
         assert observerImpl.peek(child, true, true) == null : "Tombstone should not exist";
      }
   }
View Full Code Here

      }
   }

   protected TransactionWorkspace extractTransactionWorkspace(Cache c)
   {
      CacheSPI cs = (CacheSPI) c;
      try
      {
         GlobalTransaction gtx = cs.getTransactionTable().get(cs.getTransactionManager().getTransaction());
         OptimisticTransactionEntry entry = (OptimisticTransactionEntry) cs.getTransactionTable().get(gtx);
         return entry.getTransactionWorkSpace();
      }
      catch (SystemException e)
      {
         e.printStackTrace();
View Full Code Here

      State originalState = overallState;
      moveComponentsToState(overallState == STARTED ? STOPPED : CONSTRUCTED);
      moveComponentsToState(originalState);
      // re- add a few key components - this is a hack for now
      CacheImpl ci = getComponent(CacheImpl.class);
      CacheSPI rcid = getComponent("remoteDelegate", RemoteCacheInvocationDelegate.class);
      CacheSPI spi = getComponent(CacheSPI.class.getName(), CacheSPI.class);

      unregisterComponent(CacheImpl.class);
      unregisterComponent(CacheSPI.class.getName());
      unregisterComponent("remoteDelegate");
View Full Code Here

   private void testDataOwner(boolean optimistic) throws Exception
   {
      caches = createCaches(1, 2, false, true, optimistic);

      // add some stuff on the primary
      CacheSPI dataOwner = caches.get(0);
      CacheSPI buddy = caches.get(1);

      dataOwner.put(fqn, key, value);

      System.out.println("dataOwner: " + CachePrinter.printCacheLockingInfo(dataOwner));
      System.out.println("buddy: " + CachePrinter.printCacheLockingInfo(buddy));

      assert dataOwner.peek(fqn, false) != null : "Should have data";
      assert dataOwner.peek(new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(buddy.getLocalAddress())), false) != null : "Should have backup node for buddy";
      assert dataOwner.peek(new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(dataOwner.getLocalAddress())), false) == null : "Should NOT have backup node for self!";

      assert buddy.peek(fqn, false) == null : "Should not have data";
      assert buddy.peek(new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(buddy.getLocalAddress())), false) == null : "Should NOT have backup node for self!";
      assert buddy.peek(new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(dataOwner.getLocalAddress())), false) != null : "Should have backup node for buddy";
      assert buddy.peek(BuddyManager.getBackupFqn(dataOwner.getLocalAddress(), fqn), false) != null : "Should have backup data";

      // now do a gravitate call.
      assert buddy.get(fqn, key).equals(value) : "Data should have gravitated!";

      System.out.println("dataOwner: " + CachePrinter.printCacheLockingInfo(dataOwner));
      System.out.println("buddy: " + CachePrinter.printCacheLockingInfo(buddy));

      assert buddy.peek(fqn, false) != null : "Should have data";
      assert buddy.peek(new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(dataOwner.getLocalAddress())), false) != null : "Should have backup node for buddy";
      assert buddy.peek(new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(buddy.getLocalAddress())), false) == null : "Should NOT have backup node for self!";

      assert dataOwner.peek(fqn, false) == null : "Should not have data";
      assert dataOwner.peek(new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(dataOwner.getLocalAddress())), false) == null : "Should NOT have backup node for self!";
      assert dataOwner.peek(new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(buddy.getLocalAddress())), false) != null : "Should have backup node for buddy";
      assert dataOwner.peek(BuddyManager.getBackupFqn(buddy.getLocalAddress(), fqn), false) != null : "Should have backup data";
   }
View Full Code Here

   private void testBuddy(boolean optimistic) throws Exception
   {
      caches = createCaches(1, 3, false, true, optimistic);

      // add some stuff on the primary
      CacheSPI dataOwner = caches.get(0);
      CacheSPI buddy = caches.get(1);
      CacheSPI thirdInstance = caches.get(2);

      assertIsBuddy(dataOwner, buddy, true);
      assertIsBuddy(buddy, thirdInstance, true);
      assertIsBuddy(thirdInstance, dataOwner, true);

      dataOwner.put(fqn, key, value);

      System.out.println("dataOwner: " + CachePrinter.printCacheLockingInfo(dataOwner));
      System.out.println("buddy: " + CachePrinter.printCacheLockingInfo(buddy));
      System.out.println("thirdInstance: " + CachePrinter.printCacheLockingInfo(thirdInstance));

      assert dataOwner.peek(fqn, false) != null : "Should have data";
      assert dataOwner.peek(new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(thirdInstance.getLocalAddress())), false) != null : "Should have backup node for buddy";
      assert dataOwner.peek(new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(dataOwner.getLocalAddress())), false) == null : "Should NOT have backup node for self!";
      assert dataOwner.peek(new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(buddy.getLocalAddress())), false) == null : "Should NOT have backup node for 2nd instance!";

      assert buddy.peek(fqn, false) == null : "Should not have data";
      assert buddy.peek(new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(buddy.getLocalAddress())), false) == null : "Should NOT have backup node for self!";
      assert buddy.peek(new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(dataOwner.getLocalAddress())), false) != null : "Should have backup node for buddy";
      assert buddy.peek(BuddyManager.getBackupFqn(dataOwner.getLocalAddress(), fqn), false) != null : "Should have backup data";

      // now do a gravitate call.
      assert thirdInstance.get(fqn, key).equals(value) : "Data should have gravitated!";

      System.out.println("dataOwner: " + CachePrinter.printCacheLockingInfo(dataOwner));
      System.out.println("buddy: " + CachePrinter.printCacheLockingInfo(buddy));
      System.out.println("thirdInstance: " + CachePrinter.printCacheLockingInfo(thirdInstance));

      assert thirdInstance.peek(fqn, false) != null : "Should have data";
      assert thirdInstance.peek(new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(buddy.getLocalAddress())), false) != null : "Should have backup node for buddy";
      assert thirdInstance.peek(new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(thirdInstance.getLocalAddress())), false) == null : "Should NOT have backup node for self!";

      assert dataOwner.peek(fqn, false) == null : "Should not have data";
      assert dataOwner.peek(new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(dataOwner.getLocalAddress())), false) == null : "Should NOT have backup node for self!";
      assert dataOwner.peek(new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(thirdInstance.getLocalAddress())), false) != null : "Should have backup node for buddy";
      assert dataOwner.peek(BuddyManager.getBackupFqn(thirdInstance.getLocalAddress(), fqn), false) != null : "Should have backup data";
      assert buddy.peek(fqn, false) == null : "Should not have data";
      assert buddy.peek(fqn.getParent(), false) == null : "Should not have any part of the data";
      assert buddy.peek(BuddyManager.getBackupFqn(dataOwner.getLocalAddress(), fqn), false) == null : "Should NOT have backup data";

   }
View Full Code Here

public class OptimisticWithCacheLoaderTest extends AbstractOptimisticTestCase
{

   public void testLoaderIndependently() throws Exception
   {
      CacheSPI cache = createCacheWithLoader();
      CacheLoader loader = cache.getCacheLoaderManager().getCacheLoader();

      // test the cache loader independently first ...
      loader.remove(fqn);
      assert loader.get(fqn) == null;
      loader.put(fqn, key, value);
View Full Code Here

    */
   private void _testConcurrentCommits(int num_threads)
   {
      Object myMutex = new Object();

      final CacheSPI c1 = (CacheSPI) new DefaultCacheFactory().createCache(false);
      final CacheSPI c2 = (CacheSPI) new DefaultCacheFactory().createCache(false);
      c1.getConfiguration().setClusterName("TempCluster");
      c2.getConfiguration().setClusterName("TempCluster");
      c1.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
      c2.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
      c1.getConfiguration().setSyncCommitPhase(true);
      c2.getConfiguration().setSyncCommitPhase(true);
      c1.getConfiguration().setSyncRollbackPhase(true);
      c2.getConfiguration().setSyncRollbackPhase(true);
      c1.getConfiguration().setIsolationLevel(IsolationLevel.REPEATABLE_READ);
      c2.getConfiguration().setIsolationLevel(IsolationLevel.REPEATABLE_READ);
      c1.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
      c2.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
      c1.getConfiguration().setLockAcquisitionTimeout(5000);
      c2.getConfiguration().setLockAcquisitionTimeout(5000);
      c1.start();
      c2.start();
      final List<Exception> exceptions = new ArrayList<Exception>();

      class MyThread extends Thread
      {
         Object mutex;

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

         public void run()
         {
            TransactionManager tm = null;

            try
            {
               tm = beginTransaction(c1);
               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");
               tm.commit();
               System.out.println("Thread " + getName() + " committed successfully");
            }
            catch (Exception e)
            {
               exceptions.add(e);
            }
            finally
            {
               try
               {
                  if (tm != null)
                     tm.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();
      }

      TestingUtil.sleepThread(6000);
      synchronized (myMutex)
      {
         System.out.println("cache is " + CachePrinter.printCacheLockingInfo(c1));
         System.out.println("******************* SIGNALLING THREADS ********************");
         myMutex.notifyAll();
      }

      for (MyThread thread : threads)
      {
         try
         {
            thread.join();
            System.out.println("Joined thread " + thread.getName());
         }
         catch (InterruptedException e)
         {
            e.printStackTrace();
         }
      }

      System.out.println("FINAL c1:\n" + CachePrinter.printCacheDetails(c1) + "\nlocks:\n" + CachePrinter.printCacheLockingInfo(c1));

      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

    */
   private void deletedChildResurrectionTest1(boolean optimistic) throws Exception
   {
      cache.getConfiguration().setNodeLockingOptimistic(optimistic);
      cache.start();
      CacheSPI spi = (CacheSPI) cache;
      Node<Object, Object> root = cache.getRoot();

      TransactionManager txManager = cache.getConfiguration().getRuntimeConfig().getTransactionManager();

      root.addChild(A_B).put(KEY, VALUE);
      cache.put(A, "key","value");
      txManager.begin();
      root.removeChild(A);
      root.addChild(A);
      txManager.commit();
      assert !root.hasChild(A_B);
      assert null == cache.get(A, "key");
      // do a peek to ensure the node really has been removed and not just marked for removal
      assert spi.peek(A_B, true, true) == null;
      assert root.hasChild(A);
   }
View Full Code Here

      return o instanceof MarshalledValue ? ((MarshalledValue) o).get() : o;
   }

   public void testStalePersistentState() throws Exception
   {
      CacheSPI c1 = createCache("1", true, false, true, false);
      c1.put(A, "K", "V");

      assert c1.get(A, "K").equals("V");
      CacheLoader l1 = c1.getCacheLoaderManager().getCacheLoader();
      assert l1 != null;

      assert l1.exists(A);
      assert l1.get(A).get("K").equals("V");

      // test persistence
      c1.stop();

      assert l1.exists(A);
      assert l1.get(A).get("K").equals("V");

      Cache c2 = createCache("2", true, false, true, false);

      c2.put(B, "K", "V");

      c1.start();

      assert c1.get(B, "K").equals("V");
      assert c1.get(A, "K") == null;
      assert !l1.exists(A);
   }
View Full Code Here

TOP

Related Classes of org.jboss.cache.CacheSPI

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.