Package org.jboss.cache

Examples of org.jboss.cache.TreeCache$MessageListenerAdaptor


    }

    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


    }

    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

    }

    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

    }
   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

    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

    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

    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

      }
   }

   private void createCache(IsolationLevel level) throws Exception
   {
      cache = new TreeCache();
      PropertyConfigurator config = new PropertyConfigurator();
      config.configure(cache, "META-INF/local-service.xml");

      cache.setCacheMode(TreeCache.LOCAL);
      cache.setIsolationLevel(level);
View Full Code Here

        m_contextFactory = System.getProperty(Context.INITIAL_CONTEXT_FACTORY);
        System.setProperty(Context.INITIAL_CONTEXT_FACTORY, CONTEXT_FACTORY);
        DummyTransactionManager.getInstance();
        PropertyConfigurator config = new PropertyConfigurator();
        // setup and start the source cache
        m_srcCache = new TreeCache();
        config.configure(m_srcCache, "META-INF/replSync-service.xml");
        m_srcCache.setTransactionManagerLookupClass(
                "org.jboss.cache.DummyTransactionManagerLookup");
        m_srcCache.setCacheMode(TreeCache.REPL_SYNC);

        m_srcCache.setSyncCommitPhase(true);
        m_srcCache.createService();
        m_srcCache.startService();
        // setup and start the destination cache
        m_dstCache = new TreeCache();
        config.configure(m_dstCache, "META-INF/replSync-service.xml");
        m_dstCache.setTransactionManagerLookupClass(
                "org.jboss.cache.DummyTransactionManagerLookup");
        m_dstCache.setCacheMode(TreeCache.REPL_SYNC);
View Full Code Here

        log.debug("Using location for CL 2 : " + tmpLocation2);
    }

    public void setUp() throws Exception
    {
        cache1 = new TreeCache();
        cache1.setCacheLoaderConfiguration(getSingleCacheLoaderConfig("", "org.jboss.cache.loader.bdbje.BdbjeCacheLoader", "location=" + tmpLocation1, false, true, false));
        cache1.setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");

        cache2 = new TreeCache();
        cache2.setCacheLoaderConfiguration(getSingleCacheLoaderConfig("", "org.jboss.cache.loader.bdbje.BdbjeCacheLoader", "location=" + tmpLocation2, false, true, false));
        cache2.setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
    }
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.