Search in sources :

Example 86 with Customer

use of org.apache.geode.internal.cache.execute.data.Customer in project geode by apache.

the class DistributedTransactionDUnitTest method testRegionAndEntryVersionsPR.

@Test
public void testRegionAndEntryVersionsPR() throws Exception {
    Host host = Host.getHost(0);
    VM server1 = host.getVM(0);
    VM server2 = host.getVM(1);
    createPersistentPR(new VM[] { server1, server2 });
    execute(server2, new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            CacheTransactionManager mgr = getGemfireCache().getTxManager();
            mgr.setDistributed(true);
            getGemfireCache().getLoggerI18n().fine("TEST:DISTTX=" + mgr.isDistributed());
            getGemfireCache().getLoggerI18n().fine("TEST:TX BEGIN");
            mgr.begin();
            Region<CustId, Customer> prRegion = getCache().getRegion(PERSISTENT_CUSTOMER_PR);
            CustId custIdOne = new CustId(1);
            Customer customerOne = new Customer("name1", "addr1");
            getGemfireCache().getLoggerI18n().fine("TEST:TX PUT 1");
            prRegion.put(custIdOne, customerOne);
            BucketRegion br = ((PartitionedRegion) prRegion).getBucketRegion(custIdOne);
            assertEquals(0L, br.getVersionVector().getCurrentVersion());
            getGemfireCache().getLoggerI18n().fine("TEST:TX COMMIT 1");
            mgr.commit();
            // Verify region version on the region
            assertEquals(1L, br.getVersionVector().getCurrentVersion());
            RegionEntry re = br.getRegionEntry(custIdOne);
            getGemfireCache().getLoggerI18n().fine("TEST:VERSION-STAMP:" + re.getVersionStamp());
            // Verify region version on the region entry
            assertEquals(1L, re.getVersionStamp().getRegionVersion());
            // Verify entry version
            assertEquals(1, re.getVersionStamp().getEntryVersion());
            mgr.begin();
            prRegion.put(custIdOne, new Customer("name1_1", "addr1"));
            getGemfireCache().getLoggerI18n().fine("TEST:TX COMMIT 2");
            assertEquals(1L, br.getVersionVector().getCurrentVersion());
            mgr.commit();
            // Verify region version on the region
            assertEquals(2L, br.getVersionVector().getCurrentVersion());
            re = br.getRegionEntry(custIdOne);
            getGemfireCache().getLoggerI18n().fine("TEST:VERSION-STAMP:" + re.getVersionStamp());
            // Verify region version on the region entry
            assertEquals(2L, re.getVersionStamp().getRegionVersion());
            // Verify entry version
            assertEquals(2, re.getVersionStamp().getEntryVersion());
            return null;
        }
    });
    execute(server1, new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            Region<CustId, Customer> prRegion = getCache().getRegion(PERSISTENT_CUSTOMER_PR);
            CustId custIdOne = new CustId(1);
            BucketRegion br = ((PartitionedRegion) prRegion).getBucketRegion(custIdOne);
            // Verify region version on the region
            assertEquals(2L, br.getVersionVector().getCurrentVersion());
            // Verify region version ont the region entry
            RegionEntry re = br.getRegionEntry(custIdOne);
            assertEquals(2L, re.getVersionStamp().getRegionVersion());
            // Verify entry version
            assertEquals(2, re.getVersionStamp().getEntryVersion());
            return null;
        }
    });
}
Also used : BucketRegion(org.apache.geode.internal.cache.BucketRegion) CustId(org.apache.geode.internal.cache.execute.data.CustId) Customer(org.apache.geode.internal.cache.execute.data.Customer) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) LocalRegion(org.apache.geode.internal.cache.LocalRegion) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) RegionEntry(org.apache.geode.internal.cache.RegionEntry) Host(org.apache.geode.test.dunit.Host) CommitConflictException(org.apache.geode.cache.CommitConflictException) CommitIncompleteException(org.apache.geode.cache.CommitIncompleteException) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 87 with Customer

use of org.apache.geode.internal.cache.execute.data.Customer in project geode by apache.

the class DistributedTransactionDUnitTest method testTransactionalPutOnPartitionedRegion.

@Test
public void testTransactionalPutOnPartitionedRegion() throws Exception {
    Host host = Host.getHost(0);
    VM server1 = host.getVM(0);
    VM server2 = host.getVM(1);
    VM server3 = host.getVM(2);
    createPR(new VM[] { server1, server2, server3 });
    execute(server1, new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            CacheTransactionManager mgr = getGemfireCache().getTxManager();
            mgr.setDistributed(true);
            LogWriterI18n logger = getGemfireCache().getLoggerI18n();
            mgr.begin();
            logger.fine("TEST:Commit-1");
            mgr.commit();
            mgr.begin();
            Region<CustId, Customer> custRegion = getCache().getRegion(CUSTOMER_PR);
            CustId custId = new CustId(1);
            Customer expectedCustomer = custRegion.get(custId);
            assertNull(expectedCustomer);
            // Perform a put
            CustId custIdOne = new CustId(1);
            Customer customerOne = new Customer("name1", "addr1");
            logger.fine("TEST:Put-1");
            custRegion.put(custIdOne, customerOne);
            // Rollback the transaction
            logger.fine("TEST:Rollback-1");
            mgr.rollback();
            mgr.begin();
            // Verify that the entry is rolled back
            expectedCustomer = custRegion.get(custId);
            assertNull(expectedCustomer);
            // Perform two more puts and a commit
            CustId custIdTwo = new CustId(2);
            Customer customerTwo = new Customer("name2", "addr2");
            CustId custIdThree = new CustId(3);
            Customer customerThree = new Customer("name3", "addr3");
            logger.fine("TEST:Put-2");
            custRegion.put(custIdTwo, customerTwo);
            logger.fine("TEST:Put-3");
            custRegion.put(custIdThree, customerThree);
            logger.fine("TEST:Commit-2");
            mgr.commit();
            mgr.begin();
            // Verify data
            assertEquals(2, custRegion.size());
            assertTrue(custRegion.containsKey(custIdTwo));
            assertTrue(custRegion.containsKey(custIdThree));
            assertEquals(customerTwo, custRegion.get(custIdTwo));
            assertEquals(customerThree, custRegion.get(custIdThree));
            // Perform one more put but don't commit
            logger.fine("TEST:Put-4");
            Customer customerOneMod = new Customer("name1", "addr11");
            custRegion.put(custIdOne, customerOneMod);
            // Verify data
            assertEquals(3, custRegion.size());
            assertTrue(custRegion.containsKey(custIdOne));
            assertEquals(customerOneMod, custRegion.get(custIdOne));
            logger.fine("TEST:Commit-3");
            mgr.commit();
            return null;
        }
    });
}
Also used : CustId(org.apache.geode.internal.cache.execute.data.CustId) Customer(org.apache.geode.internal.cache.execute.data.Customer) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) LocalRegion(org.apache.geode.internal.cache.LocalRegion) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Host(org.apache.geode.test.dunit.Host) LogWriterI18n(org.apache.geode.i18n.LogWriterI18n) CommitConflictException(org.apache.geode.cache.CommitConflictException) CommitIncompleteException(org.apache.geode.cache.CommitIncompleteException) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 88 with Customer

use of org.apache.geode.internal.cache.execute.data.Customer in project geode by apache.

the class DistributedTransactionDUnitTest method testTxWorksWithNewNodeJoining.

@Test
public void testTxWorksWithNewNodeJoining() throws Exception {
    Host host = Host.getHost(0);
    VM server1 = host.getVM(0);
    VM server2 = host.getVM(1);
    VM server3 = host.getVM(2);
    createPR(new VM[] { server1, server2 });
    class Ops extends SerializableCallable {

        private boolean flag = false;

        public void setWaitFlag(boolean value) {
            flag = value;
        }

        @Override
        public Object call() throws Exception {
            CacheTransactionManager mgr = getGemfireCache().getTxManager();
            mgr.setDistributed(true);
            mgr.begin();
            Region<CustId, Customer> prRegion = getCache().getRegion(CUSTOMER_PR);
            CustId custIdOne = new CustId(1);
            Customer customerOne = new Customer("name1", "addr1");
            prRegion.put(custIdOne, customerOne);
            // Install the hook at this point
            TestObserver o = TestObserver.getInstance();
            o.setFlag(true);
            while (o.getFlag()) {
                Thread.currentThread().sleep(1000);
            }
            mgr.commit();
            // Verify
            assertEquals(1, prRegion.size());
            assertTrue(prRegion.containsKey(custIdOne));
            return null;
        }
    }
    server1.invokeAsync(() -> new Ops().call());
    // Now create cache on the third server and let it join the distributed system.
    createPR(new VM[] { server3 });
    // Let the original thread move on by signalling the flag
    execute(server1, new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            TestObserver o = TestObserver.getInstance();
            o.setFlag(false);
            return null;
        }
    });
}
Also used : CustId(org.apache.geode.internal.cache.execute.data.CustId) Customer(org.apache.geode.internal.cache.execute.data.Customer) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Host(org.apache.geode.test.dunit.Host) CommitConflictException(org.apache.geode.cache.CommitConflictException) CommitIncompleteException(org.apache.geode.cache.CommitIncompleteException) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 89 with Customer

use of org.apache.geode.internal.cache.execute.data.Customer in project geode by apache.

the class DistributedTransactionDUnitTest method testGetIsolated.

@Test
public void testGetIsolated() throws Exception {
    Host host = Host.getHost(0);
    VM server1 = host.getVM(0);
    VM server2 = host.getVM(1);
    VM server3 = host.getVM(2);
    createPR(new VM[] { server1, server2, server3 });
    createRR(new VM[] { server1, server2, server3 });
    execute(server1, new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            CacheTransactionManager mgr = getGemfireCache().getTxManager();
            mgr.setDistributed(true);
            mgr.begin();
            mgr.commit();
            mgr.begin();
            Region<CustId, Customer> custPR = getCache().getRegion(CUSTOMER_PR);
            CustId custIdOne = new CustId(1);
            Customer customerOne = new Customer("name1", "addr1");
            custPR.put(custIdOne, customerOne);
            Region<CustId, Customer> replicatedRegion = getCache().getRegion(CUSTOMER_RR);
            replicatedRegion.put(custIdOne, customerOne);
            CustId custIdTwo = new CustId(2);
            Customer customerTwo = new Customer("name2", "addr2");
            replicatedRegion.put(custIdTwo, customerTwo);
            // Verify before commit
            assertEquals(2, replicatedRegion.size());
            assertEquals(customerOne, replicatedRegion.get(custIdOne));
            assertEquals(customerTwo, replicatedRegion.get(custIdTwo));
            // Perform commit
            mgr.commit();
            // Verify after commit
            assertEquals(2, replicatedRegion.size());
            assertEquals(customerOne, replicatedRegion.get(custIdOne));
            assertEquals(customerTwo, replicatedRegion.get(custIdTwo));
            return null;
        }
    });
}
Also used : CustId(org.apache.geode.internal.cache.execute.data.CustId) Customer(org.apache.geode.internal.cache.execute.data.Customer) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) LocalRegion(org.apache.geode.internal.cache.LocalRegion) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Host(org.apache.geode.test.dunit.Host) CommitConflictException(org.apache.geode.cache.CommitConflictException) CommitIncompleteException(org.apache.geode.cache.CommitIncompleteException) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 90 with Customer

use of org.apache.geode.internal.cache.execute.data.Customer in project geode by apache.

the class PRTransactionDUnitTest method testCacheListenerCallbacks.

@Ignore("BUG46661")
@Test
public void testCacheListenerCallbacks() {
    createPopulateAndVerifyCoLocatedPRs(1);
    SerializableCallable registerListeners = new SerializableCallable() {

        public Object call() throws Exception {
            Region custRegion = basicGetCache().getRegion(Region.SEPARATOR + CustomerPartitionedRegionName);
            custRegion.getAttributesMutator().addCacheListener(new TransactionListener2());
            return null;
        }
    };
    accessor.invoke(registerListeners);
    dataStore1.invoke(registerListeners);
    dataStore2.invoke(registerListeners);
    dataStore3.invoke(registerListeners);
    accessor.invoke(new SerializableCallable("run function") {

        public Object call() throws Exception {
            PartitionedRegion pr = (PartitionedRegion) basicGetCache().getRegion(Region.SEPARATOR + CustomerPartitionedRegionName);
            PartitionedRegion orderpr = (PartitionedRegion) basicGetCache().getRegion(Region.SEPARATOR + OrderPartitionedRegionName);
            CustId custId = new CustId(2);
            Customer newCus = new Customer("foo", "bar");
            Order order = new Order("fooOrder");
            OrderId orderId = new OrderId(22, custId);
            ArrayList args = new ArrayList();
            Function txFunction = new MyTransactionFunction();
            FunctionService.registerFunction(txFunction);
            Execution e = FunctionService.onRegion(pr);
            Set filter = new HashSet();
            boolean caughtException = false;
            // test transaction non-coLocated operations
            filter.clear();
            args.clear();
            args.add(new Integer(VERIFY_LISTENER_CALLBACK));
            LogWriterUtils.getLogWriter().info("VERIFY_LISTENER_CALLBACK");
            args.add(custId);
            args.add(newCus);
            args.add(orderId);
            args.add(order);
            filter.add(custId);
            caughtException = false;
            e.withFilter(filter).setArguments(args).execute(txFunction.getId()).getResult();
            return null;
        }
    });
}
Also used : Order(org.apache.geode.internal.cache.execute.data.Order) HashSet(java.util.HashSet) Set(java.util.Set) Customer(org.apache.geode.internal.cache.execute.data.Customer) ArrayList(java.util.ArrayList) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException) FunctionException(org.apache.geode.cache.execute.FunctionException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) TestException(util.TestException) PRLocallyDestroyedException(org.apache.geode.internal.cache.partitioned.PRLocallyDestroyedException) Function(org.apache.geode.cache.execute.Function) Execution(org.apache.geode.cache.execute.Execution) CustId(org.apache.geode.internal.cache.execute.data.CustId) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) HashSet(java.util.HashSet) Ignore(org.junit.Ignore) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

Customer (org.apache.geode.internal.cache.execute.data.Customer)115 CustId (org.apache.geode.internal.cache.execute.data.CustId)114 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)73 Test (org.junit.Test)73 Region (org.apache.geode.cache.Region)71 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)58 Host (org.apache.geode.test.dunit.Host)54 VM (org.apache.geode.test.dunit.VM)54 RollbackException (javax.transaction.RollbackException)53 CommitConflictException (org.apache.geode.cache.CommitConflictException)48 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)39 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)37 OrderId (org.apache.geode.internal.cache.execute.data.OrderId)35 CacheTransactionManager (org.apache.geode.cache.CacheTransactionManager)34 CacheWriterException (org.apache.geode.cache.CacheWriterException)33 TransactionDataNotColocatedException (org.apache.geode.cache.TransactionDataNotColocatedException)33 TransactionDataRebalancedException (org.apache.geode.cache.TransactionDataRebalancedException)33 IgnoredException (org.apache.geode.test.dunit.IgnoredException)32 Order (org.apache.geode.internal.cache.execute.data.Order)30 NamingException (javax.naming.NamingException)28