Search in sources :

Example 11 with Order

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

the class PRTransactionDUnitTest method _resumeTx.

private void _resumeTx(Op op, TransactionId txId, PartitionedRegion pr, CacheTransactionManager mgr) {
    CustId cust1 = new CustId(1);
    OrderId order1 = new OrderId(11, cust1);
    OrderId neworder = new OrderId(111, cust1);
    mgr.resume(txId);
    try {
        switch(op) {
            case GET:
                pr.get(order1);
                break;
            case CONTAINSVALUEFORKEY:
                pr.containsValueForKey(order1);
                break;
            case CONTAINSKEY:
                pr.containsKey(order1);
                break;
            case CREATE:
                pr.create(neworder, new Order("test"));
                break;
            case PUT:
                pr.put(order1, new Order("test"));
                break;
            case INVALIDATE:
                pr.invalidate(order1);
                break;
            case DESTROY:
                pr.destroy(order1);
                break;
            case GETENTRY:
                pr.getEntry(order1);
                break;
            default:
                throw new AssertionError("Unknown operations " + op);
        }
    } finally {
        mgr.rollback();
    }
}
Also used : Order(org.apache.geode.internal.cache.execute.data.Order) CustId(org.apache.geode.internal.cache.execute.data.CustId) OrderId(org.apache.geode.internal.cache.execute.data.OrderId)

Example 12 with Order

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

the class PRTransactionDUnitTest method validatePRTXInCacheListener.

/**
   * verify that 10 orders are created for each customer
   * 
   * @throws ClassNotFoundException
   */
public static void validatePRTXInCacheListener() throws ClassNotFoundException {
    PartitionedRegion customerPartitionedregion = null;
    PartitionedRegion orderPartitionedregion = null;
    try {
        customerPartitionedregion = (PartitionedRegion) basicGetCache().getRegion(Region.SEPARATOR + CustomerPartitionedRegionName);
        orderPartitionedregion = (PartitionedRegion) basicGetCache().getRegion(Region.SEPARATOR + OrderPartitionedRegionName);
    } catch (Exception e) {
        Assert.fail("validateAfterPutPartitionedRegion : failed while getting the region", e);
    }
    assertNotNull(customerPartitionedregion);
    assertNotNull(orderPartitionedregion);
    customerPartitionedregion.getDataStore().dumpEntries(false);
    orderPartitionedregion.getDataStore().dumpEntries(false);
    Iterator custIterator = customerPartitionedregion.getDataStore().getEntries().iterator();
    LogWriterUtils.getLogWriter().info("Found " + customerPartitionedregion.getDataStore().getEntries().size() + " Customer entries in the partition");
    Region.Entry custEntry = null;
    while (custIterator.hasNext()) {
        custEntry = (Entry) custIterator.next();
        CustId custid = (CustId) custEntry.getKey();
        Customer cust = (Customer) custEntry.getValue();
        Iterator orderIterator = orderPartitionedregion.getDataStore().getEntries().iterator();
        LogWriterUtils.getLogWriter().info("Found " + orderPartitionedregion.getDataStore().getEntries().size() + " Order entries in the partition");
        int orderPerCustomer = 0;
        Region.Entry orderEntry = null;
        while (orderIterator.hasNext()) {
            orderEntry = (Entry) orderIterator.next();
            OrderId orderId = (OrderId) orderEntry.getKey();
            Order order = (Order) orderEntry.getValue();
            if (custid.equals(orderId.getCustId())) {
                orderPerCustomer++;
            }
        }
        assertEquals(10, orderPerCustomer);
    }
}
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) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Entry(org.apache.geode.cache.Region.Entry) Iterator(java.util.Iterator) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException) FunctionException(org.apache.geode.cache.execute.FunctionException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) TestException(util.TestException) PRLocallyDestroyedException(org.apache.geode.internal.cache.partitioned.PRLocallyDestroyedException)

Example 13 with Order

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

the class PRTransactionDUnitTest method doOp.

private void doOp(Op op, CacheTransactionManager mgr) {
    PartitionedRegion cust = (PartitionedRegion) basicGetCache().getRegion(Region.SEPARATOR + CustomerPartitionedRegionName);
    PartitionedRegion order = (PartitionedRegion) basicGetCache().getRegion(Region.SEPARATOR + OrderPartitionedRegionName);
    CustId cust1 = new CustId(1);
    CustId cust2 = new CustId(2);
    OrderId order2 = new OrderId(21, cust2);
    OrderId neworder2 = new OrderId(221, cust2);
    mgr.begin();
    // touch 1 bucket
    cust.get(cust1);
    try {
        switch(op) {
            case GET:
                order.get(order2);
                break;
            case CONTAINSVALUEFORKEY:
                order.containsValueForKey(order2);
                break;
            case CONTAINSKEY:
                order.containsKey(order2);
                break;
            case CREATE:
                order.create(neworder2, new Order("test"));
                break;
            case PUT:
                order.put(order2, new Order("test"));
                break;
            case INVALIDATE:
                order.invalidate(order2);
                break;
            case DESTROY:
                order.destroy(order2);
                break;
            case GETENTRY:
                order.getEntry(order2);
                break;
            default:
                throw new AssertionError("Unknown operations " + op);
        }
    } finally {
        mgr.rollback();
    }
}
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) OrderId(org.apache.geode.internal.cache.execute.data.OrderId)

Example 14 with Order

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

the class PRTransactionDUnitTest method basicPRTXInFunction.

/**
   * Test all the basic functionality of colocated transactions. This method invokes
   * {@link MyTransactionFunction} and tells it what to test, using different arguments.
   * 
   * @param redundantBuckets redundant buckets for colocated PRs
   * @param populateData if false tests are carried out on empty colocated PRs
   */
protected void basicPRTXInFunction(int redundantBuckets, boolean populateData) {
    if (populateData) {
        createPopulateAndVerifyCoLocatedPRs(redundantBuckets);
    } else {
        createColocatedPRs(redundantBuckets);
    }
    SerializableCallable registerFunction = new SerializableCallable("register Fn") {

        public Object call() throws Exception {
            Function txFunction = new MyTransactionFunction();
            FunctionService.registerFunction(txFunction);
            return Boolean.TRUE;
        }
    };
    dataStore1.invoke(registerFunction);
    dataStore2.invoke(registerFunction);
    dataStore3.invoke(registerFunction);
    accessor.invoke(new SerializableCallable("run function") {

        public Object call() throws Exception {
            PartitionedRegion pr = (PartitionedRegion) basicGetCache().getRegion(Region.SEPARATOR + CustomerPartitionedRegionName);
            PartitionedRegion orderpr = (PartitionedRegion) basicGetCache().getRegion(Region.SEPARATOR + OrderPartitionedRegionName);
            CustId custId = new CustId(2);
            Customer newCus = new Customer("foo", "bar");
            Order order = new Order("fooOrder");
            OrderId orderId = new OrderId(22, custId);
            ArrayList args = new ArrayList();
            Function txFunction = new MyTransactionFunction();
            FunctionService.registerFunction(txFunction);
            Execution e = FunctionService.onRegion(pr);
            Set filter = new HashSet();
            // test transaction non-coLocated operations
            filter.clear();
            args.clear();
            args.add(new Integer(VERIFY_NON_COLOCATION));
            LogWriterUtils.getLogWriter().info("VERIFY_NON_COLOCATION");
            args.add(custId);
            args.add(newCus);
            args.add(orderId);
            args.add(order);
            filter.add(custId);
            try {
                e.withFilter(filter).setArguments(args).execute(txFunction.getId()).getResult();
                fail("Expected exception was not thrown");
            } catch (FunctionException fe) {
                LogWriterUtils.getLogWriter().info("Caught Expected exception");
                if (fe.getCause() instanceof TransactionDataNotColocatedException) {
                } else {
                    throw new TestException("Expected to catch FunctionException with cause TransactionDataNotColocatedException" + " but cause is  " + fe.getCause(), fe.getCause());
                }
            }
            // verify that the transaction modifications are applied
            args.set(0, new Integer(VERIFY_TX));
            LogWriterUtils.getLogWriter().info("VERIFY_TX");
            orderpr.put(orderId, order);
            assertNotNull(orderpr.get(orderId));
            e.withFilter(filter).setArguments(args).execute(txFunction.getId()).getResult();
            assertTrue("Unexpected customer value after commit", newCus.equals(pr.get(custId)));
            Order commitedOrder = (Order) orderpr.get(orderId);
            assertTrue("Unexpected order value after commit. Expected:" + order + " Found:" + commitedOrder, order.equals(commitedOrder));
            // verify conflict detection
            args.set(0, new Integer(VERIFY_TXSTATE_CONFLICT));
            e.withFilter(filter).setArguments(args).execute(txFunction.getId()).getResult();
            // verify that the transaction is rolled back
            args.set(0, new Integer(VERIFY_ROLLBACK));
            LogWriterUtils.getLogWriter().info("VERIFY_ROLLBACK");
            e.withFilter(filter).setArguments(args).execute(txFunction.getId()).getResult();
            // verify destroy
            args.set(0, new Integer(VERIFY_DESTROY));
            LogWriterUtils.getLogWriter().info("VERIFY_DESTROY");
            e.withFilter(filter).setArguments(args).execute(txFunction.getId()).getResult();
            // verify invalidate
            args.set(0, new Integer(VERIFY_INVALIDATE));
            LogWriterUtils.getLogWriter().info("VERIFY_INVALIDATE");
            e.withFilter(filter).setArguments(args).execute(txFunction.getId()).getResult();
            return Boolean.TRUE;
        }
    });
}
Also used : Order(org.apache.geode.internal.cache.execute.data.Order) HashSet(java.util.HashSet) Set(java.util.Set) TestException(util.TestException) Customer(org.apache.geode.internal.cache.execute.data.Customer) ArrayList(java.util.ArrayList) FunctionException(org.apache.geode.cache.execute.FunctionException) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException) FunctionException(org.apache.geode.cache.execute.FunctionException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) TestException(util.TestException) PRLocallyDestroyedException(org.apache.geode.internal.cache.partitioned.PRLocallyDestroyedException) Function(org.apache.geode.cache.execute.Function) Execution(org.apache.geode.cache.execute.Execution) CustId(org.apache.geode.internal.cache.execute.data.CustId) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) HashSet(java.util.HashSet)

Example 15 with Order

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

the class PRTransactionDUnitTest method testRepeatableRead.

@Test
public void testRepeatableRead() throws Exception {
    createColocatedPRs(1);
    SerializableCallable registerFunction = new SerializableCallable("register Fn") {

        public Object call() throws Exception {
            Function txFunction = new MyTransactionFunction();
            FunctionService.registerFunction(txFunction);
            return Boolean.TRUE;
        }
    };
    dataStore1.invoke(registerFunction);
    dataStore2.invoke(registerFunction);
    dataStore3.invoke(registerFunction);
    accessor.invoke(new SerializableCallable("run function") {

        public Object call() throws Exception {
            PartitionedRegion pr = (PartitionedRegion) basicGetCache().getRegion(Region.SEPARATOR + CustomerPartitionedRegionName);
            PartitionedRegion orderpr = (PartitionedRegion) basicGetCache().getRegion(Region.SEPARATOR + OrderPartitionedRegionName);
            CustId custId = new CustId(2);
            Customer newCus = new Customer("foo", "bar");
            Order order = new Order("fooOrder");
            OrderId orderId = new OrderId(22, custId);
            ArrayList args = new ArrayList();
            Function txFunction = new MyTransactionFunction();
            FunctionService.registerFunction(txFunction);
            Execution e = FunctionService.onRegion(pr);
            Set filter = new HashSet();
            filter.clear();
            args.clear();
            args.add(new Integer(VERIFY_REP_READ));
            LogWriterUtils.getLogWriter().info("VERIFY_REP_READ");
            args.add(custId);
            args.add(newCus);
            args.add(orderId);
            args.add(order);
            filter.add(custId);
            e.withFilter(filter).setArguments(args).execute(txFunction.getId()).getResult();
            return null;
        }
    });
}
Also used : Order(org.apache.geode.internal.cache.execute.data.Order) HashSet(java.util.HashSet) Set(java.util.Set) Customer(org.apache.geode.internal.cache.execute.data.Customer) ArrayList(java.util.ArrayList) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException) FunctionException(org.apache.geode.cache.execute.FunctionException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) TestException(util.TestException) PRLocallyDestroyedException(org.apache.geode.internal.cache.partitioned.PRLocallyDestroyedException) Function(org.apache.geode.cache.execute.Function) Execution(org.apache.geode.cache.execute.Execution) CustId(org.apache.geode.internal.cache.execute.data.CustId) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) HashSet(java.util.HashSet) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

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