Search in sources :

Example 96 with CacheTransactionManager

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

the class RemoteTransactionDUnitTest method doTestIterator.

private void doTestIterator(final OP iteratorType, final int redundancy, 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, redundancy);
    accessor.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Region custRegion = getCache().getRegion(CUSTOMER);
            Set originalSet;
            TXManagerImpl mgr = getGemfireCache().getTxManager();
            mgr.begin();
            switch(iteratorType) {
                case KEYS:
                    originalSet = getCustIdSet(5);
                    assertTrue(originalSet.containsAll(custRegion.keySet()));
                    assertEquals(5, custRegion.keySet().size());
                    break;
                case VALUES:
                    originalSet = getCustomerSet(5);
                    assertTrue(originalSet.containsAll(custRegion.values()));
                    assertEquals(5, custRegion.values().size());
                    break;
                case ENTRIES:
                    Set originalKeySet = getCustIdSet(5);
                    Set originalValueSet = getCustomerSet(5);
                    Set entrySet = new HashSet();
                    Region.Entry entry;
                    for (Iterator it = custRegion.entrySet().iterator(); it.hasNext(); ) {
                        entrySet.add(it.next());
                    }
                    for (Iterator it = entrySet.iterator(); it.hasNext(); ) {
                        entry = (Entry) it.next();
                        assertTrue(originalKeySet.contains(entry.getKey()));
                        assertTrue(originalValueSet.contains(entry.getValue()));
                    }
                    assertEquals(5, custRegion.entrySet().size());
                    break;
                default:
                    throw new IllegalArgumentException();
            }
            assertNotNull(mgr.getTXState());
            return null;
        }
    });
    datastore1.invoke(verifyNoTxState);
    datastore2.invoke(verifyNoTxState);
    accessor.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Region custRegion = getCache().getRegion(CUSTOMER);
            Region orderRegion = getCache().getRegion(ORDER);
            TXManagerImpl mgr = getGemfireCache().getTxManager();
            assertNotNull(mgr.getTXState());
            int expectedSetSize = 0;
            switch(op) {
                case PUT:
                    CustId custId = new CustId(5);
                    OrderId orderId = new OrderId(5, custId);
                    custRegion.put(custId, new Customer("customer5", "address5"));
                    orderRegion.put(orderId, new Order("order5"));
                    expectedSetSize = 6;
                    break;
                case DESTROY:
                    CustId custId1 = new CustId(4);
                    OrderId orderId1 = new OrderId(4, custId1);
                    custRegion.destroy(custId1);
                    orderRegion.destroy(orderId1);
                    expectedSetSize = 4;
                    break;
                default:
                    throw new IllegalStateException();
            }
            Set expectedSet;
            switch(iteratorType) {
                case KEYS:
                    expectedSet = getCustIdSet(expectedSetSize);
                    assertTrue(expectedSet.containsAll(custRegion.keySet()));
                    assertEquals(expectedSetSize, custRegion.keySet().size());
                    break;
                case VALUES:
                    expectedSet = getCustomerSet(expectedSetSize);
                    assertTrue(expectedSet.containsAll(custRegion.values()));
                    assertEquals(expectedSetSize, custRegion.values().size());
                    break;
                case ENTRIES:
                    Set originalKeySet = getCustIdSet(expectedSetSize);
                    Set originalValueSet = getCustomerSet(expectedSetSize);
                    Set entrySet = new HashSet();
                    Region.Entry entry;
                    for (Iterator it = custRegion.entrySet().iterator(); it.hasNext(); ) {
                        entrySet.add(it.next());
                    }
                    for (Iterator it = entrySet.iterator(); it.hasNext(); ) {
                        entry = (Entry) it.next();
                        assertTrue(originalKeySet.contains(entry.getKey()));
                        assertTrue(originalValueSet.contains(entry.getValue()));
                    }
                    assertEquals(expectedSetSize, custRegion.entrySet().size());
                    break;
                default:
                    throw new IllegalArgumentException();
            }
            return null;
        }
    });
    final Integer txOnDatastore1 = (Integer) datastore1.invoke(getNumberOfTXInProgress);
    final Integer txOnDatastore2 = (Integer) datastore2.invoke(getNumberOfTXInProgress);
    assertEquals(1, txOnDatastore1 + txOnDatastore2);
    accessor.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            CacheTransactionManager mgr = getGemfireCache().getTxManager();
            mgr.commit();
            return null;
        }
    });
    final Integer txOnDatastore1_1 = (Integer) datastore1.invoke(getNumberOfTXInProgress);
    final Integer txOnDatastore2_2 = (Integer) datastore2.invoke(getNumberOfTXInProgress);
    assertEquals(0, txOnDatastore1_1 + txOnDatastore2_2);
    datastore1.invoke(new SerializableCallable() {

        CustId custId;

        Customer customer;

        PartitionedRegion custRegion;

        int originalSetSize;

        int expectedSetSize;

        public Object call() throws Exception {
            TXManagerImpl mgr = getGemfireCache().getTXMgr();
            custRegion = (PartitionedRegion) getGemfireCache().getRegion(CUSTOMER);
            mgr.begin();
            doLocalOp();
            Set expectedSet;
            switch(iteratorType) {
                case KEYS:
                    expectedSet = getExpectedCustIdSet();
                    assertEquals(expectedSet, custRegion.keySet());
                    assertEquals(expectedSetSize, custRegion.keySet().size());
                    break;
                case VALUES:
                    expectedSet = getExpectedCustomerSet();
                    assertEquals(expectedSet, custRegion.values());
                    assertEquals(expectedSetSize, custRegion.values().size());
                    break;
                case ENTRIES:
                    Set originalKeySet = getExpectedCustIdSet();
                    Set originalValueSet = getExpectedCustomerSet();
                    Set entrySet = new HashSet();
                    Region.Entry entry;
                    for (Iterator it = custRegion.entrySet().iterator(); it.hasNext(); ) {
                        entrySet.add(it.next());
                    }
                    for (Iterator it = entrySet.iterator(); it.hasNext(); ) {
                        entry = (Entry) it.next();
                        assertTrue(originalKeySet.contains(entry.getKey()));
                        assertTrue(originalValueSet.contains(entry.getValue()));
                    }
                    assertEquals(expectedSetSize, custRegion.entrySet().size());
                    break;
                default:
                    throw new IllegalArgumentException();
            }
            mgr.commit();
            return null;
        }

        private void doLocalOp() {
            switch(op) {
                case PUT:
                    for (int i = 6; ; i++) {
                        custId = new CustId(i);
                        customer = new Customer("customer" + i, "address" + i);
                        int bucketId = PartitionedRegionHelper.getHashKey(custRegion, custId);
                        InternalDistributedMember primary = custRegion.getBucketPrimary(bucketId);
                        if (primary.equals(getGemfireCache().getMyId())) {
                            custRegion.put(custId, customer);
                            break;
                        }
                    }
                    originalSetSize = 6;
                    expectedSetSize = 7;
                    break;
                case DESTROY:
                    for (int i = 3; ; i--) {
                        custId = new CustId(i);
                        customer = new Customer("customer" + i, "address" + i);
                        int bucketId = PartitionedRegionHelper.getHashKey(custRegion, custId);
                        InternalDistributedMember primary = custRegion.getBucketPrimary(bucketId);
                        if (primary.equals(getGemfireCache().getMyId())) {
                            custRegion.destroy(custId);
                            break;
                        }
                    }
                    originalSetSize = 4;
                    expectedSetSize = 3;
                    break;
                default:
                    throw new IllegalStateException();
            }
        }

        private Set getExpectedCustIdSet() {
            Set retVal = getCustIdSet(originalSetSize);
            switch(op) {
                case PUT:
                    retVal.add(custId);
                    break;
                case DESTROY:
                    retVal.remove(custId);
                    break;
                default:
                    throw new IllegalStateException();
            }
            return retVal;
        }

        private Set getExpectedCustomerSet() {
            Set retVal = getCustomerSet(originalSetSize);
            switch(op) {
                case PUT:
                    retVal.add(customer);
                    break;
                case DESTROY:
                    retVal.remove(customer);
                    break;
                default:
                    throw new IllegalStateException();
            }
            return retVal;
        }
    });
}
Also used : Order(org.apache.geode.internal.cache.execute.data.Order) Set(java.util.Set) HashSet(java.util.HashSet) 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) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) Entry(org.apache.geode.cache.Region.Entry) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) CustId(org.apache.geode.internal.cache.execute.data.CustId) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Iterator(java.util.Iterator) Region(org.apache.geode.cache.Region) HashSet(java.util.HashSet)

Example 97 with CacheTransactionManager

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

the class RemoteTransactionDUnitTest method doTestListeners.

private void doTestListeners(final OP op) {
    Host host = Host.getHost(0);
    VM acc = host.getVM(0);
    VM datastore = host.getVM(1);
    initAccessorAndDataStore(acc, datastore, 0);
    VM accessor = getVMForTransactions(acc, datastore);
    accessor.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Region ref = getCache().getRegion(D_REFERENCE);
            ref.getAttributesMutator().addCacheListener(new TestCacheListener(true));
            ref.getAttributesMutator().setCacheWriter(new TestCacheWriter(true));
            Region cust = getCache().getRegion(CUSTOMER);
            cust.getAttributesMutator().addCacheListener(new TestCacheListener(true));
            cust.getAttributesMutator().setCacheWriter(new TestCacheWriter(true));
            Region order = getCache().getRegion(ORDER);
            order.getAttributesMutator().addCacheListener(new TestCacheListener(true));
            order.getAttributesMutator().setCacheWriter(new TestCacheWriter(true));
            getGemfireCache().getTxManager().addListener(new TestTxListener(true));
            if (!getGemfireCache().isClient()) {
                getGemfireCache().getTxManager().setWriter(new TestTxWriter(true));
            }
            return null;
        }
    });
    SerializableCallable addListenersToDataStore = new SerializableCallable() {

        public Object call() throws Exception {
            Region ref = getCache().getRegion(D_REFERENCE);
            ref.getAttributesMutator().addCacheListener(new TestCacheListener(false));
            ref.getAttributesMutator().setCacheWriter(new TestCacheWriter(false));
            Region cust = getCache().getRegion(CUSTOMER);
            cust.getAttributesMutator().addCacheListener(new TestCacheListener(false));
            cust.getAttributesMutator().setCacheWriter(new TestCacheWriter(false));
            Region order = getCache().getRegion(ORDER);
            order.getAttributesMutator().addCacheListener(new TestCacheListener(false));
            order.getAttributesMutator().setCacheWriter(new TestCacheWriter(false));
            getGemfireCache().getTxManager().addListener(new TestTxListener(false));
            if (!getGemfireCache().isClient()) {
                getGemfireCache().getTxManager().setWriter(new TestTxWriter(false));
            }
            return null;
        }
    };
    datastore.invoke(addListenersToDataStore);
    accessor.invoke(new DoOpsInTX(op));
    // Invalidate operations don't fire cache writers, so don't assert they were fired.
    if (op != OP.INVALIDATE) {
        // Ensure the cache writer was not fired in accessor
        accessor.invoke(new SerializableCallable() {

            public Object call() throws Exception {
                Region cust = getCache().getRegion(CUSTOMER);
                assertFalse(((TestCacheWriter) cust.getAttributes().getCacheWriter()).wasFired);
                Region order = getCache().getRegion(ORDER);
                assertFalse(((TestCacheWriter) order.getAttributes().getCacheWriter()).wasFired);
                Region ref = getCache().getRegion(D_REFERENCE);
                assertFalse(((TestCacheWriter) ref.getAttributes().getCacheWriter()).wasFired);
                return null;
            }
        });
        // Ensure the cache writer was fired in the primary
        datastore.invoke(new SerializableCallable() {

            public Object call() throws Exception {
                Region cust = getCache().getRegion(CUSTOMER);
                assertTrue(((TestCacheWriter) cust.getAttributes().getCacheWriter()).wasFired);
                Region order = getCache().getRegion(ORDER);
                assertTrue(((TestCacheWriter) order.getAttributes().getCacheWriter()).wasFired);
                Region ref = getCache().getRegion(D_REFERENCE);
                assertTrue(((TestCacheWriter) ref.getAttributes().getCacheWriter()).wasFired);
                return null;
            }
        });
    }
    accessor.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            CacheTransactionManager mgr = getGemfireCache().getTxManager();
            mgr.commit();
            return null;
        }
    });
    datastore.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            TestTxListener l = (TestTxListener) getGemfireCache().getTxManager().getListener();
            assertTrue(l.isListenerInvoked());
            return null;
        }
    });
    SerializableCallable verifyListeners = new SerializableCallable() {

        public Object call() throws Exception {
            Region cust = getCache().getRegion(CUSTOMER);
            Region order = getCache().getRegion(ORDER);
            throwListenerException(cust);
            throwListenerException(order);
            throwWriterException(cust);
            throwWriterException(order);
            if (!getGemfireCache().isClient()) {
                throwTransactionCallbackException();
            }
            return null;
        }

        private void throwTransactionCallbackException() throws Exception {
            TestTxListener l = (TestTxListener) getGemfireCache().getTxManager().getListener();
            if (l.ex != null) {
                throw l.ex;
            }
            TestTxWriter w = (TestTxWriter) getGemfireCache().getTxManager().getWriter();
            if (w.ex != null) {
                throw w.ex;
            }
        }

        private void throwListenerException(Region r) throws Exception {
            Exception e = null;
            CacheListener listener = r.getAttributes().getCacheListeners()[0];
            if (listener instanceof TestCacheListener) {
                e = ((TestCacheListener) listener).ex;
            } else {
            // e = ((ClientListener)listener).???
            }
            if (e != null) {
                throw e;
            }
        }

        private void throwWriterException(Region r) throws Exception {
            Exception e = null;
            CacheListener listener = r.getAttributes().getCacheListeners()[0];
            if (listener instanceof TestCacheListener) {
                e = ((TestCacheListener) listener).ex;
            } else {
            // e = ((ClientListener)listener).???
            }
            if (e != null) {
                throw e;
            }
        }
    };
    accessor.invoke(verifyListeners);
    datastore.invoke(verifyListeners);
}
Also used : 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) CacheListener(org.apache.geode.cache.CacheListener) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Region(org.apache.geode.cache.Region)

Example 98 with CacheTransactionManager

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

the class RemoteTransactionDUnitTest method testNonColocatedTX.

/**
   * When we have narrowed down on a target node for a transaction, test that we throw an exception
   * if that node does not host primary for subsequent entries
   */
@Test
public void testNonColocatedTX() {
    Host host = Host.getHost(0);
    VM accessor = host.getVM(0);
    VM datastore1 = host.getVM(1);
    VM datastore2 = host.getVM(2);
    datastore2.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            createRegion(false, 1, null);
            return null;
        }
    });
    initAccessorAndDataStore(accessor, datastore1, 1);
    accessor.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Region<CustId, Customer> custRegion = getCache().getRegion(CUSTOMER);
            Region<OrderId, Order> orderRegion = getCache().getRegion(ORDER);
            CacheTransactionManager mgr = getGemfireCache().getTxManager();
            mgr.begin();
            try {
                put10Entries(custRegion, orderRegion);
                fail("Expected TransactionDataNotColocatedException not thrown");
            } catch (TransactionDataNotColocatedException e) {
            }
            mgr.rollback();
            put10Entries(custRegion, orderRegion);
            mgr.begin();
            try {
                put10Entries(custRegion, orderRegion);
                fail("Expected TransactionDataNotColocatedException not thrown");
            } catch (TransactionDataNotColocatedException e) {
            }
            mgr.rollback();
            return null;
        }

        private void put10Entries(Region custRegion, Region orderRegion) {
            for (int i = 0; i < 10; i++) {
                CustId custId = new CustId(i);
                Customer customer = new Customer("customer" + i, "address" + i);
                OrderId orderId = new OrderId(i, custId);
                Order order = new Order("order" + i);
                custRegion.put(custId, customer);
                orderRegion.put(orderId, order);
            }
        }
    });
}
Also used : Order(org.apache.geode.internal.cache.execute.data.Order) 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) 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) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) TXExpiryJUnitTest(org.apache.geode.TXExpiryJUnitTest) Test(org.junit.Test)

Example 99 with CacheTransactionManager

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

the class RemoteTransactionDUnitTest method testBug49398.

@Test
public void testBug49398() {
    disconnectAllFromDS();
    Host host = Host.getHost(0);
    VM vm1 = host.getVM(0);
    VM vm2 = host.getVM(1);
    final String lrName = getName() + "_lr";
    SerializableCallable createRegion = new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            createRegion(false, 1, null);
            getCache().createRegionFactory(RegionShortcut.LOCAL).create(lrName);
            return null;
        }
    };
    vm1.invoke(createRegion);
    vm2.invoke(createRegion);
    vm1.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            CacheTransactionManager txMgr = getCache().getCacheTransactionManager();
            Region ref = getCache().getRegion(D_REFERENCE);
            Region lr = getCache().getRegion(lrName);
            txMgr.begin();
            ref.put(new CustId(1), new Customer("name1", "address1"));
            lr.put("key", "value");
            txMgr.commit();
            return null;
        }
    });
    // make sure local region changes are not reflected in the other vm
    vm2.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            Region lr = getCache().getRegion(lrName);
            assertNull(lr.get("key"));
            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) 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 100 with CacheTransactionManager

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

the class RemoteTransactionDUnitTest method doSizeTest.

private void doSizeTest(final boolean isAccessor) {
    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);
    VM taskVM = isAccessor ? accessor : datastore1;
    taskVM.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Region custRegion = getCache().getRegion(CUSTOMER);
            TXManagerImpl mgr = getGemfireCache().getTxManager();
            mgr.begin();
            assertEquals(5, custRegion.size());
            assertNotNull(mgr.getTXState());
            return null;
        }
    });
    datastore1.invoke(verifyNoTxState);
    datastore2.invoke(verifyNoTxState);
    taskVM.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Region custRegion = getCache().getRegion(CUSTOMER);
            Region orderRegion = getCache().getRegion(ORDER);
            TXManagerImpl mgr = getGemfireCache().getTxManager();
            TransactionId txId = mgr.suspend();
            PartitionedRegion custPR = (PartitionedRegion) custRegion;
            int remoteKey = -1;
            for (int i = 100; i < 200; i++) {
                DistributedMember myId = custPR.getMyId();
                if (!myId.equals(custPR.getOwnerForKey(custPR.getKeyInfo(new CustId(i))))) {
                    remoteKey = i;
                    break;
                }
            }
            if (remoteKey == -1) {
                throw new IllegalStateException("expected non-negative key");
            }
            mgr.resume(txId);
            assertNotNull(mgr.getTXState());
            CustId custId = new CustId(remoteKey);
            OrderId orderId = new OrderId(remoteKey, custId);
            custRegion.put(custId, new Customer("customer" + remoteKey, "address" + remoteKey));
            getCache().getLogger().info("Putting " + custId + ", keyInfo:" + custPR.getKeyInfo(new CustId(remoteKey)));
            orderRegion.put(orderId, new Order("order" + remoteKey));
            assertEquals(6, custRegion.size());
            return mgr.getTransactionId();
        }
    });
    final Integer txOnDatastore1 = (Integer) datastore1.invoke(getNumberOfTXInProgress);
    final Integer txOnDatastore2 = (Integer) datastore2.invoke(getNumberOfTXInProgress);
    assertEquals(1, txOnDatastore1 + txOnDatastore2);
    taskVM.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            CacheTransactionManager mgr = getGemfireCache().getTxManager();
            mgr.commit();
            return null;
        }
    });
    datastore1.invoke(verifyNoTxState);
    datastore2.invoke(verifyNoTxState);
    final Integer txOnDatastore1_1 = (Integer) datastore1.invoke(getNumberOfTXInProgress);
    final Integer txOnDatastore2_2 = (Integer) datastore2.invoke(getNumberOfTXInProgress);
    assertEquals(0, txOnDatastore1_1.intValue());
    assertEquals(0, txOnDatastore2_2.intValue());
}
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) TransactionId(org.apache.geode.cache.TransactionId) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) CustId(org.apache.geode.internal.cache.execute.data.CustId) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) Region(org.apache.geode.cache.Region)

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