Package org.jboss.cache

Examples of org.jboss.cache.TreeCache$MessageListenerAdaptor


        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


    }


    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

   }

   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

    }


    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

        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

        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

    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

    public void testNoTransactionGetMethod() 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);

        boolean fail = false;
        try
        {
            assertEquals(null, cache.get("/one/two", "key1"));
        }
        catch (Exception e)
        {
            fail = true;
        }
        assertTrue(fail);
        assertEquals(null, dummy.getCalled());
        cache.stopService();
    }
View Full Code Here

    }


    public void testExplicitTxFailure() throws Exception
    {
        final TreeCache c = createCache();

        // explicit.
        TransactionManager mgr = c.getTransactionManager();
        try
        {
            mgr.begin();
            c.put("/a", "k", "v");
            Transaction t = mgr.suspend();
            c.put("/a", "k2", "v2");
            mgr.resume(t);
            mgr.commit();
            Assert.assertTrue("Expecting a rollback exception!", false);
        }
        catch (RollbackException re)
        {
            Assert.assertTrue("Expecting a rollback exception!", true);
        }
        c.stopService();
    }
View Full Code Here

        c.stopService();
    }

    public void testImplicitTxFailure() throws Exception
    {
        final TreeCache c = createCache();

        // implicit (much harder to orchestrate...
        int numThreads = 50;
        ExceptionThread thread[] = new ExceptionThread[numThreads];

        for (int i = 0; i < numThreads; i++)
        {
            thread[i] = new ExceptionThread()
            {
                public void run()
                {
                    try
                    {
                        c.put("/a", "k", "v");
                    }
                    catch (Exception e)
                    {
                        log.fatal("*** Thew an exception!!", e);
                        setException(e);
                    }
                }
            };
        }

        for (int i = 0; i < numThreads; i++) thread[i].start();
        for (int i = 0; i < numThreads; i++) thread[i].join();
        // test exceptions.
        for (int i = 0; i < numThreads; i++)
        {
            Assert.assertNull("Thread " + thread[i].getName() + " threw exception!", thread[i].getException());
        }
        c.stopService();
    }
View Full Code Here

TOP

Related Classes of org.jboss.cache.TreeCache$MessageListenerAdaptor

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.