Search in sources :

Example 36 with Order

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

the class RemoteTransactionDUnitTest method createRegion.

void createRegion(boolean accessor, int redundantCopies, InterestPolicy interestPolicy) {
    AttributesFactory af = new AttributesFactory();
    af.setScope(Scope.DISTRIBUTED_ACK);
    af.setDataPolicy(DataPolicy.REPLICATE);
    af.setConcurrencyChecksEnabled(getConcurrencyChecksEnabled());
    getCache().createRegion(D_REFERENCE, af.create());
    af = new AttributesFactory();
    af.setConcurrencyChecksEnabled(getConcurrencyChecksEnabled());
    if (interestPolicy != null) {
        af.setSubscriptionAttributes(new SubscriptionAttributes(interestPolicy));
    }
    af.setPartitionAttributes(new PartitionAttributesFactory<CustId, Customer>().setTotalNumBuckets(4).setLocalMaxMemory(accessor ? 0 : 1).setPartitionResolver(new CustomerIDPartitionResolver("resolver1")).setRedundantCopies(redundantCopies).create());
    getCache().createRegion(CUSTOMER, af.create());
    af.setPartitionAttributes(new PartitionAttributesFactory<OrderId, Order>().setTotalNumBuckets(4).setLocalMaxMemory(accessor ? 0 : 1).setPartitionResolver(new CustomerIDPartitionResolver("resolver2")).setRedundantCopies(redundantCopies).setColocatedWith(CUSTOMER).create());
    getCache().createRegion(ORDER, af.create());
}
Also used : Order(org.apache.geode.internal.cache.execute.data.Order) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CustomerIDPartitionResolver(org.apache.geode.internal.cache.execute.CustomerIDPartitionResolver) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) SubscriptionAttributes(org.apache.geode.cache.SubscriptionAttributes)

Example 37 with Order

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

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

the class RemoteTransactionDUnitTest method testTxPutIfAbsent.

@Test
public void testTxPutIfAbsent() {
    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 newCustId = new CustId(10);
    final Customer updateCust = new Customer("customer10", "address10");
    final TXId txId = (TXId) accessor.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            TXManagerImpl mgr = getGemfireCache().getTxManager();
            mgr.begin();
            Region<CustId, Customer> cust = getGemfireCache().getRegion(CUSTOMER);
            Region<CustId, Customer> rr = getGemfireCache().getRegion(D_REFERENCE);
            Customer expectedCust = new Customer("customer" + 1, "address" + 1);
            getGemfireCache().getLoggerI18n().fine("SWAP:doingPutIfAbsent");
            CustId oldCustId = new CustId(1);
            Customer old = cust.putIfAbsent(oldCustId, updateCust);
            assertTrue("expected:" + expectedCust + " but was " + old, expectedCust.equals(old));
            // transaction should be bootstrapped
            old = rr.putIfAbsent(oldCustId, updateCust);
            assertTrue("expected:" + expectedCust + " but was " + old, expectedCust.equals(old));
            // now a key that does not exist
            old = cust.putIfAbsent(newCustId, updateCust);
            assertNull(old);
            old = rr.putIfAbsent(newCustId, updateCust);
            assertNull(old);
            Region<OrderId, Order> order = getGemfireCache().getRegion(ORDER);
            Order oldOrder = order.putIfAbsent(new OrderId(10, newCustId), new Order("order10"));
            assertNull(old);
            assertNull(oldOrder);
            assertNotNull(cust.get(newCustId));
            assertNotNull(rr.get(newCustId));
            TXStateProxy tx = mgr.internalSuspend();
            assertNull(cust.get(newCustId));
            assertNull(rr.get(newCustId));
            mgr.internalResume(tx);
            cust.put(oldCustId, new Customer("foo", "bar"));
            rr.put(oldCustId, new Customer("foo", "bar"));
            return mgr.getTransactionId();
        }
    });
    datastore.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Region cust = getGemfireCache().getRegion(CUSTOMER);
            int hash1 = PartitionedRegionHelper.getHashKey((PartitionedRegion) cust, new CustId(1));
            int hash10 = PartitionedRegionHelper.getHashKey((PartitionedRegion) cust, new CustId(10));
            TXManagerImpl mgr = getGemfireCache().getTxManager();
            assertTrue(mgr.isHostedTxInProgress(txId));
            TXStateProxy tx = mgr.getHostedTXState(txId);
            // 2 buckets for the two
            assertEquals(3 + (hash1 == hash10 ? 0 : 1), 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);
                    assertNotNull(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);
            assertEquals(updateCust, cust.get(newCustId));
            assertEquals(updateCust, rr.get(newCustId));
            // test conflict
            mgr.begin();
            CustId conflictCust = new CustId(11);
            cust.putIfAbsent(conflictCust, new Customer("name11", "address11"));
            TXStateProxy tx = mgr.internalSuspend();
            cust.put(conflictCust, new Customer("foo", "bar"));
            mgr.internalResume(tx);
            try {
                mgr.commit();
                fail("expected exception not thrown");
            } catch (CommitConflictException cce) {
            }
            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) 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 39 with Order

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

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

the class RemoteCQTransactionDUnitTest method verifyAfterRollback.

void verifyAfterRollback(OP op) {
    Region<CustId, Customer> custRegion = getCache().getRegion(CUSTOMER);
    Region<OrderId, Order> orderRegion = getCache().getRegion(ORDER);
    Region<CustId, Customer> refRegion = getCache().getRegion(D_REFERENCE);
    assertNotNull(custRegion);
    assertNotNull(orderRegion);
    assertNotNull(refRegion);
    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;
    Customer expectedRef;
    switch(op) {
        case PUT:
            expectedCust = new Customer("customer1", "address1");
            expectedOrder = new Order("order1");
            expectedRef = new Customer("customer1", "address1");
            assertEquals(expectedCust, custRegion.getEntry(custId).getValue());
            assertEquals(expectedOrder, orderRegion.getEntry(orderId).getValue());
            getCache().getLogger().info("SWAP:verifyRollback:" + orderRegion);
            getCache().getLogger().info("SWAP:verifyRollback:" + orderRegion.getEntry(orderId2));
            assertNull(getGemfireCache().getTXMgr().getTXState());
            assertNull("" + orderRegion.getEntry(orderId2), orderRegion.getEntry(orderId2));
            assertNull(orderRegion.getEntry(orderId3));
            assertNull(orderRegion.get(orderId2));
            assertNull(orderRegion.get(orderId3));
            assertEquals(expectedRef, refRegion.getEntry(custId).getValue());
            validateContains(custId, Collections.singleton(orderId), true);
            break;
        case GET:
            expectedCust = custRegion.getEntry(custId).getValue();
            expectedOrder = orderRegion.getEntry(orderId).getValue();
            expectedRef = refRegion.getEntry(custId).getValue();
            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), true);
            break;
        case INVALIDATE:
            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), true, true);
            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)

Aggregations

Order (org.apache.geode.internal.cache.execute.data.Order)55 OrderId (org.apache.geode.internal.cache.execute.data.OrderId)53 CustId (org.apache.geode.internal.cache.execute.data.CustId)48 Region (org.apache.geode.cache.Region)32 Customer (org.apache.geode.internal.cache.execute.data.Customer)30 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)23 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)15 Test (org.junit.Test)15 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)14 ArrayList (java.util.ArrayList)13 IgnoredException (org.apache.geode.test.dunit.IgnoredException)13 CacheTransactionManager (org.apache.geode.cache.CacheTransactionManager)12 TransactionDataNotColocatedException (org.apache.geode.cache.TransactionDataNotColocatedException)12 TransactionDataRebalancedException (org.apache.geode.cache.TransactionDataRebalancedException)12 CommitConflictException (org.apache.geode.cache.CommitConflictException)11 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)11 IOException (java.io.IOException)10 RollbackException (javax.transaction.RollbackException)10 BucketRegion (org.apache.geode.internal.cache.BucketRegion)10 HashMap (java.util.HashMap)8