Search in sources :

Example 36 with Customer

use of org.apache.geode.internal.cache.execute.data.Customer 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 37 with Customer

use of org.apache.geode.internal.cache.execute.data.Customer 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 38 with Customer

use of org.apache.geode.internal.cache.execute.data.Customer 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)

Example 39 with Customer

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

the class DistributedTransactionDUnitTest method testTransactionalPutOnReplicatedRegion.

@Test
public void testTransactionalPutOnReplicatedRegion() 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();
            mgr.commit();
            mgr.begin();
            Region<CustId, Customer> custRegion = getCache().getRegion(CUSTOMER_RR);
            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");
            custRegion.put(custIdOne, customerOne);
            // Rollback the transaction
            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");
            custRegion.put(custIdTwo, customerTwo);
            custRegion.put(custIdThree, customerThree);
            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
            custRegion.put(custIdOne, customerOne);
            // Verify data
            assertEquals(3, custRegion.size());
            assertTrue(custRegion.containsKey(custIdOne));
            assertEquals(customerOne, custRegion.get(custIdOne));
            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) 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 40 with Customer

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

the class RemoteTransactionDUnitTest method testDRFunctionExecution.

@Test
public void testDRFunctionExecution() {
    Host host = Host.getHost(0);
    VM accessor = host.getVM(0);
    VM datastore1 = host.getVM(1);
    VM datastore2 = host.getVM(2);
    class CreateDR extends SerializableCallable {

        private final boolean isAccessor;

        public CreateDR(boolean isAccessor) {
            this.isAccessor = isAccessor;
        }

        public Object call() throws Exception {
            AttributesFactory af = new AttributesFactory();
            af.setDataPolicy(isAccessor ? DataPolicy.EMPTY : DataPolicy.REPLICATE);
            af.setScope(Scope.DISTRIBUTED_ACK);
            af.setConcurrencyChecksEnabled(getConcurrencyChecksEnabled());
            getCache().createRegion(CUSTOMER, af.create());
            if (isAccessor) {
                Region custRegion = getCache().getRegion(CUSTOMER);
                for (int i = 0; i < 5; i++) {
                    CustId custId = new CustId(i);
                    Customer customer = new Customer("customer" + i, "address" + i);
                    custRegion.put(custId, customer);
                }
            }
            return null;
        }
    }
    datastore1.invoke(new CreateDR(false));
    datastore2.invoke(new CreateDR(false));
    accessor.invoke(new CreateDR(true));
    SerializableCallable registerFunction = new SerializableCallable() {

        public Object call() throws Exception {
            FunctionService.registerFunction(new TXFunction());
            return null;
        }
    };
    accessor.invoke(registerFunction);
    datastore1.invoke(registerFunction);
    datastore2.invoke(registerFunction);
    accessor.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Region custRegion = getGemfireCache().getRegion(CUSTOMER);
            TXManagerImpl mgr = getGemfireCache().getTXMgr();
            mgr.begin();
            FunctionService.onRegion(custRegion).execute(TXFunction.id).getResult();
            assertNotNull(mgr.getTXState());
            TXStateProxy tx = mgr.internalSuspend();
            assertNull(mgr.getTXState());
            getGemfireCache().getLogger().fine("SWAP:callingget");
            assertNull("expected null but was:" + custRegion.get(expectedCustId), custRegion.get(expectedCustId));
            mgr.internalResume(tx);
            mgr.commit();
            assertEquals(expectedCustomer, custRegion.get(expectedCustId));
            return null;
        }
    });
    datastore1.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            final Region custRegion = getGemfireCache().getRegion(CUSTOMER);
            TXManagerImpl mgr = getGemfireCache().getTXMgr();
            mgr.begin();
            FunctionService.onRegion(custRegion).execute(new FunctionAdapter() {

                @Override
                public String getId() {
                    return "LocalDS";
                }

                @Override
                public void execute(FunctionContext context) {
                    assertNotNull(getGemfireCache().getTxManager().getTXState());
                    custRegion.destroy(expectedCustId);
                    context.getResultSender().lastResult(Boolean.TRUE);
                }
            }).getResult();
            TXStateProxy tx = mgr.internalSuspend();
            assertEquals(custRegion.get(expectedCustId), expectedCustomer);
            mgr.internalResume(tx);
            mgr.commit();
            assertNull(custRegion.get(expectedCustId));
            return null;
        }
    });
}
Also used : Customer(org.apache.geode.internal.cache.execute.data.Customer) Host(org.apache.geode.test.dunit.Host) NamingException(javax.naming.NamingException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) TransactionWriterException(org.apache.geode.cache.TransactionWriterException) CacheWriterException(org.apache.geode.cache.CacheWriterException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException) TransactionException(org.apache.geode.cache.TransactionException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException) RollbackException(javax.transaction.RollbackException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) CommitConflictException(org.apache.geode.cache.CommitConflictException) FunctionContext(org.apache.geode.cache.execute.FunctionContext) RegionFunctionContext(org.apache.geode.cache.execute.RegionFunctionContext) 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) Region(org.apache.geode.cache.Region) FunctionAdapter(org.apache.geode.cache.execute.FunctionAdapter) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) TXExpiryJUnitTest(org.apache.geode.TXExpiryJUnitTest) Test(org.junit.Test)

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