Search in sources :

Example 41 with Customer

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

the class RemoteTransactionDUnitTest method testPRTXGetEntryOnRemoteSide.

/**
   * Make sure that getEntry returns null properly and values when it should
   */
@Test
public void testPRTXGetEntryOnRemoteSide() {
    Host host = Host.getHost(0);
    VM accessor = host.getVM(0);
    VM datastore = host.getVM(1);
    initAccessorAndDataStore(accessor, datastore, 0);
    datastore.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            return null;
        }
    });
    accessor.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Region cust = getCache().getRegion(CUSTOMER);
            CustId sup = new CustId(7);
            Region.Entry e = cust.getEntry(sup);
            assertNull(e);
            CustId custId = new CustId(5);
            cust.put(custId, new Customer("customer5", "address5"));
            Region.Entry ee = cust.getEntry(custId);
            assertNotNull(ee);
            CacheTransactionManager mgr = getGemfireCache().getTxManager();
            mgr.begin();
            Region.Entry e2 = cust.getEntry(sup);
            assertNull(e2);
            mgr.commit();
            Region.Entry e3 = cust.getEntry(sup);
            assertNull(e3);
            mgr.begin();
            Customer dawg = new Customer("dawg", "dawgaddr");
            cust.put(sup, dawg);
            Region.Entry e4 = cust.getEntry(sup);
            assertNotNull(e4);
            assertEquals(dawg, e4.getValue());
            mgr.commit();
            Region.Entry e5 = cust.getEntry(sup);
            assertNotNull(e5);
            assertEquals(dawg, e5.getValue());
            return null;
        }
    });
}
Also used : Entry(org.apache.geode.cache.Region.Entry) 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) Region(org.apache.geode.cache.Region) 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) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) TXExpiryJUnitTest(org.apache.geode.TXExpiryJUnitTest) Test(org.junit.Test)

Example 42 with Customer

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

the class RemoteTransactionDUnitTest method doTestBasicBulkOP.

private void doTestBasicBulkOP(final OP op) {
    Host host = Host.getHost(0);
    VM accessor = host.getVM(0);
    VM datastore1 = host.getVM(1);
    VM datastore2 = host.getVM(2);
    initAccessorAndDataStore(accessor, datastore1, datastore2, 1);
    if (op.equals(OP.REMOVEALL)) {
        // for remove all populate more data
        accessor.invoke(new SerializableCallable() {

            @Override
            public Object call() throws Exception {
                Region<CustId, Customer> custRegion = getCache().getRegion(CUSTOMER);
                for (int i = 0; i < 50; i++) {
                    custRegion.put(new CustId(i), new Customer("name" + i, "address" + i));
                }
                return null;
            }
        });
    }
    final List ds1Buckets = (List) datastore1.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            // do local operations with rollback and then commit
            Map<CustId, Customer> custMap = new HashMap<>();
            Region<CustId, Customer> custRegion = getCache().getRegion(CUSTOMER);
            PartitionedRegion pr = ((PartitionedRegion) custRegion);
            List localBuckets = pr.getLocalPrimaryBucketsListTestOnly();
            System.out.println("localBuckets:" + localBuckets);
            for (int i = 10; i < 20; i++) {
                int hash = PartitionedRegionHelper.getHashKey(i, pr.getPartitionAttributes().getTotalNumBuckets());
                if (localBuckets.contains(hash)) {
                    custMap.put(new CustId(i), new Customer("name" + i, "address" + i));
                }
            }
            System.out.println("SWAP:custMap:" + custMap);
            int regionSize = custRegion.size();
            getCache().getCacheTransactionManager().begin();
            if (op.equals(OP.PUTALL)) {
                custRegion.putAll(custMap);
            } else {
                custRegion.removeAll(custMap.keySet());
            }
            getCache().getCacheTransactionManager().rollback();
            assertEquals(regionSize, custRegion.size());
            // now commit
            getCache().getCacheTransactionManager().begin();
            if (op.equals(OP.PUTALL)) {
                custRegion.putAll(custMap);
            } else {
                custRegion.removeAll(custMap.keySet());
            }
            getCache().getCacheTransactionManager().commit();
            assertEquals(getExpectedSize(custMap, regionSize), custRegion.size());
            // bulk op on other member
            custMap.clear();
            for (int i = 10; i < 20; i++) {
                int hash = PartitionedRegionHelper.getHashKey(i, pr.getPartitionAttributes().getTotalNumBuckets());
                if (!localBuckets.contains(hash)) {
                    // not on local member
                    custMap.put(new CustId(i), new Customer("name" + i, "address" + i));
                }
            }
            System.out.println("SWAP:custMap:" + custMap);
            regionSize = custRegion.size();
            getCache().getCacheTransactionManager().begin();
            if (op.equals(OP.PUTALL)) {
                custRegion.putAll(custMap);
            } else {
                custRegion.removeAll(custMap.keySet());
            }
            getCache().getCacheTransactionManager().rollback();
            assertEquals(regionSize, custRegion.size());
            // now commit
            getCache().getCacheTransactionManager().begin();
            if (op.equals(OP.PUTALL)) {
                custRegion.putAll(custMap);
            } else {
                custRegion.removeAll(custMap.keySet());
            }
            getCache().getCacheTransactionManager().commit();
            assertEquals(getExpectedSize(custMap, regionSize), custRegion.size());
            return localBuckets;
        }

        private int getExpectedSize(Map<CustId, Customer> custMap, int regionSize) {
            if (op.equals(OP.REMOVEALL)) {
                return regionSize - custMap.size();
            }
            return regionSize + custMap.size();
        }
    });
    accessor.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            // do a transaction on one of the nodes
            Map<CustId, Customer> custMap = new HashMap<>();
            Region<CustId, Customer> custRegion = getCache().getRegion(CUSTOMER);
            for (int i = 20; i < 30; i++) {
                int hash = PartitionedRegionHelper.getHashKey(i, custRegion.getAttributes().getPartitionAttributes().getTotalNumBuckets());
                if (ds1Buckets.contains(hash)) {
                    custMap.put(new CustId(i), new Customer("name" + i, "address" + i));
                }
            }
            System.out.println("SWAP:custMap:" + custMap);
            int regionSize = custRegion.size();
            getCache().getCacheTransactionManager().begin();
            if (op.equals(OP.PUTALL)) {
                custRegion.putAll(custMap);
            } else {
                custRegion.removeAll(custMap.keySet());
            }
            getCache().getCacheTransactionManager().rollback();
            assertEquals(regionSize, custRegion.size());
            // now commit
            getCache().getCacheTransactionManager().begin();
            if (op.equals(OP.PUTALL)) {
                custRegion.putAll(custMap);
            } else {
                custRegion.removeAll(custMap.keySet());
            }
            getCache().getCacheTransactionManager().commit();
            assertEquals(getExpectedSize(custMap, regionSize), custRegion.size());
            return null;
        }

        private int getExpectedSize(Map<CustId, Customer> custMap, int regionSize) {
            if (op.equals(OP.REMOVEALL)) {
                return regionSize - custMap.size();
            }
            return regionSize + custMap.size();
        }
    });
}
Also used : Customer(org.apache.geode.internal.cache.execute.data.Customer) HashMap(java.util.HashMap) 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) 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) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap)

Example 43 with Customer

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

the class RemoteTransactionDUnitTest method testEntriesIterationOnRR.

@Test
public void testEntriesIterationOnRR() {
    Host host = Host.getHost(0);
    VM accessor = host.getVM(0);
    VM datastore1 = host.getVM(1);
    VM datastore2 = host.getVM(2);
    initAccessorAndDataStore(accessor, datastore1, datastore2, 0);
    accessor.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Region custRegion = getGemfireCache().getRegion(CUSTOMER);
            Region rr = getGemfireCache().getRegion(D_REFERENCE);
            TXManagerImpl mgr = getGemfireCache().getTxManager();
            mgr.begin();
            CustId custId = new CustId(5);
            Customer customer = new Customer("customer5", "address5");
            custRegion.put(custId, customer);
            Set set = rr.entrySet();
            Iterator it = set.iterator();
            int i = 0;
            while (it.hasNext()) {
                i++;
                it.next();
            }
            assertEquals(5, i);
            // assertTrue(getCustIdSet(5).equals(set));
            assertEquals(5, rr.entrySet().size());
            rr.put(custId, customer);
            set = rr.entrySet();
            // assertTrue(getCustIdSet(6).equals(set));
            it = set.iterator();
            i = 0;
            while (it.hasNext()) {
                i++;
                it.next();
            }
            assertEquals(6, i);
            assertEquals(6, rr.entrySet().size());
            assertNotNull(rr.get(custId));
            TXStateProxy tx = mgr.internalSuspend();
            // assertIndexDetailsEquals(getCustIdSet(5), rr.entrySet());
            assertEquals(5, rr.entrySet().size());
            assertNull(rr.get(custId));
            mgr.internalResume(tx);
            mgr.commit();
            return null;
        }
    });
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) 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) Iterator(java.util.Iterator) Region(org.apache.geode.cache.Region) 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) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) TXExpiryJUnitTest(org.apache.geode.TXExpiryJUnitTest) Test(org.junit.Test)

Example 44 with Customer

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

the class RemoteTransactionDUnitTest method doNonColocatedbulkOp.

private void doNonColocatedbulkOp(final OP op) {
    Host host = Host.getHost(0);
    VM accessor = host.getVM(0);
    VM datastore1 = host.getVM(1);
    VM datastore2 = host.getVM(2);
    initAccessorAndDataStore(accessor, datastore1, datastore2, 0);
    accessor.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Map custMap = new HashMap();
            for (int i = 0; i < 10; i++) {
                CustId cId = new CustId(i);
                Customer c = new Customer("name" + i, "addr" + i);
                custMap.put(cId, c);
            }
            GemFireCacheImpl cache = getGemfireCache();
            cache.getCacheTransactionManager().begin();
            Region r = cache.getRegion(CUSTOMER);
            try {
                switch(op) {
                    case PUTALL:
                        r.putAll(custMap);
                        break;
                    case GETALL:
                        r.put(new CustId(1), new Customer("cust1", "addr1"));
                        r.getAll(custMap.keySet());
                        break;
                    default:
                        break;
                }
                fail("expected exception not thrown");
            } catch (TransactionDataNotColocatedException e) {
            }
            cache.getCacheTransactionManager().rollback();
            return null;
        }
    });
}
Also used : HashMap(java.util.HashMap) CustId(org.apache.geode.internal.cache.execute.data.CustId) Customer(org.apache.geode.internal.cache.execute.data.Customer) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Region(org.apache.geode.cache.Region) Host(org.apache.geode.test.dunit.Host) Map(java.util.Map) HashMap(java.util.HashMap) 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)

Example 45 with Customer

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

the class RemoteTransactionDUnitTest method testTXWithRICommitInDatastore.

@Test
public void testTXWithRICommitInDatastore() throws Exception {
    Host host = Host.getHost(0);
    VM accessor = host.getVM(0);
    VM datastore = host.getVM(1);
    VM client = host.getVM(2);
    initAccessorAndDataStore(accessor, datastore, 0);
    int port = startServer(datastore);
    createClientRegion(client, port, false, true);
    datastore.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Region<CustId, Customer> custRegion = getCache().getRegion(CUSTOMER);
            Region<OrderId, Order> orderRegion = getCache().getRegion(ORDER);
            Region<CustId, Customer> refRegion = getCache().getRegion(D_REFERENCE);
            CustId custId = new CustId(1);
            OrderId orderId = new OrderId(1, custId);
            getCache().getCacheTransactionManager().begin();
            custRegion.put(custId, new Customer("foo", "bar"));
            orderRegion.put(orderId, new Order("fooOrder"));
            refRegion.put(custId, new Customer("foo", "bar"));
            getCache().getCacheTransactionManager().commit();
            return null;
        }
    });
    client.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Region<CustId, Customer> custRegion = getCache().getRegion(CUSTOMER);
            Region<OrderId, Order> orderRegion = getCache().getRegion(ORDER);
            Region<CustId, Customer> refRegion = getCache().getRegion(D_REFERENCE);
            final ClientListener cl = (ClientListener) custRegion.getAttributes().getCacheListeners()[0];
            WaitCriterion waitForListenerInvocation = new WaitCriterion() {

                public boolean done() {
                    return cl.invoked;
                }

                public String description() {
                    return "listener was never invoked";
                }
            };
            Wait.waitForCriterion(waitForListenerInvocation, 10 * 1000, 10, true);
            return null;
        }
    });
}
Also used : Order(org.apache.geode.internal.cache.execute.data.Order) Customer(org.apache.geode.internal.cache.execute.data.Customer) Host(org.apache.geode.test.dunit.Host) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) 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) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) 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) 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