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;
}
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());
}
}
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);
}
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);
}
}
}
}
}
}
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;
}
Aggregations