Search in sources :

Example 6 with RegionFunctionContext

use of org.apache.geode.cache.execute.RegionFunctionContext in project geode by apache.

the class MyTransactionFunction method execute.

public void execute(FunctionContext context) {
    RegionFunctionContext ctx = (RegionFunctionContext) context;
    verifyExecutionOnPrimary(ctx);
    ArrayList args = (ArrayList) ctx.getArguments();
    Integer testOperation = (Integer) args.get(0);
    int op = testOperation.intValue();
    switch(op) {
        case PRTransactionDUnitTest.VERIFY_TX:
            verifyTransactionExecution(ctx);
            ctx.getDataSet().getCache().getLogger().info("verifyTransactionExecution Passed");
            break;
        case PRTransactionDUnitTest.VERIFY_ROLLBACK:
            verifyTransactionRollback(ctx);
            ctx.getDataSet().getCache().getLogger().info("verifyTransactionRollback Passed");
            break;
        case PRTransactionDUnitTest.VERIFY_DESTROY:
            verifyDestroyOperation(ctx);
            ctx.getDataSet().getCache().getLogger().info("verifyDestroy Passed");
            break;
        case PRTransactionDUnitTest.VERIFY_INVALIDATE:
            verifyInvalidateOperation(ctx);
            ctx.getDataSet().getCache().getLogger().info("verifyInvalidate Passed");
            break;
        case PRTransactionDUnitTest.VERIFY_NON_COLOCATION:
            verifyNonCoLocatedOpsRejection(ctx);
            ctx.getDataSet().getCache().getLogger().info("verifyNonCoLocatedOpsRejection Passed");
            break;
        case PRTransactionDUnitTest.VERIFY_LISTENER_CALLBACK:
            verifyListenerCallback(ctx);
            break;
        case PRTransactionDUnitTest.VERIFY_TXSTATE_CONFLICT:
            verifyTxStateAndConflicts(ctx);
            break;
        case PRTransactionDUnitTest.VERIFY_REP_READ:
            verifyRepeatableRead(ctx);
            break;
    }
    context.getResultSender().lastResult(null);
}
Also used : ArrayList(java.util.ArrayList) RegionFunctionContext(org.apache.geode.cache.execute.RegionFunctionContext)

Example 7 with RegionFunctionContext

use of org.apache.geode.cache.execute.RegionFunctionContext in project geode by apache.

the class PerfFunction method execute.

public void execute(FunctionContext context) {
    RegionFunctionContext ctx = (RegionFunctionContext) context;
    Region customerPR = ctx.getDataSet();
    Region orderPR = customerPR.getCache().getRegion(PRColocationDUnitTest.OrderPartitionedRegionName);
    Region shipmentPR = customerPR.getCache().getRegion(PRColocationDUnitTest.ShipmentPartitionedRegionName);
    ArrayList args = (ArrayList) ctx.getArguments();
    for (int i = 0; i < args.size() / 4; i++) {
        OrderId orderId = (OrderId) args.get(i * 4);
        Order order = (Order) args.get(i * 4 + 1);
        ShipmentId shipmentId = (ShipmentId) args.get(i * 4 + 2);
        Shipment shipment = (Shipment) args.get(i * 4 + 3);
        orderPR.put(orderId, order);
        shipmentPR.put(shipmentId, shipment);
    }
    context.getResultSender().lastResult(null);
}
Also used : Order(org.apache.geode.internal.cache.execute.data.Order) ShipmentId(org.apache.geode.internal.cache.execute.data.ShipmentId) ArrayList(java.util.ArrayList) Region(org.apache.geode.cache.Region) Shipment(org.apache.geode.internal.cache.execute.data.Shipment) RegionFunctionContext(org.apache.geode.cache.execute.RegionFunctionContext) OrderId(org.apache.geode.internal.cache.execute.data.OrderId)

Example 8 with RegionFunctionContext

use of org.apache.geode.cache.execute.RegionFunctionContext in project geode by apache.

the class PerfTxFunction method execute.

public void execute(FunctionContext context) {
    RegionFunctionContext ctx = (RegionFunctionContext) context;
    Region customerPR = ctx.getDataSet();
    Region orderPR = customerPR.getCache().getRegion(PRColocationDUnitTest.OrderPartitionedRegionName);
    Region shipmentPR = customerPR.getCache().getRegion(PRColocationDUnitTest.ShipmentPartitionedRegionName);
    ArrayList args = (ArrayList) ctx.getArguments();
    // put the entries
    CacheTransactionManager mgr = customerPR.getCache().getCacheTransactionManager();
    mgr.begin();
    for (int i = 0; i < args.size() / 4; i++) {
        OrderId orderId = (OrderId) args.get(i * 4);
        Order order = (Order) args.get(i * 4 + 1);
        ShipmentId shipmentId = (ShipmentId) args.get(i * 4 + 2);
        Shipment shipment = (Shipment) args.get(i * 4 + 3);
        orderPR.put(orderId, order);
        shipmentPR.put(shipmentId, shipment);
    }
    mgr.commit();
    context.getResultSender().lastResult(null);
}
Also used : Order(org.apache.geode.internal.cache.execute.data.Order) ShipmentId(org.apache.geode.internal.cache.execute.data.ShipmentId) ArrayList(java.util.ArrayList) Region(org.apache.geode.cache.Region) Shipment(org.apache.geode.internal.cache.execute.data.Shipment) RegionFunctionContext(org.apache.geode.cache.execute.RegionFunctionContext) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager)

Example 9 with RegionFunctionContext

use of org.apache.geode.cache.execute.RegionFunctionContext in project geode by apache.

the class PerformanceTestFunction method execute.

/**
   * Application execution implementation
   * 
   * @since GemFire 5.8Beta
   */
public void execute(FunctionContext context) {
    if (context instanceof RegionFunctionContext) {
        RegionFunctionContext prContext = (RegionFunctionContext) context;
        final Set allKeysSet = prContext.getFilter();
        ArrayList vals = new ArrayList();
        Region fcd = PartitionRegionHelper.getLocalDataForContext(prContext);
        for (Iterator i = allKeysSet.iterator(); i.hasNext(); ) {
            Object val = fcd.get(i.next());
            assertNotNull(val);
            vals.add(val);
        }
        context.getResultSender().lastResult(vals);
    } else {
        context.getResultSender().lastResult(null);
    }
}
Also used : Set(java.util.Set) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Region(org.apache.geode.cache.Region) RegionFunctionContext(org.apache.geode.cache.execute.RegionFunctionContext)

Example 10 with RegionFunctionContext

use of org.apache.geode.cache.execute.RegionFunctionContext in project geode by apache.

the class LocalDataSetFunction method execute.

public void execute(FunctionContext context) {
    RegionFunctionContext rContext = (RegionFunctionContext) context;
    Region cust = rContext.getDataSet();
    LocalDataSet localCust = (LocalDataSet) PartitionRegionHelper.getLocalDataForContext(rContext);
    Map<String, Region<?, ?>> colocatedRegions = PartitionRegionHelper.getColocatedRegions(cust);
    Map<String, Region<?, ?>> localColocatedRegions = PartitionRegionHelper.getLocalColocatedRegions(rContext);
    Assert.assertTrue(colocatedRegions.size() == 2);
    Set custKeySet = cust.keySet();
    Set localCustKeySet = localCust.keySet();
    Region ord = colocatedRegions.get("/OrderPR");
    LocalDataSet localOrd = (LocalDataSet) localColocatedRegions.get("/OrderPR");
    Set ordKeySet = ord.keySet();
    Set localOrdKeySet = localOrd.keySet();
    Region ship = colocatedRegions.get("/ShipmentPR");
    LocalDataSet localShip = (LocalDataSet) localColocatedRegions.get("/ShipmentPR");
    Set shipKeySet = ship.keySet();
    Set localShipKeySet = localShip.keySet();
    Assert.assertTrue(localCust.getBucketSet().size() == localOrd.getBucketSet().size());
    Assert.assertTrue(localCust.getBucketSet().size() == localShip.getBucketSet().size());
    Assert.assertTrue(custKeySet.size() == 120);
    Assert.assertTrue(ordKeySet.size() == 120);
    Assert.assertTrue(shipKeySet.size() == 120);
    Assert.assertTrue(localCustKeySet.size() == localOrdKeySet.size());
    Assert.assertTrue(localCustKeySet.size() == localShipKeySet.size());
    context.getResultSender().lastResult(null);
}
Also used : LocalDataSet(org.apache.geode.internal.cache.LocalDataSet) Set(java.util.Set) LocalDataSet(org.apache.geode.internal.cache.LocalDataSet) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) RegionFunctionContext(org.apache.geode.cache.execute.RegionFunctionContext)

Aggregations

RegionFunctionContext (org.apache.geode.cache.execute.RegionFunctionContext)38 Region (org.apache.geode.cache.Region)23 ArrayList (java.util.ArrayList)21 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)17 Set (java.util.Set)15 Iterator (java.util.Iterator)14 FunctionContext (org.apache.geode.cache.execute.FunctionContext)12 FunctionAdapter (org.apache.geode.cache.execute.FunctionAdapter)10 HashSet (java.util.HashSet)8 Serializable (java.io.Serializable)6 Map (java.util.Map)6 FunctionException (org.apache.geode.cache.execute.FunctionException)6 IgnoredException (org.apache.geode.test.dunit.IgnoredException)6 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)6 Test (org.junit.Test)6 HashMap (java.util.HashMap)5 List (java.util.List)5 CacheClosedException (org.apache.geode.cache.CacheClosedException)5 Execution (org.apache.geode.cache.execute.Execution)5 ResultCollector (org.apache.geode.cache.execute.ResultCollector)5