Search in sources :

Example 86 with SerializableCallable

use of org.apache.geode.test.dunit.SerializableCallable 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 87 with SerializableCallable

use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.

the class DistributedTransactionDUnitTest method preTearDownCacheTestCase.

@Override
public final void preTearDownCacheTestCase() throws Exception {
    Invoke.invokeInEveryVM(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "sync-commits", "false");
            return null;
        }
    });
    Invoke.invokeInEveryVM(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            // System.setProperty("gemfire.ALLOW_PERSISTENT_TRANSACTIONS", "false");
            TXManagerImpl.ALLOW_PERSISTENT_TRANSACTIONS = false;
            return null;
        }
    });
}
Also used : SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) CommitConflictException(org.apache.geode.cache.CommitConflictException) CommitIncompleteException(org.apache.geode.cache.CommitIncompleteException)

Example 88 with SerializableCallable

use of org.apache.geode.test.dunit.SerializableCallable 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 89 with SerializableCallable

use of org.apache.geode.test.dunit.SerializableCallable 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 90 with SerializableCallable

use of org.apache.geode.test.dunit.SerializableCallable 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

SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)502 VM (org.apache.geode.test.dunit.VM)326 Test (org.junit.Test)314 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)311 Host (org.apache.geode.test.dunit.Host)306 Region (org.apache.geode.cache.Region)224 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)157 IgnoredException (org.apache.geode.test.dunit.IgnoredException)155 AttributesFactory (org.apache.geode.cache.AttributesFactory)139 Cache (org.apache.geode.cache.Cache)109 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)95 FunctionException (org.apache.geode.cache.execute.FunctionException)88 ArrayList (java.util.ArrayList)83 HashSet (java.util.HashSet)83 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)77 Execution (org.apache.geode.cache.execute.Execution)74 CommitConflictException (org.apache.geode.cache.CommitConflictException)70 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)66 Function (org.apache.geode.cache.execute.Function)63 IOException (java.io.IOException)62