Examples of TreeCache


Examples of org.jboss.cache.TreeCache

    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

Examples of org.jboss.cache.TreeCache

    }


    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

Examples of org.jboss.cache.TreeCache

        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

Examples of org.jboss.cache.TreeCache

    }

    public void testLocalTransaction() throws Exception
    {

        TreeCache cache = createCacheWithListener();

        Interceptor txInterceptor = new TxInterceptor();
        txInterceptor.setCache(cache);
        Interceptor replicationInterceptor = new OptimisticReplicationInterceptor();
        replicationInterceptor.setCache(cache);
        Interceptor createInterceptor = new OptimisticCreateIfNotExistsInterceptor();
        createInterceptor.setCache(cache);
        Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
        nodeInterceptor.setCache(cache);
        MockInterceptor dummy = new MockInterceptor();
        dummy.setCache(cache);

        txInterceptor.setNext(replicationInterceptor);
        replicationInterceptor.setNext(createInterceptor);
        createInterceptor.setNext(nodeInterceptor);
        nodeInterceptor.setNext(dummy);

        cache.setInterceptorChain(txInterceptor);

        DummyTransactionManager mgr = DummyTransactionManager.getInstance();
        assertNull(mgr.getTransaction());

        mgr.begin();

        assertEquals(0, cache.getTransactionTable().getNumGlobalTransactions());
        assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());

        SamplePojo pojo = new SamplePojo(21, "test");

        cache.put("/one/two", "key1", pojo);

        mgr.commit();

        assertNull(mgr.getTransaction());
        assertEquals(0, cache.getTransactionTable().getNumGlobalTransactions());
        assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());

        //make sure all calls were done in right order

        List calls = dummy.getAllCalled();
View Full Code Here

Examples of org.jboss.cache.TreeCache

    }

    public void testRollbackTransaction() throws Exception
    {

        TreeCache cache = createCacheWithListener();

        Interceptor txInterceptor = new TxInterceptor();
        txInterceptor.setCache(cache);
        Interceptor replicationInterceptor = new OptimisticReplicationInterceptor();
        replicationInterceptor.setCache(cache);
        Interceptor createInterceptor = new OptimisticCreateIfNotExistsInterceptor();
        createInterceptor.setCache(cache);
        Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
        nodeInterceptor.setCache(cache);
        MockInterceptor dummy = new MockInterceptor();
        dummy.setCache(cache);

        txInterceptor.setNext(replicationInterceptor);
        replicationInterceptor.setNext(createInterceptor);
        createInterceptor.setNext(nodeInterceptor);
        nodeInterceptor.setNext(dummy);
        cache.setInterceptorChain(txInterceptor);

        DummyTransactionManager mgr = DummyTransactionManager.getInstance();
        assertNull(mgr.getTransaction());
        assertEquals(0, cache.getTransactionTable().getNumGlobalTransactions());
        assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());

        SamplePojo pojo = new SamplePojo(21, "test");
        mgr.begin();
        cache.put("/one/two", "key1", pojo);
        mgr.rollback();
        assertNull(mgr.getTransaction());
        assertEquals(0, cache.getTransactionTable().getNumGlobalTransactions());
        assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());

        //make sure all calls were done in right order

        List calls = dummy.getAllCalled();
View Full Code Here

Examples of org.jboss.cache.TreeCache

    }

    public void testRemotePrepareTransaction() throws Exception
    {

        TreeCache cache = createCacheWithListener();

        Interceptor txInterceptor = new TxInterceptor();
        txInterceptor.setCache(cache);
        Interceptor replicationInterceptor = new OptimisticReplicationInterceptor();
        replicationInterceptor.setCache(cache);
        Interceptor createInterceptor = new OptimisticCreateIfNotExistsInterceptor();
        createInterceptor.setCache(cache);
        Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
        nodeInterceptor.setCache(cache);
        MockInterceptor dummy = new MockInterceptor();
        dummy.setCache(cache);

        txInterceptor.setNext(replicationInterceptor);
        replicationInterceptor.setNext(createInterceptor);
        createInterceptor.setNext(nodeInterceptor);
        nodeInterceptor.setNext(dummy);

        cache.setInterceptorChain(txInterceptor);
        DummyTransactionManager mgr = DummyTransactionManager.getInstance();

        //start local transaction
        mgr.begin();
        Transaction tx = mgr.getTransaction();

        //this sets
        cache.getCurrentTransaction(tx);

        SamplePojo pojo = new SamplePojo(21, "test");

        cache.put("/one/two", "key1", pojo);

        GlobalTransaction gtx = cache.getCurrentTransaction(tx);
        TransactionTable table = cache.getTransactionTable();
        OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
        assertNotNull(mgr.getTransaction());
        mgr.commit();


        GlobalTransaction remoteGtx = new GlobalTransaction();

        remoteGtx.setAddress(new Address()
        {

            public int compareTo(Object arg0)
            {
                return 0;
            }

            public void readFrom(DataInputStream arg0) throws IOException,
                    IllegalAccessException, InstantiationException
            {

            }

            public void writeTo(DataOutputStream arg0) throws IOException
            {

            }

            public void readExternal(ObjectInput arg0) throws IOException,
                    ClassNotFoundException
            {

            }

            public void writeExternal(ObjectOutput arg0) throws IOException
            {

            }

            public int size()
            {
                return 0;
            }

            public boolean isMulticastAddress()
            {
                return false;
            }

        });
        //hack the method call to make it have the remote gtx
        MethodCall meth = (MethodCall) entry.getModifications().get(0);

        meth.getArgs()[0] = remoteGtx;
        //call our remote method
        MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, new Object[]{remoteGtx, injectDataVersion(entry.getModifications()), null, remoteGtx.getAddress(), Boolean.FALSE});
        try
        {
            cache._replicate(prepareMethod);
        }
        catch (Throwable t)
        {
            fail();
        }

        //our thread should be null
        assertNull(mgr.getTransaction());

        //   there should be a registration for the remote gtx
        assertNotNull(table.get(remoteGtx));
        assertNotNull(table.getLocalTransaction(remoteGtx));
        //assert that this is populated
        assertEquals(1, table.get(remoteGtx).getModifications().size());

        //assert that the remote prepare has populated the local workspace
        OptimisticTransactionEntry opEntry = (OptimisticTransactionEntry) table.get(gtx);

        assertEquals(3, entry.getTransactionWorkSpace().getNodes().size());
        assertEquals(1, entry.getModifications().size());
        List calls = dummy.getAllCalled();
        assertEquals(MethodDeclarations.optimisticPrepareMethod, calls.get(2));

        assertEquals(1, cache.getTransactionTable().getNumGlobalTransactions());
        assertEquals(1, cache.getTransactionTable().getNumLocalTransactions());
        destroyCache(cache);

    }
View Full Code Here

Examples of org.jboss.cache.TreeCache

    }
   public void testRemoteCacheBroadcast() throws Exception
    {


        TreeCache cache = createReplicatedCache(TreeCache.REPL_SYNC);
        TreeCache cache2 = createReplicatedCache(TreeCache.REPL_SYNC);

        DummyTransactionManager mgr = DummyTransactionManager.getInstance();

        //start local transaction
        mgr.begin();
        Transaction tx = mgr.getTransaction();

        //this sets
        GlobalTransaction gtx = cache.getCurrentTransaction(tx);

        SamplePojo pojo = new SamplePojo(21, "test");

        cache.put("/one/two", "key1", pojo);

        //GlobalTransaction gtx = cache.getCurrentTransaction(tx);
        TransactionTable table = cache.getTransactionTable();
        assertNotNull(mgr.getTransaction());
        mgr.commit();


        assertNull(mgr.getTransaction());

        //assert that the local cache is in the right state
        assertEquals(0, cache.getTransactionTable().getNumGlobalTransactions());
        assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());

        assertTrue(cache.exists(Fqn.fromString("/one/two")));
        assertTrue(cache.exists(Fqn.fromString("/one")));
        assertEquals(pojo, cache.get(Fqn.fromString("/one/two"), "key1"));

        assertEquals(0, cache2.getTransactionTable().getNumGlobalTransactions());
        assertEquals(0, cache2.getTransactionTable().getNumLocalTransactions());

        assertTrue(cache2.exists(Fqn.fromString("/one/two")));
        assertTrue(cache2.exists(Fqn.fromString("/one")));
        assertEquals(pojo, cache2.get(Fqn.fromString("/one/two"), "key1"));


        destroyCache(cache);
        destroyCache(cache2);
    }
View Full Code Here

Examples of org.jboss.cache.TreeCache

    public void testTwoWayRemoteCacheBroadcast() throws Exception
    {


        TreeCache cache = createReplicatedCache(TreeCache.REPL_SYNC);
        TreeCache cache2 = createReplicatedCache(TreeCache.REPL_SYNC);

        DummyTransactionManager mgr = DummyTransactionManager.getInstance();

        //start local transaction
        mgr.begin();
        Transaction tx = mgr.getTransaction();

        //this sets
        cache.getCurrentTransaction(tx);

        SamplePojo pojo = new SamplePojo(21, "test");

        cache.put("/one/two", "key1", pojo);

        GlobalTransaction gtx = cache.getCurrentTransaction(tx);
        TransactionTable table = cache.getTransactionTable();
        assertNotNull(mgr.getTransaction());
        mgr.commit();


        assertNull(mgr.getTransaction());

        //assert that the local cache is in the right state
        assertEquals(0, cache.getTransactionTable().getNumGlobalTransactions());
        assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());

        assertTrue(cache.exists(Fqn.fromString("/one/two")));
        assertTrue(cache.exists(Fqn.fromString("/one")));
        assertEquals(pojo, cache.get(Fqn.fromString("/one/two"), "key1"));


        assertEquals(0, cache2.getTransactionTable().getNumGlobalTransactions());
        assertEquals(0, cache2.getTransactionTable().getNumLocalTransactions());

        assertTrue(cache2.exists(Fqn.fromString("/one/two")));
        assertTrue(cache2.exists(Fqn.fromString("/one")));

        assertEquals(pojo, cache2.get(Fqn.fromString("/one/two"), "key1"));


        destroyCache(cache);
        destroyCache(cache2);
View Full Code Here

Examples of org.jboss.cache.TreeCache

    final int numThreadsPerTopLevelNode = 5; // we'll have 5 requests for nodes within a branch


    public void testBlockingProblem() throws Exception {

        TreeCache cache = new TreeCache();
        cache.setCacheLoader(new TestSlowCacheLoader());
        cache.startService();

        long begin = System.currentTimeMillis();
        Collection threads = new ArrayList();

        /*
 
View Full Code Here

Examples of org.jboss.cache.TreeCache

    protected void setUp() throws Exception
    {
        if (cache1 != null || cache2 != null) tearDown();

        // set up 2 instances of TreeCache with shared CacheLoaders.
        cache1 = new TreeCache();
        cache2 = new TreeCache();

        cache1.setCacheMode(TreeCache.REPL_SYNC);
        cache2.setCacheMode(TreeCache.REPL_SYNC);

        cache1.setCacheLoaderConfiguration(getSingleCacheLoaderConfig("", DummyCacheLoader.class.getName(), "", false, false, true));
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.