Search in sources :

Example 21 with ShipmentId

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

the class WANTestBase method putShipmentPartitionedRegion.

public static Map putShipmentPartitionedRegion(int numPuts) {
    assertNotNull(cache);
    assertNotNull(shipmentRegion);
    Map shipmentKeyValue = new HashMap();
    for (int i = 1; i <= numPuts; i++) {
        CustId custid = new CustId(i);
        int oid = i + 1;
        OrderId orderId = new OrderId(oid, custid);
        int sid = oid + 1;
        ShipmentId shipmentId = new ShipmentId(sid, orderId);
        Shipment shipment = new Shipment("Shipment" + sid);
        try {
            shipmentRegion.put(shipmentId, shipment);
            assertTrue(shipmentRegion.containsKey(shipmentId));
            assertEquals(shipment, shipmentRegion.get(shipmentId));
            shipmentKeyValue.put(shipmentId, shipment);
        } catch (Exception e) {
            org.apache.geode.test.dunit.Assert.fail("putShipmentPartitionedRegion : failed while doing put operation in ShipmentPartitionedRegion ", e);
        }
        LogWriterUtils.getLogWriter().info("Shipment :- { " + shipmentId + " : " + shipment + " }");
    }
    return shipmentKeyValue;
}
Also used : ShipmentId(org.apache.geode.internal.cache.execute.data.ShipmentId) HashMap(java.util.HashMap) CustId(org.apache.geode.internal.cache.execute.data.CustId) Shipment(org.apache.geode.internal.cache.execute.data.Shipment) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) 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 22 with ShipmentId

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

the class SingleHopStatsDUnitTest method getPR.

private void getPR(String FromClient, boolean colocated) {
    Cache cache = CacheFactory.getAnyInstance();
    Region region = cache.getRegion(Region_Name);
    Region customerRegion = cache.getRegion(CUSTOMER_REGION_NAME);
    Region orderRegion = cache.getRegion(ORDER_REGION_NAME);
    Region shipmentRegion = cache.getRegion("SHIPMENT");
    if (!colocated) {
        for (int i = 0; i < 226; i++) {
            region.get(i);
        }
        ClientMetadataService cms = ((GemFireCacheImpl) cache).getClientMetadataService();
        Map<String, ClientPartitionAdvisor> regionMetaData = cms.getClientPRMetadata_TEST_ONLY();
        assertEquals(1, regionMetaData.size());
        regionMetaData.get(region.getFullPath());
        assertEquals(metaDataRefreshCount, ((LocalRegion) region).getCachePerfStats().getMetaDataRefreshCount());
    } else {
        for (int i = 0; i <= 20; i++) {
            CustId custid = new CustId(i);
            customerRegion.get(custid);
            for (int j = 1; j <= 10; j++) {
                int oid = (i * 10) + j;
                OrderId orderId = new OrderId(oid, custid);
                orderRegion.get(orderId);
                for (int k = 1; k <= 10; k++) {
                    int sid = (oid * 10) + k;
                    ShipmentId shipmentId = new ShipmentId(sid, orderId);
                    shipmentRegion.get(shipmentId);
                }
            }
        }
        ClientMetadataService cms = ((GemFireCacheImpl) cache).getClientMetadataService();
        Map<String, ClientPartitionAdvisor> regionMetaData = cms.getClientPRMetadata_TEST_ONLY();
        assertEquals(3, regionMetaData.size());
        assertTrue(regionMetaData.containsKey(customerRegion.getFullPath()));
        regionMetaData.get(customerRegion.getFullPath());
        assertEquals(metaDataRefreshCount_Customer, ((LocalRegion) customerRegion).getCachePerfStats().getMetaDataRefreshCount());
        regionMetaData.get(orderRegion.getFullPath());
        assertEquals(metaDataRefreshCount_Order, ((LocalRegion) orderRegion).getCachePerfStats().getMetaDataRefreshCount());
        regionMetaData.get(shipmentRegion.getFullPath());
        assertEquals(metaDataRefreshCount_Shipment, ((LocalRegion) shipmentRegion).getCachePerfStats().getMetaDataRefreshCount());
    }
}
Also used : ShipmentId(org.apache.geode.internal.cache.execute.data.ShipmentId) CustId(org.apache.geode.internal.cache.execute.data.CustId) ClientMetadataService(org.apache.geode.cache.client.internal.ClientMetadataService) Region(org.apache.geode.cache.Region) ClientPartitionAdvisor(org.apache.geode.cache.client.internal.ClientPartitionAdvisor) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) Cache(org.apache.geode.cache.Cache)

Example 23 with ShipmentId

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

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

the class PRColocationDUnitTest method validateAfterPutPartitionedRegion.

public static void validateAfterPutPartitionedRegion(String customerPartitionedRegionName, String orderPartitionedRegionName, String shipmentPartitionedRegionName) throws ClassNotFoundException {
    assertNotNull(basicGetCache());
    PartitionedRegion customerPartitionedregion = null;
    PartitionedRegion orderPartitionedregion = null;
    PartitionedRegion shipmentPartitionedregion = null;
    try {
        customerPartitionedregion = (PartitionedRegion) basicGetCache().getRegion(Region.SEPARATOR + customerPartitionedRegionName);
        orderPartitionedregion = (PartitionedRegion) basicGetCache().getRegion(Region.SEPARATOR + orderPartitionedRegionName);
        shipmentPartitionedregion = (PartitionedRegion) basicGetCache().getRegion(Region.SEPARATOR + shipmentPartitionedRegionName);
    } catch (Exception e) {
        Assert.fail("validateAfterPutPartitionedRegion : failed while getting the region", e);
    }
    assertNotNull(customerPartitionedregion);
    for (int i = 1; i <= 10; i++) {
        InternalDistributedMember idmForCustomer = customerPartitionedregion.getBucketPrimary(i);
        InternalDistributedMember idmForOrder = orderPartitionedregion.getBucketPrimary(i);
        InternalDistributedMember idmForShipment = shipmentPartitionedregion.getBucketPrimary(i);
        // take all the keys from the shipmentfor each bucket
        Set customerKey = customerPartitionedregion.getBucketKeys(i);
        assertNotNull(customerKey);
        Iterator customerIterator = customerKey.iterator();
        while (customerIterator.hasNext()) {
            CustId custId = (CustId) customerIterator.next();
            assertNotNull(customerPartitionedregion.get(custId));
            Set orderKey = orderPartitionedregion.getBucketKeys(i);
            assertNotNull(orderKey);
            Iterator orderIterator = orderKey.iterator();
            while (orderIterator.hasNext()) {
                OrderId orderId = (OrderId) orderIterator.next();
                if (custId.equals(orderId.getCustId())) {
                    LogWriterUtils.getLogWriter().info(orderId + "belongs to node " + idmForCustomer + " " + idmForOrder);
                    assertEquals(idmForCustomer, idmForOrder);
                }
                Set shipmentKey = shipmentPartitionedregion.getBucketKeys(i);
                assertNotNull(shipmentKey);
                Iterator shipmentIterator = shipmentKey.iterator();
                while (shipmentIterator.hasNext()) {
                    ShipmentId shipmentId = (ShipmentId) shipmentIterator.next();
                    // assertNotNull(shipmentPartitionedregion.get(shipmentId));
                    if (orderId.equals(shipmentId.getOrderId())) {
                        LogWriterUtils.getLogWriter().info(shipmentId + "belongs to node " + idmForOrder + " " + idmForShipment);
                    }
                }
            }
        }
    }
}
Also used : ShipmentId(org.apache.geode.internal.cache.execute.data.ShipmentId) Set(java.util.Set) HashSet(java.util.HashSet) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) CustId(org.apache.geode.internal.cache.execute.data.CustId) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Iterator(java.util.Iterator) 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 ShipmentId

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

the class CustomerIDPartitionResolver method getRoutingObject.

public Serializable getRoutingObject(EntryOperation opDetails) {
    Serializable routingbject = null;
    if (opDetails.getKey() instanceof ShipmentId) {
        ShipmentId shipmentId = (ShipmentId) opDetails.getKey();
        routingbject = shipmentId.getOrderId().getCustId();
    }
    if (opDetails.getKey() instanceof OrderId) {
        OrderId orderId = (OrderId) opDetails.getKey();
        routingbject = orderId.getCustId();
    } else if (opDetails.getKey() instanceof CustId) {
        CustId custId = (CustId) opDetails.getKey();
        routingbject = custId.getCustId();
    }
    return routingbject;
}
Also used : ShipmentId(org.apache.geode.internal.cache.execute.data.ShipmentId) Serializable(java.io.Serializable) CustId(org.apache.geode.internal.cache.execute.data.CustId) OrderId(org.apache.geode.internal.cache.execute.data.OrderId)

Aggregations

OrderId (org.apache.geode.internal.cache.execute.data.OrderId)25 ShipmentId (org.apache.geode.internal.cache.execute.data.ShipmentId)25 CustId (org.apache.geode.internal.cache.execute.data.CustId)23 Shipment (org.apache.geode.internal.cache.execute.data.Shipment)11 Region (org.apache.geode.cache.Region)10 IOException (java.io.IOException)9 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)8 ParseException (java.text.ParseException)5 HARegion (org.apache.geode.internal.cache.HARegion)4 Order (org.apache.geode.internal.cache.execute.data.Order)4 IgnoredException (org.apache.geode.test.dunit.IgnoredException)4 Serializable (java.io.Serializable)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Set (java.util.Set)3 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 ExecutionException (java.util.concurrent.ExecutionException)2 CacheClosedException (org.apache.geode.cache.CacheClosedException)2