Package org.jboss.cache.loader

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


   }

   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


   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

   }

   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

   }

   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

   }

   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

    * 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

    * 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

    * Tests modifications.
    */
   private void doTestModifications()
         throws Exception
   {
      CacheLoader loader = loaderTL.get();

      /* PUT_KEY_VALUE, PUT_DATA */
      List<Modification> list = createUpdates();
      loader.put(list);
      addDelay();
      checkModifications(list);

      /* REMOVE_KEY_VALUE */
      list = new ArrayList<Modification>();
      Modification mod = new Modification();
      mod.setType(Modification.ModificationType.REMOVE_KEY_VALUE);
      mod.setFqn(FQN);
      mod.setKey("one");
      list.add(mod);
      loader.put(list);
      addDelay();
      checkModifications(list);

      /* REMOVE_NODE */
      list = new ArrayList<Modification>();
      mod = new Modification();
      mod.setType(Modification.ModificationType.REMOVE_NODE);
      mod.setFqn(FQN);
      list.add(mod);
      loader.put(list);
      addDelay();
      checkModifications(list);
      assertEquals(null, loader.get(FQN));

      /* REMOVE_DATA */
      loader.put(FQN, "one", "two");
      list = new ArrayList<Modification>();
      mod = new Modification();
      mod.setType(Modification.ModificationType.REMOVE_DATA);
      mod.setFqn(FQN);
      list.add(mod);
      loader.put(list);
      addDelay();
      checkModifications(list);
   }
View Full Code Here

    * Tests a one-phase transaction.
    */
   public void testOnePhaseTransaction()
         throws Exception
   {
      CacheLoader loader = loaderTL.get();

      List<Modification> mods = createUpdates();
      loader.prepare(null, mods, true);
      checkModifications(mods);
   }
View Full Code Here

TOP

Related Classes of org.jboss.cache.loader.CacheLoader

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.