Search in sources :

Example 66 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 67 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)

Example 68 with CacheTransactionManager

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

the class RemoteTransactionDUnitTest method testTXDestroy.

@Test
public void testTXDestroy() {
    Host host = Host.getHost(0);
    VM acc = host.getVM(0);
    VM datastore = host.getVM(1);
    initAccessorAndDataStore(acc, datastore, 0);
    VM accessor = getVMForTransactions(acc, datastore);
    final TXId txId = (TXId) accessor.invoke(new DoOpsInTX(OP.DESTROY));
    datastore.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            TXManagerImpl mgr = getGemfireCache().getTxManager();
            assertTrue(mgr.isHostedTxInProgress(txId));
            TXStateProxy tx = mgr.getHostedTXState(txId);
            // 2 buckets for the two puts we
            assertEquals(3, tx.getRegions().size());
            // plus the dist. region
            for (LocalRegion r : tx.getRegions()) {
                assertTrue(r instanceof BucketRegion || r instanceof DistributedRegion);
                TXRegionState rs = tx.readRegion(r);
                for (Object key : rs.getEntryKeys()) {
                    TXEntryState es = rs.readEntry(key);
                    assertNull(es.getValue(key, r, false));
                    assertTrue(es.isDirty());
                }
            }
            return null;
        }
    });
    accessor.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            CacheTransactionManager mgr = getGemfireCache().getTxManager();
            mgr.commit();
            verifyAfterCommit(OP.DESTROY);
            return null;
        }
    });
}
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) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) TXExpiryJUnitTest(org.apache.geode.TXExpiryJUnitTest) Test(org.junit.Test)

Example 69 with CacheTransactionManager

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

the class RemoteTransactionDUnitTest method testPRTXGetOnLocalWithLoader.

@Test
public void testPRTXGetOnLocalWithLoader() {
    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 {
            AttributesMutator am = getCache().getRegion(CUSTOMER).getAttributesMutator();
            am.setCacheLoader(new CacheLoader() {

                public Object load(LoaderHelper helper) throws CacheLoaderException {
                    return new Customer("sup dawg", "addr");
                }

                public void close() {
                }
            });
            CacheTransactionManager mgr = getGemfireCache().getTxManager();
            mgr.begin();
            Region cust = getCache().getRegion(CUSTOMER);
            CustId custId = new CustId(6);
            Customer s = (Customer) cust.get(custId);
            mgr.commit();
            Customer s2 = (Customer) cust.get(custId);
            Customer expectedCust = new Customer("sup dawg", "addr");
            assertEquals(s, expectedCust);
            assertEquals(s2, expectedCust);
            return null;
        }
    });
    accessor.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            return null;
        }
    });
}
Also used : LoaderHelper(org.apache.geode.cache.LoaderHelper) Customer(org.apache.geode.internal.cache.execute.data.Customer) 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) Host(org.apache.geode.test.dunit.Host) CacheLoader(org.apache.geode.cache.CacheLoader) 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) AttributesMutator(org.apache.geode.cache.AttributesMutator) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) TXExpiryJUnitTest(org.apache.geode.TXExpiryJUnitTest) Test(org.junit.Test)

Example 70 with CacheTransactionManager

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

the class RemoteTransactionDUnitTest method testPRTXGetOnRemoteWithLoader.

@Test
public void testPRTXGetOnRemoteWithLoader() {
    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 {
            AttributesMutator am = getCache().getRegion(CUSTOMER).getAttributesMutator();
            am.setCacheLoader(new CacheLoader() {

                public Object load(LoaderHelper helper) throws CacheLoaderException {
                    return new Customer("sup dawg", "add");
                }

                public void close() {
                }
            });
            return null;
        }
    });
    accessor.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            CacheTransactionManager mgr = getGemfireCache().getTxManager();
            mgr.begin();
            Region cust = getCache().getRegion(CUSTOMER);
            Customer s = (Customer) cust.get(new CustId(8));
            assertEquals(new Customer("sup dawg", "add"), s);
            assertTrue(cust.containsKey(new CustId(8)));
            TXStateProxy tx = ((TXManagerImpl) mgr).internalSuspend();
            assertFalse(cust.containsKey(new CustId(8)));
            ((TXManagerImpl) mgr).internalResume(tx);
            mgr.commit();
            Customer s2 = (Customer) cust.get(new CustId(8));
            Customer ex = new Customer("sup dawg", "add");
            assertEquals(ex, s);
            assertEquals(ex, s2);
            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) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) LoaderHelper(org.apache.geode.cache.LoaderHelper) 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) CacheLoader(org.apache.geode.cache.CacheLoader) AttributesMutator(org.apache.geode.cache.AttributesMutator) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) TXExpiryJUnitTest(org.apache.geode.TXExpiryJUnitTest) Test(org.junit.Test)

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