Search in sources :

Example 56 with Customer

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

the class RemoteTransactionDUnitTest method testTxRemoveAllWithRedundancy.

@Test
public void testTxRemoveAllWithRedundancy() {
    Host host = Host.getHost(0);
    VM acc = host.getVM(0);
    VM datastore1 = host.getVM(1);
    VM datastore2 = host.getVM(3);
    // Create a second data store.
    datastore2.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            createRegion(false, /* accessor */
            1, null);
            return null;
        }
    });
    initAccessorAndDataStore(acc, datastore1, 1);
    VM accessor = getVMForTransactions(acc, datastore1);
    // There are 4 buckets, so 0, 4, and 20 are all colocated
    final CustId custId0 = new CustId(0);
    final CustId custId4 = new CustId(4);
    final CustId custId20 = new CustId(20);
    final TXId txId = (TXId) accessor.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Region<CustId, Customer> cust = getGemfireCache().getRegion(CUSTOMER);
            Region<CustId, Customer> ref = getGemfireCache().getRegion(D_REFERENCE);
            TXManagerImpl mgr = getGemfireCache().getTxManager();
            mgr.begin();
            cust.removeAll(Arrays.asList(custId0, custId4));
            mgr.commit();
            assertNull(cust.get(custId0));
            assertNull(cust.get(custId4));
            return mgr.getTransactionId();
        }
    });
    SerializableCallable checkArtifacts = new SerializableCallable() {

        public Object call() throws Exception {
            PartitionedRegion cust = (PartitionedRegion) getGemfireCache().getRegion(CUSTOMER);
            assertNull(cust.get(custId0));
            assertNull(cust.get(custId4));
            return null;
        }
    };
    datastore1.invoke(checkArtifacts);
    datastore2.invoke(checkArtifacts);
}
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) 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 57 with Customer

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

the class RemoteTransactionDUnitTest method testRemoteTxCleanupOnCrash.

@Test
public void testRemoteTxCleanupOnCrash() {
    Host host = Host.getHost(0);
    VM accessor = host.getVM(0);
    VM datastore = host.getVM(1);
    initAccessorAndDataStore(accessor, datastore, 0);
    accessor.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Region cust = getGemfireCache().getRegion(CUSTOMER);
            TXManagerImpl mgr = getGemfireCache().getTxManager();
            mgr.begin();
            cust.put(new CustId(6), new Customer("customer6", "address6"));
            return null;
        }
    });
    final InternalDistributedMember member = (InternalDistributedMember) accessor.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            return getGemfireCache().getMyId();
        }
    });
    datastore.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            TXManagerImpl mgr = getGemfireCache().getTxManager();
            assertEquals(1, mgr.hostedTransactionsInProgressForTest());
            mgr.memberDeparted(member, true);
            assertEquals(0, mgr.hostedTransactionsInProgressForTest());
            return null;
        }
    });
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) 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) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) TXExpiryJUnitTest(org.apache.geode.TXExpiryJUnitTest) Test(org.junit.Test)

Example 58 with Customer

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

the class RemoteTransactionDUnitTest method populateData.

void populateData() {
    Region custRegion = getCache().getRegion(CUSTOMER);
    Region orderRegion = getCache().getRegion(ORDER);
    Region refRegion = getCache().getRegion(D_REFERENCE);
    for (int i = 0; i < 5; 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);
        refRegion.put(custId, customer);
    }
}
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) Region(org.apache.geode.cache.Region) OrderId(org.apache.geode.internal.cache.execute.data.OrderId)

Example 59 with Customer

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

the class RemoteTransactionDUnitTest method testTxRemoveAll.

@Test
public void testTxRemoveAll() {
    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 CustId custId1 = new CustId(1);
    final CustId custId2 = new CustId(2);
    final CustId custId20 = new CustId(20);
    final TXId txId = (TXId) accessor.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Region<CustId, Customer> cust = getGemfireCache().getRegion(CUSTOMER);
            Region<CustId, Customer> ref = getGemfireCache().getRegion(D_REFERENCE);
            TXManagerImpl mgr = getGemfireCache().getTxManager();
            mgr.begin();
            Customer customer = new Customer("customer1", "address1");
            Customer customer2 = new Customer("customer2", "address2");
            Customer fakeCust = new Customer("foo2", "bar2");
            cust.removeAll(Arrays.asList(custId1, custId2, custId20));
            ref.removeAll(Arrays.asList(custId1, custId2, custId20));
            TXStateProxy tx = mgr.internalSuspend();
            assertNotNull(cust.get(custId1));
            assertNotNull(ref.get(custId2));
            mgr.internalResume(tx);
            return mgr.getTransactionId();
        }
    });
    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(4, tx.getRegions().size());
            // different buckets
            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));
                    // custId20 won't be dirty because it doesn't exist.
                    assertTrue("key:" + key + " r:" + r.getFullPath(), key.equals(custId20) || es.isDirty());
                }
            }
            return null;
        }
    });
    accessor.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            TXManagerImpl mgr = getGemfireCache().getTxManager();
            mgr.commit();
            Region<CustId, Customer> cust = getGemfireCache().getRegion(CUSTOMER);
            Region<CustId, Customer> rr = getGemfireCache().getRegion(D_REFERENCE);
            assertNull(cust.get(custId1));
            assertNull(rr.get(custId2));
            // check conflict
            mgr.begin();
            CustId custId3 = new CustId(3);
            CustId custId4 = new CustId(4);
            getGemfireCache().getLoggerI18n().fine("SWAP:removeConflict");
            cust.removeAll(Arrays.asList(custId3, custId20, custId4));
            TXStateProxy tx = mgr.internalSuspend();
            // cust.put(custId3, new Customer("foo", "bar"));
            cust.put(custId20, new Customer("foo", "bar"));
            assertNotNull(cust.get(custId20));
            cust.put(custId4, new Customer("foo", "bar"));
            mgr.internalResume(tx);
            try {
                mgr.commit();
                fail("expected exception not thrown");
            } catch (CommitConflictException e) {
            }
            assertNotNull(cust.get(custId3));
            assertNotNull(cust.get(custId4));
            assertNotNull(cust.get(custId20));
            // Test a removeall an already missing key.
            // custId2 has already been removed
            mgr.begin();
            getGemfireCache().getLoggerI18n().fine("SWAP:removeConflict");
            cust.removeAll(Arrays.asList(custId2, custId3));
            tx = mgr.internalSuspend();
            cust.put(custId2, new Customer("foo", "bar"));
            mgr.internalResume(tx);
            mgr.commit();
            assertNotNull(cust.get(custId2));
            assertNull(cust.get(custId3));
            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) 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) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) TXExpiryJUnitTest(org.apache.geode.TXExpiryJUnitTest) Test(org.junit.Test)

Example 60 with Customer

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

the class RemoteTransactionDUnitTest method doRemoteJTA.

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

        public Object call() throws Exception {
            getGemfireCache().getTxManager().addListener(new TestTxListener(false));
            return null;
        }
    });
    final CustId expectedCustId = new CustId(6);
    final Customer expectedCustomer = new Customer("customer6", "address6");
    accessor.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            getGemfireCache().getTxManager().addListener(new TestTxListener(true));
            Region custRegion = getCache().getRegion(CUSTOMER);
            Context ctx = getCache().getJNDIContext();
            UserTransaction tx = (UserTransaction) ctx.lookup("java:/UserTransaction");
            assertEquals(Status.STATUS_NO_TRANSACTION, tx.getStatus());
            tx.begin();
            assertEquals(Status.STATUS_ACTIVE, tx.getStatus());
            custRegion.put(expectedCustId, expectedCustomer);
            assertEquals(expectedCustomer, custRegion.get(expectedCustId));
            return null;
        }
    });
    datastore.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Region custRegion = getCache().getRegion(CUSTOMER);
            assertNull(custRegion.get(expectedCustId));
            return null;
        }
    });
    accessor.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Region custRegion = getCache().getRegion(CUSTOMER);
            Context ctx = getCache().getJNDIContext();
            UserTransaction tx = (UserTransaction) ctx.lookup("java:/UserTransaction");
            if (isCommit) {
                tx.commit();
                assertEquals(expectedCustomer, custRegion.get(expectedCustId));
            } else {
                tx.rollback();
                assertNull(custRegion.get(expectedCustId));
            }
            return null;
        }
    });
    datastore.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            TestTxListener l = (TestTxListener) getGemfireCache().getTXMgr().getListener();
            assertTrue(l.isListenerInvoked());
            return null;
        }
    });
}
Also used : FunctionContext(org.apache.geode.cache.execute.FunctionContext) Context(javax.naming.Context) RegionFunctionContext(org.apache.geode.cache.execute.RegionFunctionContext) UserTransaction(javax.transaction.UserTransaction) 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)

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