Package org.jboss.cache

Examples of org.jboss.cache.TreeCacheMBean


      assertEquals("Incorrect name for /a/d", JANE, cache1.get("/a/d", "name"));
   }
  
   public void testPartialStateTferWithLoader() throws Exception
   {
      TreeCacheMBean cache1 = createCache("cache1", false, true, true);
     
      cache1.activateRegion("/a");
     
      cache1.put("/a/b", "name", JOE);
      cache1.put("/a/b", "age", TWENTY);
      cache1.put("/a/c", "name", BOB);
      cache1.put("/a/c", "age", FORTY);
     
      TreeCacheMBean cache2 = createCache("cache2", false, true, true);
     
      // Pause to give caches time to see each other
      TestingUtil.blockUntilViewsReceived(new TreeCacheMBean[] { cache1, cache2 }, 60000);
     
      CacheLoader loader = cache2.getCacheLoader();
     
      assertNull("/a/b transferred to loader against policy", loader.get(A_B));

      assertNull("/a/b name transferred against policy", cache2.get("/a/b", "name"));
      assertNull("/a/b age transferred against policy", cache2.get("/a/b", "age"));
      assertNull("/a/c name transferred against policy", cache2.get("/a/c", "name"));
      assertNull("/a/c age transferred against policy", cache2.get("/a/c", "age"));
     
      cache2.activateRegion("/a/b");    

     
      Map ab = loader.get(A_B);
      assertNotNull("Loader transferred /a/b", ab);
      assertEquals("Incorrect name from loader for /a/b", JOE, ab.get("name"));
      assertEquals("Incorrect age from loader for /a/b", TWENTY, ab.get("age"));
      assertNull("/a/c transferred to loader against policy", loader.get(A_C));

      assertEquals("Incorrect name for /a/b", JOE, cache2.get("/a/b", "name"));
      assertEquals("Incorrect age for /a/b", TWENTY, cache2.get("/a/b", "age"));
      assertNull("/a/c name transferred against policy", cache2.get("/a/c", "name"));
      assertNull("/a/c age transferred against policy", cache2.get("/a/c", "age"));
     
      cache1.put("/a/d", "name", JANE);
     
      assertNull("/a/d name transferred against policy", cache2.get("/a/d", "name"));
     
      cache2.activateRegion("/a/c");    
     
      ab = loader.get(A_B);
      assertNotNull("Loader still has /a/b", ab);
      assertEquals("Incorrect name from loader for /a/b", JOE, ab.get("name"));
      assertEquals("Incorrect age from loader for /a/b", TWENTY, ab.get("age"));

      Map ac = loader.get(A_C);
      assertNotNull("Loader transferred /a/c", ac);
      assertEquals("Incorrect name from loader for /a/c", BOB, ac.get("name"));
      assertEquals("Incorrect age from loader for /a/c", FORTY, ac.get("age"));
     
      assertEquals("Incorrect name for /a/b", JOE, cache2.get("/a/b", "name"));
      assertEquals("Incorrect age for /a/b", TWENTY, cache2.get("/a/b", "age"));
      assertEquals("Incorrect name for /a/c", BOB, cache2.get("/a/c", "name"));
      assertEquals("Incorrect age for /a/c", FORTY, cache2.get("/a/c", "age"));
      assertNull("/a/d name transferred against policy", cache2.get("/a/d", "name"));
     
      cache2.activateRegion("/a/d");        
     
      ab = loader.get(A_B);
      assertNotNull("Loader still has /a/b", ab);     
      assertEquals("Incorrect name from loader for /a/b", JOE, ab.get("name"));
      assertEquals("Incorrect age from loader for /a/b", TWENTY, ab.get("age"));
      ac = loader.get(A_C);
      assertNotNull("Loader transferred /a/c", ac);
      assertEquals("Incorrect name from loader for /a/c", BOB, ac.get("name"));
      assertEquals("Incorrect age from loader for /a/c", FORTY, ac.get("age"));
      Map ad = loader.get(A_D);
      assertNotNull("Loader transferred /a/d", ad);
      assertEquals("Incorrect name from loader for /a/d", JANE, ad.get("name"));
     
      assertEquals("Incorrect name for /a/b", JOE, cache2.get("/a/b", "name"));
      assertEquals("Incorrect age for /a/b", TWENTY, cache2.get("/a/b", "age"));
      assertEquals("Incorrect name for /a/c", BOB, cache2.get("/a/c", "name"));
      assertEquals("Incorrect age for /a/c", FORTY, cache2.get("/a/c", "age"));
      assertEquals("Incorrect name for /a/d", JANE, cache2.get("/a/d", "name"));
     
      cache1.inactivateRegion("/a");
     
      cache1.activateRegion("/a/b");     
      cache1.activateRegion("/a/c");     
View Full Code Here


      // both before and after startService()
     
      // Set the TCL to a classloader that can't see Person/Address
      Thread.currentThread().setContextClassLoader(getNotFoundClassLoader());
     
      TreeCacheMBean cache1 = createCache("cache1",
                                          false,  // async
                                          true,   // use marshaller
                                          true,   // use cacheloader
                                          false, false); // don't start
      ClassLoader cl1 = getClassLoader();
      cache1.registerClassLoader("/a", cl1);
      startCache(cache1);
     
      cache1.activateRegion("/a");
     
      Object ben = createBen(cl1);
     
      cache1.put("/a/b", "person", ben);
     
      // For cache 2 we won't register loader until later
      TreeCacheMBean cache2 = createCache("cache2",
                                          false,  // async
                                          true,   // use marshalling
                                          true,   // use cacheloader
                                          false, true)// start
     
      // Pause to give caches time to see each other
      TestingUtil.blockUntilViewsReceived(new TreeCacheMBean[] { cache1, cache2 }, 60000);
     
      CacheLoader loader = cache2.getCacheLoader();
     
      assertNull("/a/b not transferred to loader", loader.get(A_B));
     
      assertNull("/a/b not transferred to cache", cache2.get("/a/b", "person"));
     
      ClassLoader cl2 = getClassLoader();
     
//      cache2.registerClassLoader("/a", cl2);
      cache2.activateRegion("/a");    
     
      assertEquals("Correct state from loader for /a/b", ben.toString(), loader.get(A_B).get("person").toString());
     
      assertEquals("Correct state from cache for /a/b", ben.toString(), cache2.get("/a/b", "person").toString());
     
   }
View Full Code Here

     
   }
  
   public void testLoadEntireStateAfterStart() throws Exception
   {
      TreeCacheMBean cache1 = createCache("cache1", false, true, true);
     
      cache1.activateRegion("/");
     
      cache1.put("/a/b", "name", JOE);
      cache1.put("/a/b", "age", TWENTY);
      cache1.put("/a/c", "name", BOB);
      cache1.put("/a/c", "age", FORTY);
     
      TreeCacheMBean cache2 = createCache("cache2", false, true, true);
     
      // Pause to give caches time to see each other
      TestingUtil.blockUntilViewsReceived(new TreeCacheMBean[] { cache1, cache2 }, 60000);
     
      CacheLoader loader = cache2.getCacheLoader();
     
      assertNull("/a/b transferred to loader against policy", loader.get(A_B));
     
      assertNull("/a/b name transferred against policy", cache2.get("/a/b", "name"));
      assertNull("/a/b age transferred against policy", cache2.get("/a/b", "age"));
      assertNull("/a/c name transferred against policy", cache2.get("/a/c", "name"));
      assertNull("/a/c age transferred against policy", cache2.get("/a/c", "age"));
     
      cache2.activateRegion("/");    
     
      assertEquals("Incorrect name from loader for /a/b", JOE, loader.get(A_B).get("name"));
      assertEquals("Incorrect age from loader for /a/b", TWENTY, loader.get(A_B).get("age"));
      assertEquals("Incorrect name from loader for /a/c", BOB, loader.get(A_C).get("name"));
      assertEquals("Incorrect age from loader for /a/c", FORTY, loader.get(A_C).get("age"));
     
      assertEquals("Incorrect name for /a/b", JOE, cache2.get("/a/b", "name"));
      assertEquals("Incorrect age for /a/b", TWENTY, cache2.get("/a/b", "age"));
      assertEquals("Incorrect name for /a/c", BOB, cache2.get("/a/c", "name"));
      assertEquals("Incorrect age for /a/c", FORTY, cache2.get("/a/c", "age"));
     
   }
View Full Code Here

      CacheStressor[] stressors = new CacheStressor[count];
     
      try {
        
         // The first cache we create is inactivated.
         TreeCacheMBean cacheA = createCache("cacheA", sync, true, false);
        
         TreeCacheMBean[] caches = new TreeCacheMBean[count + 1];
         caches[0] = cacheA;
        
         // Create a semaphore and take all its tickets
         Semaphore semaphore = new Semaphore(count);        
         for (int i = 0; i < count; i++) {
            semaphore.acquire();
         }  
        
         // Create stressor threads that will block on the semaphore
                 
         for (int i = 0; i < count; i++)
         {
            stressors[i] = new CacheStressor(semaphore, names[i], sync);
            caches[i + 1] = stressors[i].getTreeCache();
            stressors[i].start();
         }
        
         // Make sure everyone's views are in sync
         TestingUtil.blockUntilViewsReceived(caches, 60000);
        
         // Repeat the basic test four times
         //for (int x = 0; x < 4; x++)
         for (int x = 0; x < 1; x++)
         {
            if (x > 0)
            {
               // Reset things by inactivating the region
               // and enabling the stressors
               for (int i = 0; i < count; i++)
               {
                  cacheA.inactivateRegion("/" + names[i]);
                  System.out.println("Run " + x + "-- /" + names[i] + " inactivated on A");
                  stressors[i].startPuts();
               }
            }
           
            // Release the semaphore to allow the threads to start work
            semaphore.release(count);
           
            // Sleep to ensure the threads get all the semaphore tickets
            // and to ensure puts are actively in progress
             TestingUtil.sleepThread((long)300);

             // Activate cacheA
            for (int i = 0; i < count; i++)
            {
//              System.out.println("Activating /" + names[i] + " on A");
               cacheA.activateRegion("/" + names[i]);
               // Stop the stressor so we don't pollute cacheA's state
               // with too many messages sent after activation -- we want
               // to compare transferred state with the sender
               stressors[i].stopPuts();
               System.out.println("Run " + x + "-- /" + names[i] + " activated on A");
               // Reacquire one semaphore ticket
               boolean acquired = semaphore.attempt(60000);
               if (!acquired)
                  fail("failed to acquire semaphore " + i);
              
               // Pause to allow other work to proceed
                TestingUtil.sleepThread((long)100);
            }
           
            // Sleep to allow any in transit msgs to clear
//            if (!sync)
             TestingUtil.sleepThread((long)1000);

             // Ensure the stressors saw no exceptions
            for (int i = 0; i < count; i++)
            {
               assertNull("Stressor " + names[i] + " caught an exception",
                          stressors[i].getException());           
            }
           
            // Compare cache contents
            for (int i = 0; i < count; i++)
            {
               for (int j = 0; j < SUBTREE_SIZE; j++)
               {
                  String fqn = "/" + names[i] +"/" + j;
                  assertEquals("/A/" + j + " matches " + fqn,
                               cacheA.get(fqn, "KEY"),
                               stressors[i].getTreeCache().get(fqn, "KEY"));
               }
            }
         }
        
View Full Code Here

      CacheProperties cacheProperties = new CacheProperties(properties);
     
      try
      {
         ObjectName mbeanObjectName = new ObjectName(cacheProperties.getCacheObjectName());
         TreeCacheMBean mbean = (TreeCacheMBean) MBeanProxyExt.create(TreeCacheMBean.class, mbeanObjectName, MBeanServerLocator.locateJBoss());
         cache = mbean.getInstance();
         if ("OPTIMISTIC".equals(cache.getNodeLockingScheme()))
         {
            optimistic = true;
            log.debug("JBoss Cache is configured for optimistic locking; " +
                    "provided Cache implementations will also implement OptimisticCache");
View Full Code Here

TOP

Related Classes of org.jboss.cache.TreeCacheMBean

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.