Search in sources :

Example 11 with Shipment

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

the class WANTestBase method updateShipmentPartitionedRegionUsingCustId.

public static Map updateShipmentPartitionedRegionUsingCustId(int numPuts) {
    assertNotNull(cache);
    assertNotNull(shipmentRegion);
    Map shipmentKeyValue = new HashMap();
    for (int i = 1; i <= numPuts; i++) {
        CustId custid = new CustId(i);
        Shipment shipment = new Shipment("Shipment" + i + "_update");
        try {
            shipmentRegion.put(custid, shipment);
            assertTrue(shipmentRegion.containsKey(custid));
            assertEquals(shipment, shipmentRegion.get(custid));
            shipmentKeyValue.put(custid, shipment);
        } catch (Exception e) {
            org.apache.geode.test.dunit.Assert.fail("updateShipmentPartitionedRegionUsingCustId : failed while doing put operation in ShipmentPartitionedRegion ", e);
        }
        LogWriterUtils.getLogWriter().info("Shipment :- { " + custid + " : " + shipment + " }");
    }
    return shipmentKeyValue;
}
Also used : HashMap(java.util.HashMap) CustId(org.apache.geode.internal.cache.execute.data.CustId) Shipment(org.apache.geode.internal.cache.execute.data.Shipment) Map(java.util.Map) HashMap(java.util.HashMap) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) PartitionOfflineException(org.apache.geode.cache.persistence.PartitionOfflineException) IOException(java.io.IOException) PRLocallyDestroyedException(org.apache.geode.internal.cache.partitioned.PRLocallyDestroyedException) ExecutionException(java.util.concurrent.ExecutionException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) CacheClosedException(org.apache.geode.cache.CacheClosedException)

Example 12 with Shipment

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

the class PRTransactionDUnitTest method testPRTXPerformance.

@Test
public void testPRTXPerformance() throws Exception {
    defaultStringSize = 1024;
    createPopulateAndVerifyCoLocatedPRs(1);
    // register functions
    SerializableCallable registerPerfFunctions = new SerializableCallable("register Fn") {

        public Object call() throws Exception {
            Function perfFunction = new PerfFunction();
            FunctionService.registerFunction(perfFunction);
            Function perfTxFunction = new PerfTxFunction();
            FunctionService.registerFunction(perfTxFunction);
            return Boolean.TRUE;
        }
    };
    dataStore1.invoke(registerPerfFunctions);
    dataStore2.invoke(registerPerfFunctions);
    dataStore3.invoke(registerPerfFunctions);
    accessor.invoke(registerPerfFunctions);
    SerializableCallable runPerfFunction = new SerializableCallable("runPerfFunction") {

        public Object call() throws Exception {
            long perfTime = 0;
            Region customerPR = basicGetCache().getRegion(CustomerPartitionedRegionName);
            Execution e = FunctionService.onRegion(customerPR);
            // for each customer, update order and shipment
            for (int iterations = 1; iterations <= totalIterations; iterations++) {
                LogWriterUtils.getLogWriter().info("running perfFunction");
                long startTime = 0;
                ArrayList args = new ArrayList();
                CustId custId = new CustId(iterations % 10);
                for (int i = 1; i <= perfOrderShipmentPairs; i++) {
                    OrderId orderId = new OrderId(custId.getCustId().intValue() * 10 + i, custId);
                    Order order = new Order("NewOrder" + i + iterations);
                    ShipmentId shipmentId = new ShipmentId(orderId.getOrderId().intValue() * 10 + i, orderId);
                    Shipment shipment = new Shipment("newShipment" + i + iterations);
                    args.add(orderId);
                    args.add(order);
                    args.add(shipmentId);
                    args.add(shipment);
                }
                Set filter = new HashSet();
                filter.add(custId);
                if (iterations > warmupIterations) {
                    startTime = NanoTimer.getTime();
                }
                e.withFilter(filter).setArguments(args).execute("perfFunction").getResult();
                if (startTime > 0) {
                    perfTime += NanoTimer.getTime() - startTime;
                }
            }
            return new Long(perfTime);
        }
    };
    Long perfTime = (Long) accessor.invoke(runPerfFunction);
    SerializableCallable runPerfTxFunction = new SerializableCallable("runPerfTxFunction") {

        public Object call() throws Exception {
            long perfTime = 0;
            Region customerPR = basicGetCache().getRegion(CustomerPartitionedRegionName);
            Execution e = FunctionService.onRegion(customerPR);
            // for each customer, update order and shipment
            for (int iterations = 1; iterations <= totalIterations; iterations++) {
                LogWriterUtils.getLogWriter().info("Running perfFunction");
                long startTime = 0;
                ArrayList args = new ArrayList();
                CustId custId = new CustId(iterations % 10);
                for (int i = 1; i <= perfOrderShipmentPairs; i++) {
                    OrderId orderId = new OrderId(custId.getCustId().intValue() * 10 + i, custId);
                    Order order = new Order("NewOrder" + i + iterations);
                    ShipmentId shipmentId = new ShipmentId(orderId.getOrderId().intValue() * 10 + i, orderId);
                    Shipment shipment = new Shipment("newShipment" + i + iterations);
                    args.add(orderId);
                    args.add(order);
                    args.add(shipmentId);
                    args.add(shipment);
                }
                Set filter = new HashSet();
                filter.add(custId);
                if (iterations > warmupIterations) {
                    startTime = NanoTimer.getTime();
                }
                e.withFilter(filter).setArguments(args).execute("perfTxFunction").getResult();
                if (startTime > 0) {
                    perfTime += NanoTimer.getTime() - startTime;
                }
            }
            return new Long(perfTime);
        }
    };
    Long perfTxTime = (Long) accessor.invoke(runPerfTxFunction);
    double diff = (perfTime.longValue() - perfTxTime.longValue()) * 1.0;
    double percentDiff = (diff / perfTime.longValue()) * 100;
    LogWriterUtils.getLogWriter().info((totalIterations - warmupIterations) + " iterations of function took:" + +perfTime.longValue() + " Nanos, and transaction function took:" + perfTxTime.longValue() + " Nanos, difference :" + diff + " percentDifference:" + percentDiff);
}
Also used : Order(org.apache.geode.internal.cache.execute.data.Order) ShipmentId(org.apache.geode.internal.cache.execute.data.ShipmentId) HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) Shipment(org.apache.geode.internal.cache.execute.data.Shipment) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) Function(org.apache.geode.cache.execute.Function) Execution(org.apache.geode.cache.execute.Execution) CustId(org.apache.geode.internal.cache.execute.data.CustId) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) HashSet(java.util.HashSet) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 13 with Shipment

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

the class WANTestBase method putShipmentPartitionedRegionUsingCustId.

public static Map putShipmentPartitionedRegionUsingCustId(int numPuts) {
    assertNotNull(cache);
    assertNotNull(shipmentRegion);
    Map shipmentKeyValue = new HashMap();
    for (int i = 1; i <= numPuts; i++) {
        CustId custid = new CustId(i);
        Shipment shipment = new Shipment("Shipment" + i);
        try {
            shipmentRegion.put(custid, shipment);
            assertTrue(shipmentRegion.containsKey(custid));
            assertEquals(shipment, shipmentRegion.get(custid));
            shipmentKeyValue.put(custid, shipment);
        } catch (Exception e) {
            org.apache.geode.test.dunit.Assert.fail("putShipmentPartitionedRegionUsingCustId : failed while doing put operation in ShipmentPartitionedRegion ", e);
        }
        LogWriterUtils.getLogWriter().info("Shipment :- { " + custid + " : " + shipment + " }");
    }
    return shipmentKeyValue;
}
Also used : HashMap(java.util.HashMap) CustId(org.apache.geode.internal.cache.execute.data.CustId) Shipment(org.apache.geode.internal.cache.execute.data.Shipment) Map(java.util.Map) HashMap(java.util.HashMap) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) PartitionOfflineException(org.apache.geode.cache.persistence.PartitionOfflineException) IOException(java.io.IOException) PRLocallyDestroyedException(org.apache.geode.internal.cache.partitioned.PRLocallyDestroyedException) ExecutionException(java.util.concurrent.ExecutionException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) CacheClosedException(org.apache.geode.cache.CacheClosedException)

Aggregations

Shipment (org.apache.geode.internal.cache.execute.data.Shipment)13 CustId (org.apache.geode.internal.cache.execute.data.CustId)11 OrderId (org.apache.geode.internal.cache.execute.data.OrderId)11 ShipmentId (org.apache.geode.internal.cache.execute.data.ShipmentId)11 IOException (java.io.IOException)9 Region (org.apache.geode.cache.Region)8 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)6 IgnoredException (org.apache.geode.test.dunit.IgnoredException)5 ParseException (java.text.ParseException)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 ExecutionException (java.util.concurrent.ExecutionException)4 CacheClosedException (org.apache.geode.cache.CacheClosedException)4 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)4 PartitionOfflineException (org.apache.geode.cache.persistence.PartitionOfflineException)4 ForceReattemptException (org.apache.geode.internal.cache.ForceReattemptException)4 HARegion (org.apache.geode.internal.cache.HARegion)4 Order (org.apache.geode.internal.cache.execute.data.Order)4 PRLocallyDestroyedException (org.apache.geode.internal.cache.partitioned.PRLocallyDestroyedException)4 ArrayList (java.util.ArrayList)3