use of org.apache.geode.internal.cache.execute.data.CustId in project geode by apache.
the class FixedPartitioningTestBase method putOrderPartitionedRegion.
public static void putOrderPartitionedRegion(String partitionedRegionName) {
assertNotNull(cache);
Region partitionedregion = cache.getRegion(Region.SEPARATOR + partitionedRegionName);
assertNotNull(partitionedregion);
for (int i = 1; i <= 40; i++) {
CustId custid = new CustId(i);
for (int j = 1; j <= 10; j++) {
int oid = (i * 10) + j;
OrderId orderId = new OrderId(oid, custid);
Order order = new Order("OREDR" + oid);
try {
partitionedregion.put(orderId, order);
} catch (Exception e) {
org.apache.geode.test.dunit.Assert.fail("putOrderPartitionedRegion : failed while doing put operation in OrderPartitionedRegion ", e);
}
LogWriterUtils.getLogWriter().info("Order :- { " + orderId + " : " + order + " }");
}
}
}
use of org.apache.geode.internal.cache.execute.data.CustId in project geode by apache.
the class FixedPartitioningTestBase method validateAfterPutPartitionedRegion.
public static void validateAfterPutPartitionedRegion(String customerPartitionedRegionName, String orderPartitionedRegionName, String shipmentPartitionedRegionName) throws ClassNotFoundException {
assertNotNull(cache);
PartitionedRegion customerPartitionedregion = null;
PartitionedRegion orderPartitionedregion = null;
PartitionedRegion shipmentPartitionedregion = null;
try {
customerPartitionedregion = (PartitionedRegion) cache.getRegion(Region.SEPARATOR + customerPartitionedRegionName);
orderPartitionedregion = (PartitionedRegion) cache.getRegion(Region.SEPARATOR + orderPartitionedRegionName);
shipmentPartitionedregion = (PartitionedRegion) cache.getRegion(Region.SEPARATOR + shipmentPartitionedRegionName);
} catch (Exception e) {
org.apache.geode.test.dunit.Assert.fail("validateAfterPutPartitionedRegion : failed while getting the region", e);
}
assertNotNull(customerPartitionedregion);
for (int i = 0; i < 10; i++) {
InternalDistributedMember idmForCustomer = customerPartitionedregion.getBucketPrimary(i);
InternalDistributedMember idmForOrder = orderPartitionedregion.getBucketPrimary(i);
InternalDistributedMember idmForShipment = shipmentPartitionedregion.getBucketPrimary(i);
// take all the keys from the shipment for 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.CustId in project geode by apache.
the class DistributedTransactionDUnitTest method populateRR.
void populateRR() {
Region custRegion = getCache().getRegion(CUSTOMER_RR);
for (int i = 0; i < 5; i++) {
CustId custId = new CustId(i);
Customer customer = new Customer("customer" + i, "address" + i);
custRegion.put(custId, customer);
}
}
use of org.apache.geode.internal.cache.execute.data.CustId in project geode by apache.
the class DistributedTransactionDUnitTest method testTransactionalUpdates.
@Test
public void testTransactionalUpdates() throws Exception {
Host host = Host.getHost(0);
VM server1 = host.getVM(0);
VM server2 = host.getVM(1);
VM server3 = host.getVM(2);
createPR(new VM[] { server2, server3 });
execute(server1, new SerializableCallable() {
@Override
public Object call() throws Exception {
CacheTransactionManager mgr = getGemfireCache().getTxManager();
mgr.setDistributed(true);
mgr.begin();
createPR(false, 0, null);
Region<CustId, Customer> custPR = getCache().getRegion(CUSTOMER_PR);
for (int i = 1; i <= 200; i++) {
custPR.put(new CustId(i), new Customer("name" + i, "addr" + i));
}
assertEquals(200, custPR.size());
mgr.rollback();
// mgr.commit();
mgr.begin();
assertEquals(0, custPR.size());
mgr.commit();
mgr.begin();
for (int i = 1; i <= 200; i++) {
custPR.put(new CustId(i), new Customer("name" + i, "addr" + i));
}
mgr.commit();
// mgr.begin();
for (int i = 1; i <= 200; i++) {
mgr.begin();
custPR.put(new CustId(i), new Customer("name" + i * 2, "addr" + i * 2));
mgr.commit();
}
mgr.begin();
mgr.rollback();
assertEquals(200, custPR.size());
for (int i = 1; i <= 200; i++) {
assertEquals(new Customer("name" + i * 2, "addr" + i * 2), custPR.get(new CustId(i)));
}
return null;
}
});
}
use of org.apache.geode.internal.cache.execute.data.CustId in project geode by apache.
the class DistributedTransactionDUnitTest method testTransactionalKeyBasedUpdates.
@Test
public void testTransactionalKeyBasedUpdates() throws Exception {
Host host = Host.getHost(0);
VM server1 = host.getVM(0);
VM server2 = host.getVM(1);
VM server3 = host.getVM(2);
createPR(new VM[] { server1, server2, server3 });
execute(server1, new SerializableCallable() {
@Override
public Object call() throws Exception {
CacheTransactionManager mgr = getGemfireCache().getTxManager();
mgr.setDistributed(true);
// mgr.begin();
LogWriterI18n logger = getGemfireCache().getLoggerI18n();
Region<CustId, Customer> custPR = getCache().getRegion(CUSTOMER_PR);
for (int i = 1; i <= 2; i++) {
mgr.begin();
logger.fine("TEST:PUT-" + i);
custPR.put(new CustId(i), new Customer("name" + i, "addr" + i));
logger.fine("TEST:COMMIT-" + i);
mgr.commit();
}
// Updates
for (int i = 1; i <= 2; i++) {
CustId custId = new CustId(i);
Customer customer = custPR.get(custId);
assertNotNull(customer);
mgr.begin();
logger.fine("TEST:UPDATE-" + i);
custPR.put(custId, new Customer("name" + i * 2, "addr" + i * 2));
logger.fine("TEST:UPDATED-" + i + "=" + custId + "," + custPR.get(custId));
logger.fine("TEST:UPDATE COMMIT-" + i);
mgr.commit();
logger.fine("TEST:POSTCOMMIT-" + i + "=" + custId + "," + custPR.get(custId));
}
// Verify
for (int i = 1; i <= 2; i++) {
CustId custId = new CustId(i);
Customer customer = custPR.get(custId);
assertNotNull(customer);
logger.fine("TEST:VERIFYING-" + i);
assertEquals(new Customer("name" + i * 2, "addr" + i * 2), customer);
}
return null;
}
});
}
Aggregations