Examples of CacheLoader


Examples of org.jboss.cache.loader.CacheLoader

      assertNull(loader.get(fqn));
   }

   public void testCacheLoadOnTree() throws Exception
   {
      CacheLoader loader = null;
      try
      {
         CacheSPI<Object, Object> cache = createCacheWithLoader();
         loader = cache.getCacheLoaderManager().getCacheLoader();

         TransactionManager mgr = cache.getTransactionManager();
         Transaction tx;

         // make sure the fqn is not in cache
         assertNull(cache.getNode(fqn));

         // put something in the loader and make sure all tx's can see it
         loader.put(fqn, key, value);

         // start the 1st tx
         mgr.begin();
         tx = mgr.getTransaction();
         assertEquals(value, cache.get(fqn, key));
         mgr.suspend();

         // start a new tx
         mgr.begin();
         assertEquals(value, cache.get(fqn, key));
         mgr.commit();

         mgr.resume(tx);
         assertEquals(value, cache.get(fqn, key));
         mgr.commit();
      }
      finally
      {
         // cleanup
         if (loader != null) loader.remove(fqn);
      }
   }
View Full Code Here

Examples of org.jboss.cache.loader.CacheLoader

   public void testCacheStoring() throws Exception
   {
      Transaction tx;
      CacheSPI<Object, Object> cache = createCacheWithLoader();
      CacheLoader loader = cache.getCacheLoaderManager().getCacheLoader();

      // test the cache ...
      TransactionManager mgr = cache.getTransactionManager();
      assertNull(mgr.getTransaction());
      mgr.begin();
      cache.put(fqn, key, value);
      mgr.commit();

      assertEquals(value, cache.get(fqn, key));

      //now lets see if the state has been persisted in the cache loader
      assertEquals(value, loader.get(fqn).get(key));


      mgr.begin();
      cache.removeNode(fqn);
      mgr.commit();

      assertNull(cache.get(fqn, key));
      //now lets see if the state has been persisted in the cache loader
      assertNull(loader.get(fqn));

      mgr.begin();
      cache.put(fqn, key, value);
      tx = mgr.getTransaction();
      mgr.suspend();

      // lets see what we've got halfway within a tx
      assertNull(cache.get(fqn, key));
      assertNull(loader.get(fqn));

      mgr.resume(tx);
      mgr.commit();

      // and after committing...
      assertEquals(value, cache.get(fqn, key));
      assertEquals(value, loader.get(fqn).get(key));

      // clean up loader
      loader.remove(fqn);
   }
View Full Code Here

Examples of org.jboss.cache.loader.CacheLoader


   public void testCacheStoringImplicitTx() throws Exception
   {
      CacheSPI<Object, Object> cache = createCacheWithLoader();
      CacheLoader loader = cache.getCacheLoaderManager().getCacheLoader();

      // test the cache ...
      TransactionManager mgr = cache.getTransactionManager();
      assertNull(mgr.getTransaction());
      cache.put(fqn, key, value);

      assertEquals(value, cache.get(fqn, key));

      //now lets see if the state has been persisted in the cache loader
      assertEquals(value, loader.get(fqn).get(key));


      cache.removeNode(fqn);

      assertNull(cache.get(fqn, key));
      //now lets see if the state has been persisted in the cache loader
      assertNull(loader.get(fqn));

      cache.put(fqn, key, value);

      assertEquals(value, cache.get(fqn, key));
      assertEquals(value, loader.get(fqn).get(key));

      // clean up loader
      loader.remove(fqn);
   }
View Full Code Here

Examples of org.jboss.cache.loader.CacheLoader

   }

   public void testCacheStoringImplicitTxOptionOverride() throws Exception
   {
      CacheSPI<Object, Object> cache = createCacheWithLoader();
      CacheLoader loader = cache.getCacheLoaderManager().getCacheLoader();
      Option option = new Option();
      option.setCacheModeLocal(true);
      cache.getInvocationContext().setOptionOverrides(option);
      cache.put(fqn, key, value);
      assertEquals(value, cache.get(fqn, key));
      //now lets see if the state has been persisted in the cache loader
      assertNotNull(loader.get(fqn));
      assertNotNull(value, loader.get(fqn).get(key));
      cache.removeNode(fqn);
   }
View Full Code Here

Examples of org.jboss.cache.loader.CacheLoader


   public void testCacheLoading() throws Exception
   {
      CacheSPI<Object, Object> cache = createCacheWithLoader();
      CacheLoader loader = cache.getCacheLoaderManager().getCacheLoader();

      assertNull(cache.get(fqn, key));

      // put something in the loader
      loader.put(fqn, key, value);
      assertEquals(value, loader.get(fqn).get(key));

      // test that this can now be accessed by the cache
      assertEquals(value, cache.get(fqn, key));

      // clean up loader
      loader.remove(fqn);

      // what's in the cache now?  Should not ne null...
      assertNotNull(cache.get(fqn, key));
   }
View Full Code Here

Examples of org.jboss.cache.loader.CacheLoader

   }

   public void testCacheLoadingWithReplication() throws Exception
   {
      CacheSPI<Object, Object> cache1 = createReplicatedCacheWithLoader(false);
      CacheLoader loader1 = cache1.getCacheLoaderManager().getCacheLoader();

      CacheSPI<Object, Object> cache2 = createReplicatedCacheWithLoader(false);
      CacheLoader loader2 = cache2.getCacheLoaderManager().getCacheLoader();

      // test the cache ...
      TransactionManager mgr = cache1.getTransactionManager();
      assertNull(mgr.getTransaction());

      mgr.begin();

      // add something in cache1
      cache1.put(fqn, key, value);
      assertEquals(value, cache1.get(fqn, key));

      // test that loader1, loader2, cache2 doesnt have entry
      assertNull(loader1.get(fqn));
      assertNull(loader2.get(fqn));
      assertNull(cache2.get(fqn, key));

      // commit
      mgr.commit();

      // test that loader1, loader2, cache2 has entry
      assertEquals(value, cache1.get(fqn, key));
      assertEquals(value, loader1.get(fqn).get(key));
      assertEquals(value, loader2.get(fqn).get(key));
      assertEquals(value, cache2.get(fqn, key));

      // cache2 removes entry
      cache2.getTransactionManager().begin();
      cache2.removeNode(fqn);
      assertNull(cache2.get(fqn, key));
      // test that loader1, loader2 and cache2 have the entry
      assertEquals(value, cache1.get(fqn, key));
      assertEquals(value, loader1.get(fqn).get(key));
      assertEquals(value, loader2.get(fqn).get(key));

      // commit
      cache2.getTransactionManager().commit();

      // test that the entry has been removed everywhere.
      assertNull(cache1.getNode(fqn));
      assertNull(loader1.get(fqn));
      assertNull(loader2.get(fqn));
      assertNull(cache2.getNode(fqn));

   }
View Full Code Here

Examples of org.jboss.cache.loader.CacheLoader

   }

   public void testSharedCacheLoadingWithReplication() throws Exception
   {
      CacheSPI<Object, Object> cache1 = createReplicatedCacheWithLoader(true);
      CacheLoader loader1 = cache1.getCacheLoaderManager().getCacheLoader();

      CacheSPI<Object, Object> cache2 = createReplicatedCacheWithLoader(true);
      CacheLoader loader2 = cache2.getCacheLoaderManager().getCacheLoader();

      // test the cache ...
      TransactionManager mgr = cache1.getTransactionManager();
      assertNull(mgr.getTransaction());

      mgr.begin();

      // add something in cache1
      cache1.put(fqn, key, value);
      assertEquals(value, cache1.get(fqn, key));

      // test that loader1, loader2, cache2 doesnt have entry
      System.out.println("*** " + loader1.get(fqn));
      assertNull(loader1.get(fqn));
      assertNull(loader2.get(fqn));
      assertNull(cache2.get(fqn, key));

      // commit
      mgr.commit();

      // test that loader1, loader2, cache2 has entry
      assertEquals(value, cache1.get(fqn, key));
      assertEquals(value, loader1.get(fqn).get(key));
      assertEquals(value, loader2.get(fqn).get(key));
      assertEquals(value, cache2.get(fqn, key));

      // cache2 removes entry
      cache2.getTransactionManager().begin();
      cache2.removeNode(fqn);
      assertNull(cache2.get(fqn, key));
      // test that loader1, loader2 and cache2 have the entry
      assertEquals(value, cache1.get(fqn, key));
      assertEquals(value, loader1.get(fqn).get(key));
      assertEquals(value, loader2.get(fqn).get(key));

      // commit
      cache2.getTransactionManager().commit();

      // test that the entry has been removed everywhere.
      assertNull(cache1.getNode(fqn));
      assertNull(loader1.get(fqn));
      assertNull(loader2.get(fqn));
      assertNull(cache2.getNode(fqn));

   }
View Full Code Here

Examples of org.jboss.cache.loader.CacheLoader

   }

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

      // clean up
      cache.removeNode(fqn);
      loader.remove(fqn);

      assertNull(loader.get(fqn));

      DummyTransactionManager mgr = DummyTransactionManager.getInstance();

      // put something in the cache
      mgr.begin();
      cache.put(fqn, key, value);
      mgr.commit();

      // should be nothing in the loader
      assertEquals(value, cache.get(fqn, key));
      assertNull(loader.get(fqn));

      // evict from cache
      mgr.begin();
      cache.evict(fqn);
      mgr.commit();

      mgr.begin();
      // should now be passivated in the loader
      // don't do a cache.get() first as this will activate this node from the loader again!
      // assertNull( cache.get( fqn ) );
      assertEquals(value, loader.get(fqn).get(key));

      // now do a cache.get()...
      assertEquals(value, cache.get(fqn, key));

      // and the object should now be removed from the loader
      assertNull(loader.get(fqn));
      mgr.commit();

      // clean up
      mgr.begin();
      cache.removeNode(fqn);
      loader.remove(fqn);
      mgr.commit();

   }
View Full Code Here

Examples of org.jboss.cache.loader.CacheLoader

    * Tests the getChildrenNames() method.
    */
   public void testGetChildrenNames()
         throws Exception
   {
      CacheLoader loader = loaderTL.get();

      checkChildren(Fqn.ROOT, null);
      checkChildren(Fqn.fromString("/key0"), null);

      loader.put(Fqn.fromString("/key0"), null);
      addDelay();
      checkChildren(Fqn.ROOT, new String[]{"key0"});

      loader.put(Fqn.fromString("/key1/x"), null);
      addDelay();
      checkChildren(Fqn.ROOT, new String[]{"key0", "key1"});
      checkChildren(Fqn.fromString("/key1"), new String[]{"x"});

      loader.remove(Fqn.fromString("/key1/x"));
      addDelay();
      checkChildren(Fqn.ROOT, new String[]{"key0", "key1"});
      checkChildren(Fqn.fromString("/key0"), null);
      checkChildren(Fqn.fromString("/key1"), null);

      loader.put(Fqn.fromString("/key0/a"), null);
      loader.put(Fqn.fromString("/key0/ab"), null);
      loader.put(Fqn.fromString("/key0/abc"), null);
      addDelay();
      checkChildren(Fqn.fromString("/key0"),
            new String[]{"a", "ab", "abc"});

      loader.put(Fqn.fromString("/key0/xxx"), null);
      loader.put(Fqn.fromString("/key0/xx"), null);
      loader.put(Fqn.fromString("/key0/x"), null);
      addDelay();
      checkChildren(Fqn.fromString("/key0"),
            new String[]{"a", "ab", "abc", "x", "xx", "xxx"});

      loader.put(Fqn.fromString("/key0/a/1"), null);
      loader.put(Fqn.fromString("/key0/a/2"), null);
      loader.put(Fqn.fromString("/key0/a/2/1"), null);
      addDelay();
      checkChildren(Fqn.fromString("/key0/a/2"), new String[]{"1"});
      checkChildren(Fqn.fromString("/key0/a"), new String[]{"1", "2"});
      checkChildren(Fqn.fromString("/key0"),
            new String[]{"a", "ab", "abc", "x", "xx", "xxx"});
View Full Code Here

Examples of org.jboss.cache.loader.CacheLoader

    * Checks that the given list of children part names is returned.
    */
   private void checkChildren(Fqn fqn, String[] names)
         throws Exception
   {
      CacheLoader loader = loaderTL.get();

      Set set = loader.getChildrenNames(fqn);
      if (names != null)
      {
         assertEquals(names.length, set.size());
         for (int i = 0; i < names.length; i += 1)
         {
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.