Examples of TreeCache


Examples of org.jboss.cache.TreeCache

    public void testDisabledConfig() throws Exception
    {
        String xmlConfig = "<config><buddyReplicationEnabled>false</buddyReplicationEnabled></config>";
        Element config = XmlHelper.stringToElement(xmlConfig);
        TreeCache cache = new TreeCache();
        cache.setBuddyReplicationConfig(config);
        assertNull(cache.getBuddyManager());
    }
View Full Code Here

Examples of org.jboss.cache.TreeCache



    public void testPessimisticNonTransactionalAsync() throws Exception
    {
        TreeCache cache1 = createUnstartedCache( false );
        TreeCache cache2 = createUnstartedCache( false );
        cache1.setCacheMode(TreeCache.INVALIDATION_ASYNC);
        cache2.setCacheMode(TreeCache.INVALIDATION_ASYNC);
        cache1.startService();
        cache2.startService();

        Fqn fqn = Fqn.fromString("/a/b");
        cache1.put(fqn, "key", "value");
        TestingUtil.sleepThread(500)// give it time to broadcast the evict call
        // test that this has NOT replicated, but rather has been invalidated:
        Assert.assertEquals("value", cache1.get(fqn, "key"));
        Assert.assertNull("Should NOT have replicated!", cache2.get(fqn));

        log.info("***** Node not replicated, as expected.");

        // now make sure cache2 is in sync with cache1:
        cache2.put(fqn, "key", "value");
        TestingUtil.sleepThread(500)// give it time to broadcast the evict call
        Assert.assertNull("Should be null", cache1.get(fqn));
        Assert.assertEquals("value", cache2.get(fqn, "key"));

        // now test the invalidation:
        cache1.put(fqn, "key2", "value2");
        Assert.assertEquals("value2", cache1.get(fqn, "key2"));
        TestingUtil.sleepThread(500)// give it time to broadcast the evict call
        Assert.assertNull("Should have been invalidated!", cache2.get(fqn));

        // clean up.
        cache1.stopService();
        cache2.stopService();
        cache1 = null;
        cache2 = null;
    }
View Full Code Here

Examples of org.jboss.cache.TreeCache

    public void testBasicConfig() throws Exception
    {
        String xmlConfig = "<config><buddyReplicationEnabled>true</buddyReplicationEnabled></config>";
        Element config = XmlHelper.stringToElement(xmlConfig);
        TreeCache cache = new TreeCache();
        cache.setBuddyReplicationConfig(config);
        assertNotNull(cache.getBuddyManager());
        BuddyManager mgr = cache.getBuddyManager();
        assertTrue(mgr.isEnabled());
        assertNull(mgr.getBuddyPoolName());
        assertEquals(NextMemberBuddyLocator.class, mgr.buddyLocator.getClass());
        assertEquals(1, ((NextMemberBuddyLocator)mgr.buddyLocator).numBuddies);
        assertTrue(((NextMemberBuddyLocator)mgr.buddyLocator).ignoreColocatedBuddies);
View Full Code Here

Examples of org.jboss.cache.TreeCache

        assertTrue(((NextMemberBuddyLocator)mgr.buddyLocator).ignoreColocatedBuddies);
    }

    public void testXmlConfig() throws Exception
    {
        TreeCache cache = new TreeCache();
        PropertyConfigurator pc = new PropertyConfigurator();
        pc.configure(cache, "META-INF/buddyreplication-service.xml");
        cache.createService();

        BuddyManager bm = cache.getBuddyManager();
        assertNotNull(bm);
        assertTrue(bm.isEnabled());
        assertTrue(bm.buddyLocator instanceof NextMemberBuddyLocator);
        NextMemberBuddyLocator bl = (NextMemberBuddyLocator) bm.buddyLocator;
        assertTrue(bl.ignoreColocatedBuddies);
        assertEquals(1, bl.numBuddies);
        assertEquals("myBuddyPoolReplicationGroup", bm.buddyPoolName);
        assertEquals(2000, bm.buddyCommunicationTimeout);

        // test Data Gravitator
        Iterator i = cache.getInterceptors().iterator();

        boolean hasDG = false;
        while (i.hasNext())
        {
            Object o = i.next();
View Full Code Here

Examples of org.jboss.cache.TreeCache

    }


    public void testPessimisticTransactional() throws Exception
    {
        TreeCache cache1 = createCache(false);
        TreeCache cache2 = createCache(false);

        Fqn fqn = Fqn.fromString("/a/b");
        cache1.put(fqn, "key", "value");

        // test that this has NOT replicated, but rather has been invalidated:
        Assert.assertEquals("value", cache1.get(fqn, "key"));
        Assert.assertNull("Should NOT have replicated!", cache2.get(fqn));

        log.info("***** Node not replicated, as expected.");

        // now make sure cache2 is in sync with cache1:
        // make sure this is in a tx
        TransactionManager txm = cache2.getTransactionManager();
        Assert.assertEquals("value", cache1.get(fqn, "key"));

        txm.begin();
        cache2.put(fqn, "key", "value");
        Assert.assertEquals("value", cache2.get(fqn, "key"));
        txm.commit();

        Assert.assertNull("Should be null", cache1.get(fqn));
        Assert.assertEquals("value", cache2.get(fqn, "key"));

        // now test the invalidation again
        txm = cache1.getTransactionManager();
        Assert.assertEquals("value", cache2.get(fqn, "key"));

        txm.begin();
        cache1.put(fqn, "key2", "value2");
        Assert.assertEquals("value2", cache1.get(fqn, "key2"));
        txm.commit();

        Assert.assertEquals("value2", cache1.get(fqn, "key2"));
        Assert.assertNull("Should have been invalidated!", cache2.get(fqn));

        // test a rollback
        txm = cache2.getTransactionManager();
        Assert.assertEquals("value2", cache1.get(fqn, "key2"));

        txm.begin();
        cache2.put(fqn, "key", "value");
        Assert.assertEquals("value", cache2.get(fqn, "key"));
        txm.rollback();

        Assert.assertEquals("value2", cache1.get(fqn, "key2"));
        Assert.assertNull("Should not have committed", cache2.get(fqn));

        // clean up.
        cache1.stopService();
        cache2.stopService();
        cache1 = null;
        cache2 = null;

    }
View Full Code Here

Examples of org.jboss.cache.TreeCache

   }

   void initCaches(int caching_mode) throws Exception
   {
      cachingMode_ = caching_mode;
      cache_ = new TreeCache();
      PropertyConfigurator config = new PropertyConfigurator();
      config.configure(cache_, "META-INF/replAsync-service.xml"); // read in generic replAsync xml
      cache_.setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
      cache_.startService();
   }
View Full Code Here

Examples of org.jboss.cache.TreeCache

    }


    public void testOptSyncUnableToEvict() throws Exception
    {
        TreeCache cache1 = createCache(true);
        TreeCache cache2 = createCache(true);

        Fqn fqn = Fqn.fromString("/a/b");

        cache2.put(fqn, "key", "value");
        Assert.assertEquals("value", cache2.get(fqn, "key"));
        Assert.assertNull(cache1.get(fqn));

        // start a tx that cache1 will have to send out an evict ...
        TransactionManager mgr1 = cache1.getTransactionManager();
        TransactionManager mgr2 = cache2.getTransactionManager();

        mgr1.begin();
        cache1.put(fqn, "key2", "value2");
        Transaction tx1 = mgr1.suspend();
        mgr2.begin();
        cache2.put(fqn, "key3", "value3");
        Transaction tx2 = mgr2.suspend();
        mgr1.resume(tx1);
        // this oughtta fail
        try
        {
            mgr1.commit();
            Assert.assertTrue("Ought to have succeeded!", true);
        }
        catch (RollbackException roll)
        {
            Assert.assertTrue("Ought to have succeeded!", false);
        }

        mgr2.resume(tx2);
        try
        {
            mgr2.commit();
            Assert.assertTrue("Ought to have failed!", false);
        }
        catch (RollbackException roll)
        {
            Assert.assertTrue("Ought to have failed!", true);
        }
        // clean up.
        cache1.stopService();
        cache2.stopService();
        cache1 = null;
        cache2 = null;
    }
View Full Code Here

Examples of org.jboss.cache.TreeCache

        cache2 = null;
    }

    public void testPessTxSyncUnableToEvict() throws Exception
    {
        TreeCache cache1 = createCache(false);
        TreeCache cache2 = createCache(false);

        Fqn fqn = Fqn.fromString("/a/b");

        cache1.put("/a/b", "key", "value");
        Assert.assertEquals("value", cache1.get(fqn, "key"));
        Assert.assertNull(cache2.get(fqn));

        // start a tx that cacahe1 will have to send out an evict ...
        TransactionManager mgr1 = cache1.getTransactionManager();
        TransactionManager mgr2 = cache2.getTransactionManager();

        mgr1.begin();
        cache1.put(fqn, "key2", "value2");
        Transaction tx1 = mgr1.suspend();
        mgr2.begin();
        cache2.put(fqn, "key3", "value3");
        Transaction tx2 = mgr2.suspend();
        mgr1.resume(tx1);
        // this oughtta fail
        try
        {
            mgr1.commit();
            Assert.assertTrue("Ought to have failed!", false);
        }
        catch (RollbackException roll)
        {
            Assert.assertTrue("Ought to have failed!", true);
        }

        mgr2.resume(tx2);
        try
        {
            mgr2.commit();
            Assert.assertTrue("Ought to have succeeded!", true);
        }
        catch (RollbackException roll)
        {
            Assert.assertTrue("Ought to have succeeded!", false);
        }
        // clean up.
        cache1.stopService();
        cache2.stopService();
        cache1 = null;
        cache2 = null;
    }
View Full Code Here

Examples of org.jboss.cache.TreeCache

        cache2 = null;
    }

    public void testPessTxAsyncUnableToEvict() throws Exception
    {
        TreeCache cache1 = createUnstartedCache(false);
        TreeCache cache2 = createUnstartedCache(false);
        cache1.setCacheMode(TreeCache.INVALIDATION_ASYNC);
        cache2.setCacheMode(TreeCache.INVALIDATION_ASYNC);
        cache1.startService();
        cache2.startService();

        Fqn fqn = Fqn.fromString("/a/b");

        cache1.put("/a/b", "key", "value");
        Assert.assertEquals("value", cache1.get(fqn, "key"));
        Assert.assertNull(cache2.get(fqn));

        // start a tx that cacahe1 will have to send out an evict ...
        TransactionManager mgr1 = cache1.getTransactionManager();
        TransactionManager mgr2 = cache2.getTransactionManager();

        mgr1.begin();
        cache1.put(fqn, "key2", "value2");
        Transaction tx1 = mgr1.suspend();
        mgr2.begin();
        cache2.put(fqn, "key3", "value3");
        Transaction tx2 = mgr2.suspend();
        mgr1.resume(tx1);
        // this oughtta fail
        try
        {
            mgr1.commit();
            Assert.assertTrue("Ought to have succeeded!", true);
        }
        catch (RollbackException roll)
        {
            Assert.assertTrue("Ought to have succeeded!", false);
        }

        mgr2.resume(tx2);
        try
        {
            mgr2.commit();
            Assert.assertTrue("Ought to have succeeded!", true);
        }
        catch (RollbackException roll)
        {
            Assert.assertTrue("Ought to have succeeded!", false);
        }
        // clean up.
        cache1.stopService();
        cache2.stopService();
        cache1 = null;
        cache2 = null;
    }
View Full Code Here

Examples of org.jboss.cache.TreeCache

    public void testNoTransactionCRUDMethod() throws Exception
    {

        TestListener listener = new TestListener();
        final TreeCache cache = createCacheWithListener(listener);

        Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
        interceptor.setCache(cache);
        Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
        nodeInterceptor.setCache(cache);
        MockInterceptor dummy = new MockInterceptor();
        dummy.setCache(cache);

        interceptor.setNext(nodeInterceptor);
        nodeInterceptor.setNext(dummy);

        cache.setInterceptorChain(interceptor);

        try
        {
            cache.put("/one/two", "key1", new Object());
            fail();
        }
        catch (Throwable t)
        {

            assertTrue(true);
        }
        assertEquals(null, dummy.getCalled());
        cache.stopService();
    }
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.