Package org.jboss.cache.transaction

Examples of org.jboss.cache.transaction.DummyTransactionManager


    public void testTxRollbackThroughConcurrentWrite() throws Exception
    {
        TreeCache cache = createCacheWithListener();
        Set keys;

        DummyTransactionManager mgr = DummyTransactionManager.getInstance();
        if (mgr.getTransaction() != null) mgr.rollback();
        assertNull(mgr.getTransaction());

        // first put in a value
        mgr.begin();
        assertEquals(0, cache.getTransactionTable().getNumGlobalTransactions());
        assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());
        cache.put("/one/two", "key1", "val1");
        mgr.commit();
        keys = cache.getKeys("/one/two");
        System.out.println("keys after TX #1: " + keys);
        assertEquals(1, keys.size());

        // First TX
        mgr.begin();
        Transaction tx = mgr.getTransaction();
        cache.put("/one/two", "key2", "val2"); // version for this is 1

        // start another
        mgr.suspend();

        // Second TX
        mgr.begin();
        cache.put("/one/two", "key3", "val3");
        mgr.commit(); // now version is 2, attrs are key1 and key3

        // assert we can see this outside the existing tx
        keys = cache.getKeys("/one/two");
        System.out.println("keys after TX #3 committed: " + keys);
        assertEquals(2, keys.size());

        // resume the suspended one
        mgr.resume(tx);
        // assert we can't see the change from tx2 as we already touched the node
        keys = cache.getKeys("/one/two");
        System.out.println("keys after TX #2 resumed (in private workspace of TX #2): " + keys);
        assertEquals(2, keys.size()); // we will see key1 and key2, but *not* key3

        // this will fail as our workspace has version 1, whereas cache has 2; TX will be rolled back
        try
        {
            mgr.commit();
            fail("TX should fail as other TX incremented version number");
        }
        catch (RollbackException rollback_ex)
        {
            System.out.println("TX was rolled back because the other TX committed first and incremented version ID." +
View Full Code Here


    public void testPuts() throws Exception
    {
        TreeCache cache = createCache();
        Transaction tx;

        DummyTransactionManager mgr = DummyTransactionManager.getInstance();
        Assert.assertNull(cache.get(fqn));

        mgr.begin();
        cache.put(fqn, key, value);
        Assert.assertEquals(value, cache.get(fqn, key));
        tx = mgr.getTransaction();
        mgr.suspend();

        mgr.begin();
        Assert.assertNull(cache.get(fqn, key));
        mgr.commit();

        mgr.resume(tx);
        Assert.assertEquals(value, cache.get(fqn, key));
        mgr.commit();

        Assert.assertEquals(value, cache.get(fqn, key));

    }
View Full Code Here

    public void testRemoves() throws Exception
    {
        TreeCache cache = createCache();
        Transaction tx;

        DummyTransactionManager mgr = DummyTransactionManager.getInstance();
        Assert.assertNull(cache.get(fqn));
        cache.put(fqn, key, value);
        Assert.assertEquals(value, cache.get(fqn, key));

        mgr.begin();
        Assert.assertEquals(value, cache.get(fqn, key));
        cache.remove(fqn);
        Assert.assertNull(cache.get(fqn));
        tx = mgr.getTransaction();
        mgr.suspend();

        mgr.begin();
        Assert.assertEquals(value, cache.get(fqn, key));
        mgr.commit();

        mgr.resume(tx);
        Assert.assertNull(cache.get(fqn));
        mgr.commit();

        Assert.assertNull(cache.get(fqn));
    }
View Full Code Here

    public void testRemovesBeforeGet() throws Exception
    {
        TreeCache cache = createCache();
        Transaction tx;

        DummyTransactionManager mgr = DummyTransactionManager.getInstance();
        Assert.assertNull(cache.get(fqn));
        cache.put(fqn, key, value);
        Assert.assertEquals(value, cache.get(fqn, key));

        mgr.begin();
        cache.remove(fqn);
        Assert.assertNull(cache.get(fqn));
        tx = mgr.getTransaction();
        mgr.suspend();

        mgr.begin();
        Assert.assertEquals(value, cache.get(fqn, key));
        mgr.commit();

        mgr.resume(tx);
        Assert.assertNull(cache.get(fqn));
        mgr.commit();

        Assert.assertNull(cache.get(fqn));
    }
View Full Code Here

        {
            log.debug("Starting test");
            TreeCache cache1 = createSyncReplicatedCache();
            TreeCache cache2 = createSyncReplicatedCache();
            log.debug("Created caches");
            DummyTransactionManager mgr = DummyTransactionManager.getInstance();

            int numLoops = 5, numPuts = 5;


            log.debug("Starting " + numLoops + " loops");
            for (int i = 0; i < numLoops; i++)
            {
                log.debug(" *** in loop " + i);
                mgr.begin();
                for (int j = 0; j < numPuts; j++)
                {
                    cache1.put(Fqn.fromString("/profiler/node" + i), "key" + j, "value" + j);
                }
                log.debug("*** >> Out of put loop");
                mgr.commit();
                //cache2.get(Fqn.fromString("/profiler/node" + i));
            }

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

        nodeInterceptor.setNext(dummy);

        cache.setInterceptorChain(validateInterceptor);

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

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

        GlobalTransaction gtx = table.get(tx);

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

        TransactionWorkspace workspace = entry.getTransactionWorkSpace();

        /*GlobalTransaction.class,
        List.class,
        Address.class,
        boolean.class*/

        assertEquals(3, workspace.getNodes().size());
        assertNotNull(workspace.getNode(Fqn.fromString("/one/two")));
        assertEquals(pojo, workspace.getNode(Fqn.fromString("/one/two")).get("key1"));
        assertEquals(1, workspace.getNode(Fqn.fromString("/one/two")).getMergedData().size());
        assertTrue(entry.getLocks().isEmpty());
        assertEquals(1, entry.getModifications().size());
        assertTrue(!cache.exists("/one/two"));
        assertEquals(null, dummy.getCalled());

        //now let us do a prepare
        MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, new Object[]{gtx, entry.getModifications(), gtx.getAddress(), Boolean.FALSE});
        try
        {
            cache._replicate(prepareMethod);
        }
        catch (Throwable t)
        {

        }


        assertEquals(3, workspace.getNodes().size());
        assertNotNull(workspace.getNode(Fqn.fromString("/one/two")));
        assertEquals(pojo, workspace.getNode(Fqn.fromString("/one/two")).get("key1"));
        assertEquals(1, workspace.getNode(Fqn.fromString("/one/two")).getMergedData().size());
        assertTrue(entry.getLocks().isEmpty());
        assertEquals(1, entry.getModifications().size());
        assertTrue(!cache.exists("/one/two"));
        assertEquals(null, dummy.getCalled());


        mgr.commit();

        destroyCache(cache);
    }
View Full Code Here

        nodeInterceptor.setNext(dummy);

        cache.setInterceptorChain(validateInterceptor);

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

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

        GlobalTransaction gtx = table.get(tx);

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

        TransactionWorkspace workspace = entry.getTransactionWorkSpace();

        /*GlobalTransaction.class,
List.class,
Address.class,
boolean.class*/

        assertEquals(3, workspace.getNodes().size());
        assertNotNull(workspace.getNode(Fqn.fromString("/one/two")));
        assertEquals(pojo, workspace.getNode(Fqn.fromString("/one/two")).get("key1"));
        assertEquals(1, workspace.getNode(Fqn.fromString("/one/two")).getMergedData().size());
        assertTrue(entry.getLocks().isEmpty());
        assertEquals(1, entry.getModifications().size());
        assertTrue(!cache.exists("/one/two"));
        assertEquals(null, dummy.getCalled());

        //lets change one of the underlying version numbers
        ((OptimisticTreeNode) workspace.getNode(Fqn.fromString("/one/two")).getNode()).setVersion(new DefaultDataVersion(2));
        //now let us do a prepare
        MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, new Object[]{gtx, entry.getModifications(), gtx.getAddress(), Boolean.FALSE});
        try
        {
            cache._replicate(prepareMethod);
            fail();
        }
        catch (Throwable t)
        {
            assertTrue(true);
        }


        mgr.commit();

        destroyCache(cache);
    }
View Full Code Here

        nodeInterceptor.setNext(dummy);

        cache.setInterceptorChain(validateInterceptor);

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

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

        GlobalTransaction gtx = table.get(tx);

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

        TransactionWorkspace workspace = entry.getTransactionWorkSpace();

        /*GlobalTransaction.class,
List.class,
Address.class,
boolean.class*/

        assertEquals(3, workspace.getNodes().size());
        assertNotNull(workspace.getNode(Fqn.fromString("/one/two")));
        assertEquals(pojo, workspace.getNode(Fqn.fromString("/one/two")).get("key1"));
        assertEquals(1, workspace.getNode(Fqn.fromString("/one/two")).getMergedData().size());
        assertTrue(entry.getLocks().isEmpty());
        assertEquals(1, entry.getModifications().size());
        assertTrue(!cache.exists("/one/two"));
        assertEquals(null, dummy.getCalled());

        //lets change one of the underlying version numbers
        //now let us do a prepare
        MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, new Object[]{gtx, entry.getModifications(), gtx.getAddress(), Boolean.FALSE});
        try
        {
            cache._replicate(prepareMethod);
            fail();
        }
        catch (Throwable t)
        {
            assertTrue(true);
        }

        MethodCall commitMethod = MethodCallFactory.create(MethodDeclarations.commitMethod, new Object[]{gtx});
        try
        {
            cache._replicate(commitMethod);
        }
        catch (Throwable t)
        {
            fail();
        }


        assertEquals(3, workspace.getNodes().size());
        assertNotNull(workspace.getNode(Fqn.fromString("/one/two")));
        assertEquals(pojo, workspace.getNode(Fqn.fromString("/one/two")).get("key1"));
        assertEquals(1, workspace.getNode(Fqn.fromString("/one/two")).getMergedData().size());
        assertTrue(entry.getLocks().isEmpty());
        assertEquals(1, entry.getModifications().size());


        assertEquals(null, dummy.getCalled());
        OptimisticTreeNode node = (OptimisticTreeNode) workspace.getNode(Fqn.fromString("/")).getNode();
        //assert we can navigate

        assertNotNull(node);
        node = (OptimisticTreeNode) node.getChild("one");
        assertEquals(new DefaultDataVersion(1), node.getVersion());
        assertNotNull(node);
        assertTrue(cache.exists(node.getFqn()));
        assertEquals(new DefaultDataVersion(1), node.getVersion());
        node = (OptimisticTreeNode) node.getChild("two");
        assertNotNull(node);
        assertTrue(cache.exists(node.getFqn()));
        assertEquals(new DefaultDataVersion(1), node.getVersion());

        assertEquals(pojo, node.get("key1"));

        mgr.commit();

        destroyCache(cache);
    }
View Full Code Here

        nodeInterceptor.setNext(dummy);

        cache.setInterceptorChain(validateInterceptor);

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

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

        GlobalTransaction gtx = table.get(tx);

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

        TransactionWorkspace workspace = entry.getTransactionWorkSpace();

        assertEquals(3, workspace.getNodes().size());
        assertNotNull(workspace.getNode(Fqn.fromString("/one/two")));
        assertEquals(pojo, workspace.getNode(Fqn.fromString("/one/two")).get("key1"));
        assertEquals(1, workspace.getNode(Fqn.fromString("/one/two")).getMergedData().size());
        assertTrue(entry.getLocks().isEmpty());
        assertEquals(1, entry.getModifications().size());
        assertTrue(!cache.exists("/one/two"));
        assertEquals(null, dummy.getCalled());

        //lets change one of the underlying version numbers
        //now let us do a prepare
        MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, new Object[]{gtx, entry.getModifications(), gtx.getAddress(), Boolean.FALSE});
        try
        {
            cache._replicate(prepareMethod);
            fail();
        }
        catch (Throwable t)
        {
            assertTrue(true);
        }


        MethodCall commitMethod = MethodCallFactory.create(MethodDeclarations.commitMethod, new Object[]{gtx});
        try
        {
            cache._replicate(commitMethod);
        }
        catch (Throwable t)
        {
            fail();
        }


        assertEquals(3, workspace.getNodes().size());
        assertNotNull(workspace.getNode(Fqn.fromString("/one/two")));
        assertEquals(pojo, workspace.getNode(Fqn.fromString("/one/two")).get("key1"));
        assertEquals(1, workspace.getNode(Fqn.fromString("/one/two")).getMergedData().size());
        assertTrue(entry.getLocks().isEmpty());
        assertEquals(1, entry.getModifications().size());


        assertEquals(null, dummy.getCalled());
        OptimisticTreeNode node = (OptimisticTreeNode) workspace.getNode(Fqn.fromString("/")).getNode();
        //assert we can navigate

        assertNotNull(node);
        node = (OptimisticTreeNode) node.getChild("one");
        assertEquals(new DefaultDataVersion(1), node.getVersion());
        assertNotNull(node);
        assertTrue(cache.exists(node.getFqn()));
        assertEquals(new DefaultDataVersion(1), node.getVersion());
        node = (OptimisticTreeNode) node.getChild("two");
        assertNotNull(node);
        assertTrue(cache.exists(node.getFqn()));
        assertEquals(new DefaultDataVersion(1), node.getVersion());

        assertEquals(pojo, node.get("key1"));

        mgr.commit();

        destroyCache(cache);
    }
View Full Code Here

        nodeInterceptor.setNext(dummy);

        cache.setInterceptorChain(validateInterceptor);

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

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

        GlobalTransaction gtx = table.get(tx);

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

        TransactionWorkspace workspace = entry.getTransactionWorkSpace();

        /*GlobalTransaction.class,
List.class,
Address.class,
boolean.class*/

        assertEquals(3, workspace.getNodes().size());
        assertNotNull(workspace.getNode(Fqn.fromString("/one/two")));
        assertEquals(pojo, workspace.getNode(Fqn.fromString("/one/two")).get("key1"));
        assertEquals(1, workspace.getNode(Fqn.fromString("/one/two")).getMergedData().size());
        assertTrue(entry.getLocks().isEmpty());
        assertEquals(1, entry.getModifications().size());
        assertTrue(!cache.exists("/one/two"));
        assertEquals(null, dummy.getCalled());

        //lets change one of the underlying version numbers
        //now let us do a prepare
        MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, new Object[]{gtx, entry.getModifications(), gtx.getAddress(), Boolean.FALSE});
        try
        {
            cache._replicate(prepareMethod);
            fail();
        }
        catch (Throwable t)
        {
            assertTrue(true);
        }

        MethodCall rollbackMethod = MethodCallFactory.create(MethodDeclarations.rollbackMethod, new Object[]{gtx});
        try
        {
            cache._replicate(rollbackMethod);
        }
        catch (Throwable t)
        {
            fail();
        }


        assertEquals(0, workspace.getNodes().size());
        assertNull(workspace.getNode(Fqn.fromString("/one/two")));
        assertNull(workspace.getNode(Fqn.fromString("/one")));
        assertTrue(entry.getLocks().isEmpty());
        assertEquals(1, entry.getModifications().size());

        mgr.commit();

        destroyCache(cache);
    }
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.