Examples of PojoCache


Examples of org.jboss.cache.aop.PojoCache

   public void testPartialStateTransferWithLoader() throws Exception
  
      log.info("Enter testPartialStateTransferWithLoader");
     
      PojoCache cache1 = createCache("cache1", false, true, true);
      cache1.activateRegion("/a");

      cache1.putObject(A_B_1, joe);
      cache1.putObject(A_B_2, jane);

      PojoCache cache2 = createCache("cache2", false, true, true);

      // Pause to give caches time to see each other
      TestingUtil.blockUntilViewsReceived(new PojoCache[]
      {cache1, cache2}, 60000);
     
      CacheLoader loader = cache2.getCacheLoader();
     
      Map map = loader.get(A_B_1);
      if (map != null)
      {
         assertNull("/a/b/1 name not transferred per policy", map.get("name"));
         assertNull("/a/b/1 age not transferred per policy", map.get("age"));
      }
      map = loader.get(A_B_2);
      if (map != null)
      {
         assertNull("/a/b/1 name not transferred per policy", map.get("name"));
         assertNull("/a/b/1 age not transferred per policy", map.get("age"));
      }
      assertNull("/a/b/1 not transferred per policy", cache2.getObject(A_B_1));
      assertNull("/a/b/2 not transferred per policy", cache2.getObject(A_B_2));

      cache2.activateRegion("/a/b");

      assertEquals("Correct name from loader for /a/b/1", joe.getName(), loader.get(A_B_1).get("name"));
      assertEquals("Correct age from loader for /a/b/1", TWENTY, loader.get(A_B_1).get("age"));
      assertEquals("Correct name from loader for /a/b/2", jane.getName(), loader.get(A_B_2).get("name"));
      assertEquals("Correct age from loader for /a/b/2", TWENTYFIVE, loader.get(A_B_2).get("age"));
     
     
      Person ab1  = (Person) cache2.getObject(A_B_1);
      Person ab2 = (Person) cache2.getObject(A_B_2);
      assertEquals("Name for /a/b/1 is Joe", joe.getName(), ab1.getName());
      assertEquals("City for /a/b/1 is Anytown", addr1.getCity(), ab1.getAddress().getCity());
      assertEquals("Name for /a/b/1 is Jane", jane.getName(), ab2.getName());
      assertEquals("City for /a/b/1 is Anytown", addr1.getCity(), ab2.getAddress().getCity());
      assertTrue("Address for Joe and Jane is the same object", ab1.getAddress() == ab2.getAddress());

      cache1.putObject(A_C_1, bob);
      cache1.putObject(A_C_2, jill);
     
      assertNull("/a/c/1 not transferred per policy", cache2.getObject(A_C_1));

      cache2.activateRegion("/a/c");

      assertEquals("Correct name from loader for /a/b/1", joe.getName(), loader.get(A_B_1).get("name"));
      assertEquals("Correct age from loader for /a/b/1", TWENTY, loader.get(A_B_1).get("age"));
      assertEquals("Correct name from loader for /a/b/2", jane.getName(), loader.get(A_B_2).get("name"));
      assertEquals("Correct age from loader for /a/b/2", TWENTYFIVE, loader.get(A_B_2).get("age"));
      assertEquals("Correct name from loader for /a/c/1", bob.getName(), loader.get(A_C_1).get("name"));
      assertEquals("Correct age from loader for /a/c/1", FORTY, loader.get(A_C_1).get("age"));
      assertEquals("Correct name from loader for /a/c/2", jill.getName(), loader.get(A_C_2).get("name"));
      assertEquals("Correct age from loader for /a/c/2", TWENTYFIVE, loader.get(A_C_2).get("age"));
     
      Person ac1 = (Person) cache2.getObject(A_C_1);
      Person ac2 = (Person) cache2.getObject(A_C_2);
      assertEquals("Name for /a/c/1 is Bob", bob.getName(), ac1.getName());
      assertEquals("City for /a/c/1 is Fremont", addr2.getCity(), ac1.getAddress().getCity());
      assertEquals("Name for /a/c/2 is Jill", jill.getName(), ac2.getName());
      assertEquals("City for /a/c/2 is Fremont", addr2.getCity(), ac2.getAddress().getCity());
      assertTrue("Bob and Jill have same Address", ac1.getAddress() == ac2.getAddress());
View Full Code Here

Examples of org.jboss.cache.aop.PojoCache

      int count = names.length;
      CacheStressor[] stressors = new CacheStressor[count];
     
      try {
        
         PojoCache cacheA = createCache("cacheA", sync, true, false, false);
        
         PojoCache[] caches = new PojoCache[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].getTreeCache().put("/" + names[i], null);
         }
         for (int i = 0; i < count; i++)
         {
            stressors[i].start();
            // Give each one a chance to stabilize
            TestingUtil.sleepThread(100);
         }
        
         // Make sure everyone's views are in sync
         TestingUtil.blockUntilViewsReceived(caches, 60000);
        
         // Repeat the basic test two times in order to involve inactivation
         for (int x = 0; x < 2; 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]);
                  log.info("TEST: 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(300);
           
            // Activate cacheA
            for (int i = 0; i < count; i++)
            {
               log.info("TEST: 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();
               log.info("TEST: Run " + x + "-- /" + names[i] + " activated on A");
               // Reacquire one semaphore ticket
               boolean acquired = semaphore.attempt(60000);
               if (!acquired)
                  fail("failed to acquire semaphore " + names[i]);
               log.info("TEST: Run " + x + "-- acquired semaphore from " + names[i]);
              
               // Pause to allow other work to proceed
               TestingUtil.sleepThread(100);
            }
           
            // Sleep to allow any in transit msgs to clear
            if (!sync)
               TestingUtil.sleepThread(2000);
           
            // Ensure the stressors saw no exceptions
            for (int i = 0; i < count; i++)
            {
               Exception e = stressors[i].getException();
               if (e != null)
               {
                  log.error("Stressor " + names[i] + " caught an exception",
                          e);
                  throw e;
               }
            }
           
            log.info("Cache A details:\n" + cacheA.printDetails());
           
            // Compare cache contents
            Person p1 = null;
            Person p2 = null;
            for (int i = 0; i < count; i++)
            {
               log.info("Cache " + names[i] + " details:\n" +
                        stressors[i].getTreeCache().printDetails());
              
               for (int j = 0; j < SUBTREE_SIZE; j++)
               {
                 
                  String fqn = "/" + names[i] +"/" + j;
                  log.info("TEST: Getting A:" + fqn);
                  p1 = (Person) cacheA.getObject(fqn);
                  boolean p1Null = p1 == null;
                  log.info("TEST: Getting " + names[i] + ":" + fqn);
                  p2 = (Person) stressors[i].getTreeCache().getObject(fqn);
                  boolean p2Null = p2 == null;
                  assertEquals("Run " + x + ": " + fqn +
View Full Code Here

Examples of org.jboss.cache.aop.PojoCache

      throws Exception
   {
      if (caches.get(cacheID) != null)
         throw new IllegalStateException(cacheID + " already created");

      PojoCache tree = new PojoCache();
      PropertyConfigurator config = new PropertyConfigurator();
      String configFile = sync ? "META-INF/replSync-service.xml" : "META-INF/replAsync-service.xml";
      config.configure(tree, configFile); // read in generic replAsync xml
      //tree.setDeadlockDetection(sync);
      tree.setClusterName("StateTransferTestBase");
      tree.setReplicationVersion(getReplicationVersion());
      // Use a long timeout to facilitate setting debugger breakpoints
      tree.setInitialStateRetrievalTimeout(60000);
      if (useMarshalling)
      {
         tree.setUseMarshalling(true);
         tree.setInactiveOnStartup(inactiveOnStartup);
      }
      if (useCacheLoader)
      {
         configureCacheLoader(tree, cacheID, useMarshalling);
      }
     
      // Put the cache in the map before starting, so if it fails in
      // start it can still be destroyed later
      caches.put(cacheID, tree);
     
      tree.createService();
      tree.startService();

      return tree;
   }
View Full Code Here

Examples of org.jboss.cache.aop.PojoCache

   protected void setUp() throws Exception
   {
      super.setUp();
      log.info("setUp() ....");
      String configFile = "META-INF/cache-config.xml";
      cache_ = new PojoCache();
      PropertyConfigurator config = new PropertyConfigurator();
      config.configure(cache_, configFile); // read in generic replSync xml
      cache_.start();

   }
View Full Code Here

Examples of org.jboss.cache.aop.PojoCache

   protected void setUp() throws Exception
   {
      super.setUp();
      Properties prop = new Properties();
      prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.cache.transaction.DummyContextFactory");
      cache_ = new PojoCache();
      PropertyConfigurator config = new PropertyConfigurator(); // configure tree cache.
      config.configure(cache_, "META-INF/replSync-service.xml");

      cache1_ = new PojoCache();
      config.configure(cache1_, "META-INF/replSync-service.xml");
      cache_.start();
      cache1_.start();
   }
View Full Code Here

Examples of org.jboss.cache.aop.PojoCache

   protected void setUp() throws Exception
   {
      super.setUp();
      log.info("setUp() ....");
      String configFile = "META-INF/local-service.xml";
      cache_ = new PojoCache();
      PropertyConfigurator config = new PropertyConfigurator();
      config.configure(cache_, configFile); // read in generic replSync xml
      cache_.start();

      stage();
View Full Code Here

Examples of org.jboss.cache.aop.PojoCache

      cache_.remove("/");
      cache_.stop();
   }

   private PojoCache createCache(String name) throws Exception {
      PojoCache tree = new PojoCache();
      PropertyConfigurator config = new PropertyConfigurator();
//      config.configure(tree, "META-INF/replSync-service.xml"); // read in generic replAsync xml
      config.configure(tree, "META-INF/local-service.xml"); // read in generic replAsync xml
      tree.setClusterName(name);
      tree.createService();
      tree.startService();
      return tree;
   }
View Full Code Here

Examples of org.jboss.cache.aop.PojoCache

   Transaction tx = null;
   static final Fqn FQN = new Fqn("key");

   protected void setUp() throws Exception {
      super.setUp();
      cache = new PojoCache();
      cache.setCacheMode("local");
      configureCache();
      cache.setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
      cache.createService();
      cache.startService();
View Full Code Here

Examples of org.jboss.cache.aop.PojoCache

   {
      super.setUp();
      log.info("setUp() ....");
//      String configFile = "META-INF/local-service.xml";
      String configFile = "META-INF/local-service.xml";
      cache_ = new PojoCache();
      PropertyConfigurator config = new PropertyConfigurator();
      config.configure(cache_, configFile); // read in generic replSync xml
      cache_.start();
   }
View Full Code Here

Examples of org.jboss.cache.aop.PojoCache

      cache1.stop();
      cache2.stop();
   }

   private PojoCache createCache(String name) throws Exception {
      PojoCache tree=new PojoCache();
      PropertyConfigurator config=new PropertyConfigurator();
      config.configure(tree, "META-INF/replSync-service.xml"); // read in generic replAsync xml
      tree.setClusterName(name);
      tree.createService();
      tree.startService();
      return tree;
   }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.