Package org.jboss.cache.transaction

Examples of org.jboss.cache.transaction.DummyTransactionManager


        nodeInterceptor.setNext(dummy);

        cache.setInterceptorChain(interceptor);

//     first set up a node with a pojo
        DummyTransactionManager mgr = DummyTransactionManager.getInstance();
        mgr.begin();
        Transaction tx = mgr.getTransaction();

        // inject InvocationContext
        cache.getInvocationContext().setTransaction(tx);
        cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));

        SamplePojo pojo = new SamplePojo(21, "test");
        Map temp = new HashMap();
        temp.put("key1", pojo);
        cache.put("/one/two", temp);

        // get the transaction stuff
        TransactionTable table = cache.getTransactionTable();
        GlobalTransaction gtx = table.get(tx);

        OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);

        TransactionWorkspace workspace = entry.getTransactionWorkSpace();

        WorkspaceNode one = workspace.getNode(Fqn.fromString("/one"));

        assertEquals(1, ((Set) one.getMergedChildren().get(0)).size());
        assertEquals(0, ((Set) one.getMergedChildren().get(1)).size());

        cache.remove("/one/two");

        assertNotNull(workspace.getNode(Fqn.fromString("/one/two")));
        assertEquals(true, workspace.getNode(Fqn.fromString("/one/two")).isDeleted());
        assertNotNull(workspace.getNode(Fqn.fromString("/one")));
        assertEquals(false, workspace.getNode(Fqn.fromString("/one")).isDeleted());

        //will still have alink from one to two
        assertEquals(null, workspace.getNode(Fqn.fromString("/one")).getChild("two"));


        assertEquals(null, dummy.getCalled());


        mgr.commit();

        assertEquals(0, ((Set) workspace.getNode(Fqn.fromString("/one")).getMergedChildren().get(0)).size());
        assertEquals(1, ((Set) workspace.getNode(Fqn.fromString("/one")).getMergedChildren().get(1)).size());
        //assert what should be the results of our call
        assertEquals(3, workspace.getNodes().size());
View Full Code Here


        txInterceptor.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");

        cache.put("/one/two", "key1", pojo);
        assertNull(mgr.getTransaction());
        assertEquals(0, cache.getTransactionTable().getNumGlobalTransactions());
        assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());

        //make sure all calls were done in right order
View Full Code Here

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

        cache.setInterceptorChain(txInterceptor);

        DummyTransactionManager mgr = DummyTransactionManager.getInstance();

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

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

        assertNotNull(mgr.getTransaction());
        TransactionTable txTable = cache.getTransactionTable();
        assertNull(txTable.get(tx));

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

        assertNotNull(mgr.getTransaction());
        mgr.commit();

        assertNull(mgr.getTransaction());

        List calls = dummy.getAllCalled();
        assertEquals(MethodDeclarations.optimisticPrepareMethod, calls.get(0));
        assertEquals(MethodDeclarations.commitMethod, calls.get(1));
View Full Code Here

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

        cache.setInterceptorChain(txInterceptor);

        DummyTransactionManager mgr = DummyTransactionManager.getInstance();

        //start local transaction
        mgr.begin();

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

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

        assertNotNull(mgr.getTransaction());
        mgr.rollback();

        assertNull(mgr.getTransaction());

        List calls = dummy.getAllCalled();
        assertEquals(1, calls.size());
        assertEquals(MethodDeclarations.rollbackMethod, calls.get(0));
View Full Code Here

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

        cache.setInterceptorChain(txInterceptor);

        DummyTransactionManager mgr = DummyTransactionManager.getInstance();

        //start local transaction
        mgr.begin();

        assertNotNull(mgr.getTransaction());
        mgr.commit();

        assertNull(mgr.getTransaction());

        List calls = dummy.getAllCalled();
        assertEquals(0, calls.size());

        assertNull(mgr.getTransaction());

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

        cache.stopService();
View Full Code Here

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

        cache.setInterceptorChain(txInterceptor);

        DummyTransactionManager mgr = DummyTransactionManager.getInstance();

        //start local transaction
        mgr.begin();

        assertNotNull(mgr.getTransaction());
        mgr.rollback();

        assertNull(mgr.getTransaction());

        List calls = dummy.getAllCalled();
        assertEquals(0, calls.size());

        assertNull(mgr.getTransaction());

        assertEquals(0, cache.getTransactionTable().getNumGlobalTransactions());
        assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());
        cache.stopService();
View Full Code Here

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

        cache.setInterceptorChain(txInterceptor);

        DummyTransactionManager mgr = DummyTransactionManager.getInstance();

        //start local transaction
        mgr.begin();

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

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

        assertNotNull(mgr.getTransaction());
        mgr.commit();

        assertNull(mgr.getTransaction());

        List calls = dummy.getAllCalled();
        assertEquals(MethodDeclarations.optimisticPrepareMethod, calls.get(0));
        assertEquals(MethodDeclarations.commitMethod, calls.get(1));
        boolean failed = false;
        try
        {
            mgr.rollback();
            fail();
        }
        catch (Exception e)
        {
            e.printStackTrace();
            failed = true;
            assertTrue(true);
        }
        assertTrue(failed);
        assertNull(mgr.getTransaction());
        assertEquals(0, cache.getTransactionTable().getNumGlobalTransactions());
        assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());
        cache.stopService();
    }
View Full Code Here

        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);

        assertNotNull(mgr.getTransaction());
        mgr.commit();

        assertNull(mgr.getTransaction());

        List calls = dummy.getAllCalled();
        assertEquals(MethodDeclarations.optimisticPrepareMethod, calls.get(0));
        assertEquals(MethodDeclarations.commitMethod, calls.get(1));
View Full Code Here

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

        cache.setInterceptorChain(txInterceptor);

        DummyTransactionManager mgr = DummyTransactionManager.getInstance();

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


        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();

        //test local calls
        List calls = dummy.getAllCalled();
        assertEquals(MethodDeclarations.optimisticPrepareMethod, calls.get(0));
        assertEquals(MethodDeclarations.commitMethod, calls.get(1));
        assertNull(mgr.getTransaction());

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


        GlobalTransaction remoteGtx = new GlobalTransaction();

        remoteGtx.setAddress(new Address()
        {
            public boolean isMulticastAddress()
            {

                return false;
            }

            public void readExternal(ObjectInput arg0)
            {
            }

            public void writeExternal(ObjectOutput arg0)
            {
            }

            public int compareTo(Object arg0)
            {

                return 0;
            }

            public int size()
            {

                return 0;
            }

            public void writeTo(DataOutputStream arg0)
            {
            }

            public void readFrom(DataInputStream arg0)
            {
            }
        });
        //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 still be null
        assertNull(mgr.getTransaction());

        //there should be a registration for the remote gtx
        assertNotNull(table.get(remoteGtx));
        assertNotNull(table.getLocalTransaction(remoteGtx));
View Full Code Here

        nodeInterceptor.setNext(dummy);

        cache.setInterceptorChain(interceptor);

//     first set up a node with a pojo
        DummyTransactionManager mgr = DummyTransactionManager.getInstance();
        mgr.begin();
        Transaction tx = mgr.getTransaction();

        // inject InvocationContext
        cache.getInvocationContext().setTransaction(tx);
        cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));

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

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

        assertEquals(null, dummy.getCalled());
        TransactionTable table = cache.getTransactionTable();

        GlobalTransaction gtx = table.get(tx);

        OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);

        TransactionWorkspace workspace = entry.getTransactionWorkSpace();

        //assert we can see this with a key value get in the transaction
        assertEquals(1, cache.getKeys("/one/two").size());
        mgr.commit();

        //assert what should be the results of our call
        assertEquals(3, workspace.getNodes().size());
        assertNotNull(workspace.getNode(Fqn.fromString("/one/two")));
        assertEquals(pojo, workspace.getNode(Fqn.fromString("/one/two")).get("key1"));
        assertTrue(entry.getLocks().isEmpty());
        assertEquals(1, entry.getModifications().size());
        assertTrue(!cache.exists("/one/two"));
        assertEquals(null, dummy.getCalled());

        //assert that we cannot see the change if we have not put it into the cache
        // we need to do this as we do not have the tx interceptor in this stack
        mgr.begin();

        Transaction tx2 = mgr.getTransaction();

        // inject InvocationContext
        cache.getInvocationContext().setTransaction(tx2);
        cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx2));

        assertNull(cache.get("/one/two", "key1"));
        mgr.commit();
        cache.stopService();
    }
View Full Code Here

TOP

Related Classes of org.jboss.cache.transaction.DummyTransactionManager

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.