Search in sources :

Example 26 with CacheTransactionManager

use of org.apache.geode.cache.CacheTransactionManager in project geode by apache.

the class TXOrderDUnitTest method doCommitOtherVm.

private void doCommitOtherVm() {
    VM vm = getOtherVm();
    vm.invoke(new CacheSerializableRunnable("create root") {

        public void run2() throws CacheException {
            AttributesFactory af = new AttributesFactory();
            af.setScope(Scope.DISTRIBUTED_ACK);
            Region r1 = createRootRegion("r1", af.create());
            Region r2 = r1.createSubregion("r2", af.create());
            Region r3 = r2.createSubregion("r3", af.create());
            CacheTransactionManager ctm = getCache().getCacheTransactionManager();
            ctm.begin();
            r2.put("b", "value1");
            r3.put("c", "value2");
            r1.put("a", "value3");
            r1.put("a2", "value4");
            r3.put("c2", "value5");
            r2.put("b2", "value6");
            ctm.commit();
        }
    });
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CacheException(org.apache.geode.cache.CacheException) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager)

Example 27 with CacheTransactionManager

use of org.apache.geode.cache.CacheTransactionManager in project geode by apache.

the class DistributedTransactionDUnitTest method testTransactionalUpdates.

@Test
public void testTransactionalUpdates() 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[] { server2, server3 });
    execute(server1, new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            CacheTransactionManager mgr = getGemfireCache().getTxManager();
            mgr.setDistributed(true);
            mgr.begin();
            createPR(false, 0, null);
            Region<CustId, Customer> custPR = getCache().getRegion(CUSTOMER_PR);
            for (int i = 1; i <= 200; i++) {
                custPR.put(new CustId(i), new Customer("name" + i, "addr" + i));
            }
            assertEquals(200, custPR.size());
            mgr.rollback();
            // mgr.commit();
            mgr.begin();
            assertEquals(0, custPR.size());
            mgr.commit();
            mgr.begin();
            for (int i = 1; i <= 200; i++) {
                custPR.put(new CustId(i), new Customer("name" + i, "addr" + i));
            }
            mgr.commit();
            // mgr.begin();
            for (int i = 1; i <= 200; i++) {
                mgr.begin();
                custPR.put(new CustId(i), new Customer("name" + i * 2, "addr" + i * 2));
                mgr.commit();
            }
            mgr.begin();
            mgr.rollback();
            assertEquals(200, custPR.size());
            for (int i = 1; i <= 200; i++) {
                assertEquals(new Customer("name" + i * 2, "addr" + i * 2), custPR.get(new CustId(i)));
            }
            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 28 with CacheTransactionManager

use of org.apache.geode.cache.CacheTransactionManager in project geode by apache.

the class DistributedTransactionDUnitTest method testTransactionalKeyBasedUpdates.

@Test
public void testTransactionalKeyBasedUpdates() 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);
            // mgr.begin();
            LogWriterI18n logger = getGemfireCache().getLoggerI18n();
            Region<CustId, Customer> custPR = getCache().getRegion(CUSTOMER_PR);
            for (int i = 1; i <= 2; i++) {
                mgr.begin();
                logger.fine("TEST:PUT-" + i);
                custPR.put(new CustId(i), new Customer("name" + i, "addr" + i));
                logger.fine("TEST:COMMIT-" + i);
                mgr.commit();
            }
            // Updates
            for (int i = 1; i <= 2; i++) {
                CustId custId = new CustId(i);
                Customer customer = custPR.get(custId);
                assertNotNull(customer);
                mgr.begin();
                logger.fine("TEST:UPDATE-" + i);
                custPR.put(custId, new Customer("name" + i * 2, "addr" + i * 2));
                logger.fine("TEST:UPDATED-" + i + "=" + custId + "," + custPR.get(custId));
                logger.fine("TEST:UPDATE COMMIT-" + i);
                mgr.commit();
                logger.fine("TEST:POSTCOMMIT-" + i + "=" + custId + "," + custPR.get(custId));
            }
            // Verify
            for (int i = 1; i <= 2; i++) {
                CustId custId = new CustId(i);
                Customer customer = custPR.get(custId);
                assertNotNull(customer);
                logger.fine("TEST:VERIFYING-" + i);
                assertEquals(new Customer("name" + i * 2, "addr" + i * 2), customer);
            }
            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 29 with CacheTransactionManager

use of org.apache.geode.cache.CacheTransactionManager in project geode by apache.

the class DistributedTransactionDUnitTest method testNonColocatedPutByPartitioning.

/*
   * We create 2 partitioned regions one on each server and have a third node as accessor and fire
   * transactional operations on it.
   */
@Test
public void testNonColocatedPutByPartitioning() {
    Host host = Host.getHost(0);
    // datastore
    VM server1 = host.getVM(0);
    // datastore
    VM server2 = host.getVM(1);
    // accessor
    VM server3 = host.getVM(2);
    final String CUSTOMER_PR1 = "CUSTOMER_PR1";
    final String CUSTOMER_PR2 = "CUSTOMER_PR2";
    // Create CUSTOMER_PR1 on server1
    execute(server1, new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            AttributesFactory af = new AttributesFactory();
            af.setConcurrencyChecksEnabled(getConcurrencyChecksEnabled());
            af.setPartitionAttributes(new PartitionAttributesFactory<CustId, Customer>().setTotalNumBuckets(4).setLocalMaxMemory(1).setPartitionResolver(new CustomerIDPartitionResolver("resolver1")).setRedundantCopies(0).create());
            getCache().createRegion(CUSTOMER_PR1, af.create());
            return null;
        }
    });
    // Create CUSTOMER_PR2 on server2
    execute(server2, new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            AttributesFactory af = new AttributesFactory();
            af.setConcurrencyChecksEnabled(getConcurrencyChecksEnabled());
            af.setPartitionAttributes(new PartitionAttributesFactory<CustId, Customer>().setTotalNumBuckets(4).setLocalMaxMemory(1).setPartitionResolver(new CustomerIDPartitionResolver("resolver2")).setRedundantCopies(0).create());
            getCache().createRegion(CUSTOMER_PR2, af.create());
            return null;
        }
    });
    // Create both the regions on server3 (accessor)
    execute(server3, new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            AttributesFactory af = new AttributesFactory();
            af.setConcurrencyChecksEnabled(getConcurrencyChecksEnabled());
            af.setPartitionAttributes(new PartitionAttributesFactory<CustId, Customer>().setTotalNumBuckets(4).setLocalMaxMemory(// since this is an accessor
            0).setPartitionResolver(new CustomerIDPartitionResolver("resolver1")).setRedundantCopies(0).create());
            getCache().createRegion(CUSTOMER_PR1, af.create());
            return null;
        }
    });
    execute(server3, new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            AttributesFactory af = new AttributesFactory();
            af.setConcurrencyChecksEnabled(getConcurrencyChecksEnabled());
            af.setPartitionAttributes(new PartitionAttributesFactory<CustId, Customer>().setTotalNumBuckets(4).setLocalMaxMemory(// since this is an accessor
            0).setPartitionResolver(new CustomerIDPartitionResolver("resolver2")).setRedundantCopies(0).create());
            getCache().createRegion(CUSTOMER_PR2, af.create());
            return null;
        }
    });
    // Now perform tx ops on accessor
    execute(server3, new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            CacheTransactionManager mgr = getGemfireCache().getTxManager();
            mgr.setDistributed(true);
            mgr.begin();
            Region<CustId, Customer> custPR1 = getCache().getRegion(CUSTOMER_PR1);
            CustId custIdOne = new CustId(1);
            Customer customerOne = new Customer("name1", "addr1");
            custPR1.put(custIdOne, customerOne);
            Region<CustId, Customer> custPR2 = getCache().getRegion(CUSTOMER_PR2);
            custPR2.put(custIdOne, customerOne);
            mgr.commit();
            // Verify
            assertEquals(1, custPR1.size());
            assertEquals(1, custPR2.size());
            return null;
        }
    });
    // Verify on one of the servers
    execute(server1, new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            Region<CustId, Customer> custPR1 = getCache().getRegion(CUSTOMER_PR1);
            assertEquals(1, custPR1.size());
            CustId custIdOne = new CustId(1);
            Customer customerOne = new Customer("name1", "addr1");
            assertEquals(customerOne, custPR1.get(custIdOne));
            return null;
        }
    });
}
Also used : Customer(org.apache.geode.internal.cache.execute.data.Customer) CustomerIDPartitionResolver(org.apache.geode.internal.cache.execute.CustomerIDPartitionResolver) 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) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CustId(org.apache.geode.internal.cache.execute.data.CustId) 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) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 30 with CacheTransactionManager

use of org.apache.geode.cache.CacheTransactionManager in project geode by apache.

the class DistributedTransactionDUnitTest method testTransactionalKeyBasedDestroys_RR.

@Test
public void testTransactionalKeyBasedDestroys_RR() throws Exception {
    Host host = Host.getHost(0);
    VM server1 = host.getVM(0);
    VM server2 = host.getVM(1);
    VM server3 = host.getVM(2);
    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();
            Region<CustId, Customer> custRR = getCache().getRegion(CUSTOMER_RR);
            for (int i = 1; i <= 1000; i++) {
                mgr.begin();
                custRR.put(new CustId(i), new Customer("name" + i, "addr" + i));
                mgr.commit();
            }
            // Destroys
            for (int i = 1; i <= 100; i++) {
                CustId custId = new CustId(i);
                mgr.begin();
                Object customerRemoved = custRR.remove(custId);
                assertNotNull(customerRemoved);
                mgr.commit();
            }
            // Verify
            for (int i = 1; i <= 100; i++) {
                CustId custId = new CustId(1);
                Customer customer = custRR.get(custId);
                assertNull(customer);
            }
            assertEquals(900, custRR.size());
            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)

Aggregations

CacheTransactionManager (org.apache.geode.cache.CacheTransactionManager)120 Region (org.apache.geode.cache.Region)81 Test (org.junit.Test)77 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)53 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)52 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)51 VM (org.apache.geode.test.dunit.VM)51 LocalRegion (org.apache.geode.internal.cache.LocalRegion)46 CommitConflictException (org.apache.geode.cache.CommitConflictException)45 Host (org.apache.geode.test.dunit.Host)45 CustId (org.apache.geode.internal.cache.execute.data.CustId)37 Customer (org.apache.geode.internal.cache.execute.data.Customer)34 BucketRegion (org.apache.geode.internal.cache.BucketRegion)27 AttributesFactory (org.apache.geode.cache.AttributesFactory)26 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)24 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)23 IgnoredException (org.apache.geode.test.dunit.IgnoredException)23 UnsupportedOperationInTransactionException (org.apache.geode.cache.UnsupportedOperationInTransactionException)22 CacheWriterException (org.apache.geode.cache.CacheWriterException)21 TransactionWriterException (org.apache.geode.cache.TransactionWriterException)21