Search in sources :

Example 21 with Order

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

the class RemoteTransactionDUnitTest 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)

Example 22 with Order

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

the class TransactionsWithDeltaDUnitTest method createRegion.

private void createRegion(boolean accessor, int redundantCopies, InterestPolicy interestPolicy) {
    AttributesFactory af = new AttributesFactory();
    af.setScope(Scope.DISTRIBUTED_ACK);
    af.setDataPolicy(DataPolicy.REPLICATE);
    af.setCloningEnabled(true);
    getCache().createRegion(D_REFERENCE, af.create());
    af = new AttributesFactory();
    af.setCloningEnabled(true);
    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) CustomerIDPartitionResolver(org.apache.geode.internal.cache.execute.CustomerIDPartitionResolver) OrderId(org.apache.geode.internal.cache.execute.data.OrderId)

Example 23 with Order

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

the class PRColocationDUnitTest method putOrderPartitionedRegion.

public static void putOrderPartitionedRegion(String partitionedRegionName, int numOfCust) {
    assertNotNull(basicGetCache());
    Region partitionedregion = basicGetCache().getRegion(Region.SEPARATOR + partitionedRegionName);
    assertNotNull(partitionedregion);
    for (int i = 1; i <= numOfCust; i++) {
        CustId custid = new CustId(i);
        for (int j = 1; j <= 10; j++) {
            int oid = (i * 10) + j;
            OrderId orderId = new OrderId(oid, custid);
            Order order = new Order("OREDR" + oid);
            try {
                partitionedregion.put(orderId, order);
                assertTrue(partitionedregion.containsKey(orderId));
                assertEquals(order, partitionedregion.get(orderId));
            } catch (Exception e) {
                Assert.fail("putOrderPartitionedRegion : failed while doing put operation in OrderPartitionedRegion ", e);
            }
            LogWriterUtils.getLogWriter().info("Order :- { " + orderId + " : " + order + " }");
        }
    }
}
Also used : Order(org.apache.geode.internal.cache.execute.data.Order) CustId(org.apache.geode.internal.cache.execute.data.CustId) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) IgnoredException(org.apache.geode.test.dunit.IgnoredException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException)

Example 24 with Order

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

the class PRColocationDUnitTest method putOrderPartitionedRegion2.

public static void putOrderPartitionedRegion2(String partitionedRegionName) {
    assertNotNull(basicGetCache());
    Region partitionedregion = basicGetCache().getRegion(Region.SEPARATOR + partitionedRegionName);
    assertNotNull(partitionedregion);
    for (int i = 11; i <= 100; i++) {
        CustId custid = new CustId(i);
        for (int j = 1; j <= 10; j++) {
            int oid = (i * 10) + j;
            OrderId orderId = new OrderId(oid, custid);
            Order order = new Order("OREDR" + oid);
            try {
                partitionedregion.put(orderId, order);
                assertTrue(partitionedregion.containsKey(orderId));
                assertEquals(order, partitionedregion.get(orderId));
            } catch (Exception e) {
                Assert.fail("putOrderPartitionedRegion : failed while doing put operation in OrderPartitionedRegion ", e);
            }
            LogWriterUtils.getLogWriter().info("Order :- { " + orderId + " : " + order + " }");
        }
    }
}
Also used : Order(org.apache.geode.internal.cache.execute.data.Order) CustId(org.apache.geode.internal.cache.execute.data.CustId) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) IgnoredException(org.apache.geode.test.dunit.IgnoredException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException)

Example 25 with Order

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

the class MyTransactionFunction method verifyTxStateAndConflicts.

private void verifyTxStateAndConflicts(RegionFunctionContext ctx) {
    Region custPR = ctx.getDataSet();
    Region orderPR = custPR.getCache().getRegion(PRTransactionDUnitTest.OrderPartitionedRegionName);
    ArrayList args = (ArrayList) ctx.getArguments();
    CustId custId = (CustId) args.get(1);
    CacheTransactionManager mgr = custPR.getCache().getCacheTransactionManager();
    OrderId vOrderId = new OrderId(3000, custId);
    Order vOrder = new Order("vOrder");
    TXManagerImpl mImp = (TXManagerImpl) mgr;
    mImp.begin();
    orderPR.put(vOrderId, vOrder);
    TXStateProxy txState = mImp.internalSuspend();
    Iterator it = txState.getRegions().iterator();
    Assert.assertTrue(txState.getRegions().size() == 1, "Expected 1 region; " + "found:" + txState.getRegions().size());
    LocalRegion lr = (LocalRegion) it.next();
    Assert.assertTrue(lr instanceof BucketRegion);
    TXRegionState txRegion = txState.readRegion(lr);
    TXEntryState txEntry = txRegion.readEntry(txRegion.getEntryKeys().iterator().next());
    mImp.internalResume(txState);
    orderPR.put(vOrderId, new Order("foo"));
    txState = mImp.internalSuspend();
    // since both puts were on same key, verify that
    // TxRegionState and TXEntryState are same
    LocalRegion lr1 = (LocalRegion) txState.getRegions().iterator().next();
    Assert.assertTrue(lr == lr1);
    TXRegionState txRegion1 = txState.readRegion(lr);
    TXEntryState txEntry1 = txRegion1.readEntry(txRegion.getEntryKeys().iterator().next());
    Assert.assertTrue(txEntry == txEntry1);
    // to check for conflicts, start a new transaction, operate on same key,
    // commit the second and expect the first to fail
    mImp.begin();
    orderPR.put(vOrderId, new Order("foobar"));
    mImp.commit();
    // now begin the first
    mImp.internalResume(txState);
    boolean caughtException = false;
    try {
        mImp.commit();
    } catch (CommitConflictException e) {
        caughtException = true;
    }
    if (!caughtException) {
        throw new TestException("An expected exception was not thrown");
    }
}
Also used : Order(org.apache.geode.internal.cache.execute.data.Order) TXManagerImpl(org.apache.geode.internal.cache.TXManagerImpl) TestException(util.TestException) TXRegionState(org.apache.geode.internal.cache.TXRegionState) ArrayList(java.util.ArrayList) TXEntryState(org.apache.geode.internal.cache.TXEntryState) LocalRegion(org.apache.geode.internal.cache.LocalRegion) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) CommitConflictException(org.apache.geode.cache.CommitConflictException) BucketRegion(org.apache.geode.internal.cache.BucketRegion) CustId(org.apache.geode.internal.cache.execute.data.CustId) TXStateProxy(org.apache.geode.internal.cache.TXStateProxy) Iterator(java.util.Iterator) LocalRegion(org.apache.geode.internal.cache.LocalRegion) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion)

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