Search in sources :

Example 71 with Customer

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

the class RemoteTransactionDUnitTest method verifyAfterCommit.

void verifyAfterCommit(OP op) {
    Region<CustId, Customer> custRegion = getCache().getRegion(CUSTOMER);
    Region<CustId, Customer> refRegion = getCache().getRegion(D_REFERENCE);
    Region<OrderId, Order> orderRegion = getCache().getRegion(ORDER);
    CustId custId = new CustId(1);
    OrderId orderId = new OrderId(1, custId);
    OrderId orderId2 = new OrderId(2, custId);
    OrderId orderId3 = new OrderId(3, custId);
    Customer expectedCust;
    Order expectedOrder;
    Order expectedOrder2;
    Order expectedOrder3;
    Customer expectedRef;
    switch(op) {
        case PUT:
            expectedCust = new Customer("foo", "bar");
            expectedOrder = new Order("fooOrder");
            expectedOrder2 = new Order("fooOrder2");
            expectedOrder3 = new Order("fooOrder3");
            expectedRef = expectedCust;
            assertNotNull(custRegion.getEntry(custId));
            assertEquals(expectedCust, custRegion.getEntry(custId).getValue());
            /*
         * assertNotNull(orderRegion.getEntry(orderId)); assertIndexDetailsEquals(expectedOrder,
         * orderRegion.getEntry(orderId).getValue());
         * 
         * assertNotNull(orderRegion.getEntry(orderId2)); assertIndexDetailsEquals(expectedOrder2,
         * orderRegion.getEntry(orderId2).getValue());
         * 
         * assertNotNull(orderRegion.getEntry(orderId3)); assertIndexDetailsEquals(expectedOrder3,
         * orderRegion.getEntry(orderId3).getValue());
         */
            assertNotNull(refRegion.getEntry(custId));
            assertEquals(expectedRef, refRegion.getEntry(custId).getValue());
            // validateContains(custId, ordersSet, true);
            break;
        case GET:
            expectedCust = custRegion.get(custId);
            expectedOrder = orderRegion.get(orderId);
            expectedRef = refRegion.get(custId);
            validateContains(custId, Collections.singleton(orderId), true);
            break;
        case DESTROY:
            assertTrue(!custRegion.containsKey(custId));
            assertTrue(!orderRegion.containsKey(orderId));
            assertTrue(!refRegion.containsKey(custId));
            validateContains(custId, Collections.singleton(orderId), false);
            break;
        case INVALIDATE:
            boolean validateContainsKey = true;
            if (!((GemFireCacheImpl) custRegion.getCache()).isClient()) {
                assertTrue(custRegion.containsKey(custId));
                assertTrue(orderRegion.containsKey(orderId));
                assertTrue(refRegion.containsKey(custId));
            }
            assertNull(custRegion.get(custId));
            assertNull(orderRegion.get(orderId));
            assertNull(refRegion.get(custId));
            validateContains(custId, Collections.singleton(orderId), validateContainsKey, false);
            break;
        default:
            throw new IllegalStateException();
    }
}
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) OrderId(org.apache.geode.internal.cache.execute.data.OrderId)

Example 72 with Customer

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

the class RemoteTransactionDUnitTest method testTxRemove.

@Test
public void testTxRemove() {
    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 custId = new CustId(1);
    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 fakeCust = new Customer("foo", "bar");
            assertFalse(cust.remove(custId, fakeCust));
            assertTrue(cust.remove(custId, customer));
            assertFalse(ref.remove(custId, fakeCust));
            assertTrue(ref.remove(custId, customer));
            TXStateProxy tx = mgr.internalSuspend();
            assertNotNull(cust.get(custId));
            assertNotNull(ref.get(custId));
            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(2, 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));
                    assertTrue("key:" + key + " r:" + r.getFullPath(), 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(custId));
            assertNull(rr.get(custId));
            // check conflict
            mgr.begin();
            CustId conflictCust = new CustId(2);
            Customer customer = new Customer("customer2", "address2");
            getGemfireCache().getLoggerI18n().fine("SWAP:removeConflict");
            assertTrue(cust.remove(conflictCust, customer));
            TXStateProxy tx = mgr.internalSuspend();
            cust.put(conflictCust, new Customer("foo", "bar"));
            mgr.internalResume(tx);
            try {
                mgr.commit();
                fail("expected exception not thrown");
            } catch (CommitConflictException e) {
            }
            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 73 with Customer

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

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

Example 75 with Customer

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

the class RemoteTransactionDUnitTest method testValuesIterationOnRR.

@Test
public void testValuesIterationOnRR() {
    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 = (Set) rr.values();
            Iterator it = set.iterator();
            int i = 0;
            while (it.hasNext()) {
                i++;
                it.next();
            }
            assertEquals(5, i);
            assertTrue(getCustomerSet(5).equals(set));
            assertEquals(5, rr.values().size());
            rr.put(custId, customer);
            set = (Set) rr.values();
            assertTrue(getCustomerSet(6).equals(set));
            it = set.iterator();
            i = 0;
            while (it.hasNext()) {
                i++;
                it.next();
            }
            assertEquals(6, i);
            assertEquals(6, rr.values().size());
            assertNotNull(rr.get(custId));
            TXStateProxy tx = mgr.internalSuspend();
            assertEquals(getCustomerSet(5), rr.values());
            assertEquals(5, rr.values().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)

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