Package org.jboss.cache

Examples of org.jboss.cache.TransactionTable


        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);
        assertEquals(tx, mgr.getTransaction());

        //now send the remote prepare

        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)
        {
            t.printStackTrace();
            fail();
        }

        //we should have the same transaction back again
        assertEquals(tx, mgr.getTransaction());

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


        List calls = dummy.getAllCalled();
        assertEquals(MethodDeclarations.optimisticPrepareMethod, calls.get(0));

        //assert we have two current transactions
        assertEquals(2, cache.getTransactionTable().getNumGlobalTransactions());
        assertEquals(2, cache.getTransactionTable().getNumLocalTransactions());

        //commit the local tx
        mgr.commit();

        //check local calls
        calls = dummy.getAllCalled();
        assertEquals(MethodDeclarations.optimisticPrepareMethod, calls.get(1));
        assertEquals(MethodDeclarations.commitMethod, calls.get(2));

        //assert we have only 1 transaction left

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

        assertNotNull(table.get(remoteGtx));
        assertNotNull(table.getLocalTransaction(remoteGtx));

        assertNull(table.get(gtx));
        assertNull(table.getLocalTransaction(gtx));
        //assert we are no longer associated
        assertEquals(null, mgr.getTransaction());
        cache.stopService();
    }
View Full Code Here


        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);
        assertEquals(tx, mgr.getTransaction());

        //now send the remote prepare

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

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

//        call our remote method
        MethodCall commitMethod = MethodCallFactory.create(MethodDeclarations.commitMethod, new Object[]{remoteGtx});
        try
        {
            cache._replicate(commitMethod);
        }
        catch (Throwable t)
        {
            t.printStackTrace();
            fail();
        }

        //we should have the same transaction back again
        assertEquals(tx, mgr.getTransaction());

        //   there should be a registration for the remote gtx
        assertNull(table.get(remoteGtx));
        assertNull(table.getLocalTransaction(remoteGtx));

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

        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);
        assertEquals(tx, mgr.getTransaction());

        //now send the remote prepare

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

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

//        call our remote method
        MethodCall rollbackMethod = MethodCallFactory.create(MethodDeclarations.rollbackMethod, new Object[]{remoteGtx});
        try
        {
            cache._replicate(rollbackMethod);
        }
        catch (Throwable t)
        {
            fail();
        }

        //we should have the same transaction back again
        assertEquals(tx, mgr.getTransaction());

        //   there should be a registration for the remote gtx
        assertNull(table.get(remoteGtx));
        assertNull(table.getLocalTransaction(remoteGtx));

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

        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 be null
        assertNull(mgr.getTransaction());
        assertEquals(1, cache.getTransactionTable().getNumGlobalTransactions());
        assertEquals(1, cache.getTransactionTable().getNumLocalTransactions());

        //   there should be a registration for the remote gtx
        assertNotNull(table.get(remoteGtx));
        assertNotNull(table.getLocalTransaction(remoteGtx));
        //this is not populated until replication interceptor is used
        assertEquals(1, table.get(remoteGtx).getModifications().size());

        calls = dummy.getAllCalled();
        assertEquals(MethodDeclarations.optimisticPrepareMethod, calls.get(2));

        assertNull(mgr.getTransaction());
//      call our remote method
        MethodCall commitMethod = MethodCallFactory.create(MethodDeclarations.commitMethod, new Object[]{remoteGtx, Boolean.TRUE});
        try
        {
            cache._replicate(commitMethod);
        }
        catch (Throwable t)
        {
            fail();
        }

        assertNull(table.get(remoteGtx));
        assertNull(table.getLocalTransaction(remoteGtx));

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

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

        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 be null
        assertNull(mgr.getTransaction());

        //   there should be a registration for the remote gtx
        assertNotNull(table.get(remoteGtx));
        assertNotNull(table.getLocalTransaction(remoteGtx));
        //this is not populated until replication interceptor is used
        assertEquals(1, table.get(remoteGtx).getModifications().size());

        calls = dummy.getAllCalled();
        assertEquals(MethodDeclarations.optimisticPrepareMethod, calls.get(2));

//      call our remote method
        MethodCall rollbackMethod = MethodCallFactory.create(MethodDeclarations.rollbackMethod, new Object[]{remoteGtx});
        try
        {
            cache._replicate(rollbackMethod);
        }
        catch (Throwable t)
        {
            fail();
        }

        calls = dummy.getAllCalled();
        assertEquals(MethodDeclarations.optimisticPrepareMethod, calls.get(2));
        assertEquals(MethodDeclarations.rollbackMethod, calls.get(3));

        assertNull(table.get(remoteGtx));
        assertNull(table.getLocalTransaction(remoteGtx));

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

        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 boolean isMulticastAddress()
            {

                return false;
            }

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


            }

            public void writeExternal(ObjectOutput arg0) throws IOException
            {


            }

            public int compareTo(Object arg0)
            {

                return 0;
            }

            public int size()
            {

                return 0;
            }

            public void writeTo(DataOutputStream arg0) throws IOException
            {


            }

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


            }
        });
        //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));
View Full Code Here

        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();
View Full Code Here

        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();
View Full Code Here

        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 boolean isMulticastAddress()
            {

                return false;
            }

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


            }

            public int size()
            {

                return 0;
            }

            public void writeExternal(ObjectOutput arg0) throws IOException
            {


            }

            public void writeTo(DataOutputStream arg0) throws IOException
            {


            }

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


            }

            public int compareTo(Object arg0)
            {

                return 0;
            }
        });
        //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));
View Full Code Here

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


        assertNull(mgr.getTransaction());
View Full Code Here

TOP

Related Classes of org.jboss.cache.TransactionTable

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.