use of org.apache.geode.internal.cache.execute.data.OrderId in project geode by apache.
the class ClientServerTransactionDUnitTest method testPutallRollbackInServer.
@Test
public void testPutallRollbackInServer() throws Exception {
Host host = Host.getHost(0);
VM server = host.getVM(0);
VM client = host.getVM(1);
int port1 = createRegionsAndStartServer(server, false);
createClientRegionAndPopulateData(client, port1, false);
server.invoke(new SerializableCallable("verify tx") {
public Object call() throws Exception {
TXManagerImpl mgr = getGemfireCache().getTxManager();
Region<OrderId, Order> orderRegion = getCache().getRegion(ORDER);
mgr.begin();
CustId custId = new CustId(1);
OrderId orderId = new OrderId(1000, custId);
Order expectedOrder = new Order("fooOrder");
Map map = new HashMap();
map.put(orderId, expectedOrder);
orderRegion.putAll(map);
mgr.rollback();
assertNull(orderRegion.get(orderId));
return null;
}
});
}
use of org.apache.geode.internal.cache.execute.data.OrderId in project geode by apache.
the class ClientServerTransactionDUnitTest method testGetAllRollbackInServer.
@Ignore
@Test
public void testGetAllRollbackInServer() throws Exception {
Host host = Host.getHost(0);
VM server = host.getVM(0);
createRegionsAndStartServer(server, false);
server.invoke(new SerializableCallable("verify getAll tx") {
public Object call() throws Exception {
TXManagerImpl mgr = getGemfireCache().getTxManager();
Region<OrderId, Order> orderRegion = getCache().getRegion(ORDER);
orderRegion.getAttributesMutator().setCacheLoader(new CacheLoader() {
public void close() {
}
public Object load(LoaderHelper helper) throws CacheLoaderException {
return new Order(helper.getKey() + "_loaded");
}
});
mgr.begin();
CustId custId = new CustId(1);
OrderId orderId = new OrderId(1000, custId);
Set<OrderId> keys = new HashSet();
keys.add(orderId);
Order order = (orderRegion.getAll(keys)).get(orderId);
assertNotNull(order);
mgr.rollback();
assertNull(orderRegion.getEntry(orderId));
return null;
}
});
}
use of org.apache.geode.internal.cache.execute.data.OrderId in project geode by apache.
the class SingleHopStatsDUnitTest method createdColocatedPRData.
private void createdColocatedPRData(GemFireCacheImpl cache) {
Region customerRegion = cache.getRegion(CUSTOMER_REGION_NAME);
Region orderRegion = cache.getRegion(ORDER_REGION_NAME);
Region shipmentRegion = cache.getRegion(SHIPMENT_REGION_NAME);
for (int i = 0; i <= 20; i++) {
CustId custid = new CustId(i);
Customer customer = new Customer("name" + i, "Address" + i);
customerRegion.put(custid, customer);
for (int j = 1; j <= 10; j++) {
int oid = (i * 10) + j;
OrderId orderId = new OrderId(oid, custid);
Order order = new Order(ORDER_REGION_NAME + oid);
orderRegion.put(orderId, order);
for (int k = 1; k <= 10; k++) {
int sid = (oid * 10) + k;
ShipmentId shipmentId = new ShipmentId(sid, orderId);
Shipment shipment = new Shipment("Shipment" + sid);
shipmentRegion.put(shipmentId, shipment);
}
}
}
ClientMetadataService cms = cache.getClientMetadataService();
Map<String, ClientPartitionAdvisor> regionMetaData = cms.getClientPRMetadata_TEST_ONLY();
assertEquals(3, regionMetaData.size());
assertTrue(regionMetaData.containsKey(customerRegion.getFullPath()));
regionMetaData.get(customerRegion.getFullPath());
metaDataRefreshCount_Customer = ((LocalRegion) customerRegion).getCachePerfStats().getMetaDataRefreshCount();
// hops are not predictable
assertTrue(metaDataRefreshCount_Customer != 0);
regionMetaData.get(orderRegion.getFullPath());
metaDataRefreshCount_Order = ((LocalRegion) orderRegion).getCachePerfStats().getMetaDataRefreshCount();
assertTrue(metaDataRefreshCount_Order == 0);
regionMetaData.get(shipmentRegion.getFullPath());
metaDataRefreshCount_Shipment = ((LocalRegion) shipmentRegion).getCachePerfStats().getMetaDataRefreshCount();
assertTrue(metaDataRefreshCount_Shipment == 0);
}
use of org.apache.geode.internal.cache.execute.data.OrderId in project geode by apache.
the class MyTransactionFunction method verifyTransactionRollback.
private void verifyTransactionRollback(RegionFunctionContext ctx) {
Region custPR = ctx.getDataSet();
Region orderPR = custPR.getCache().getRegion(PRTransactionDUnitTest.OrderPartitionedRegionName);
CacheTransactionManager mgr = custPR.getCache().getCacheTransactionManager();
ArrayList args = (ArrayList) ctx.getArguments();
CustId custId = (CustId) args.get(1);
Customer newCus = (Customer) args.get(2);
OrderId orderId = (OrderId) args.get(3);
Order order = (Order) args.get(4);
Customer oldCustomer = (Customer) custPR.get(custId);
Order oldOrder = (Order) orderPR.get(orderId);
mgr.begin();
custPR.put(custId, newCus);
Customer txCust = (Customer) custPR.get(custId);
orderPR.put(orderId, order);
Order txOrder = (Order) orderPR.get(orderId);
Assert.assertTrue(newCus.equals(txCust), "Expected Customer to be:" + newCus + " but was:" + txCust);
Assert.assertTrue(txOrder.equals(order), "Expected Order to be:" + order + " but was:" + txOrder);
mgr.rollback();
Customer commitedCust = (Customer) custPR.get(custId);
Assert.assertTrue(oldCustomer.equals(commitedCust), "Expected Customer to be:" + oldCustomer + " but was:" + commitedCust);
Order commitedOrder = (Order) orderPR.get(orderId);
Assert.assertTrue(oldOrder.equals(commitedOrder), "Expected Order to be:" + oldOrder + " but was:" + commitedOrder);
mgr.begin();
Assert.assertTrue(custPR.remove(custId, oldCustomer));
orderPR.replace(orderId, order);
mgr.rollback();
Assert.assertTrue(oldCustomer.equals(custPR.get(custId)));
Assert.assertTrue(oldOrder.equals(orderPR.get(orderId)));
mgr.begin();
Assert.assertTrue(custPR.replace(custId, oldCustomer, newCus));
orderPR.remove(orderId, oldOrder);
Assert.assertTrue(null == orderPR.putIfAbsent(orderId, order));
mgr.rollback();
Assert.assertTrue(oldCustomer.equals(custPR.get(custId)));
Assert.assertTrue(oldOrder.equals(orderPR.get(orderId)));
}
use of org.apache.geode.internal.cache.execute.data.OrderId in project geode by apache.
the class MyTransactionFunction method verifyInvalidateOperation.
private void verifyInvalidateOperation(RegionFunctionContext ctx) {
Region custPR = ctx.getDataSet();
Region orderPR = custPR.getCache().getRegion(PRTransactionDUnitTest.OrderPartitionedRegionName);
CacheTransactionManager mgr = custPR.getCache().getCacheTransactionManager();
ArrayList args = (ArrayList) ctx.getArguments();
CustId custId = (CustId) args.get(1);
Customer newCus = (Customer) args.get(2);
OrderId orderId = (OrderId) args.get(3);
Order order = (Order) args.get(4);
Customer oldCustomer = (Customer) custPR.get(custId);
Customer commitedCust = null;
// test destroy rollback
mgr.begin();
custPR.put(custId, newCus);
custPR.invalidate(custId);
orderPR.put(orderId, order);
mgr.rollback();
commitedCust = (Customer) custPR.get(custId);
Assert.assertTrue(oldCustomer.equals(commitedCust), "Expected customer to rollback to:" + oldCustomer + " but was:" + commitedCust);
// test destroy rollback on unmodified entry
mgr.begin();
custPR.invalidate(custId);
orderPR.put(orderId, order);
mgr.rollback();
commitedCust = (Customer) custPR.get(custId);
Assert.assertTrue(oldCustomer.equals(commitedCust), "Expected customer to rollback to:" + oldCustomer + " but was:" + commitedCust);
// test remote destroy
boolean caughtEx = false;
try {
mgr.begin();
custPR.put(custId, new Customer("foo", "bar"));
custPR.invalidate(custId);
custPR.invalidate(new CustId(1));
custPR.invalidate(new CustId(3));
custPR.invalidate(new CustId(7));
mgr.commit();
} catch (Exception e) {
mgr.rollback();
if ((e instanceof TransactionDataNotColocatedException) || (e instanceof TransactionDataRebalancedException)) {
caughtEx = true;
} else if (e instanceof EntryNotFoundException && e.getMessage().matches("Entry not found for key.*1")) {
caughtEx = true;
} else {
throw new TestException("Expected to catch PR remote destroy exception, but caught:" + e.getMessage(), e);
}
}
if (!caughtEx) {
throw new TestException("An Expected exception was not thrown");
}
// test destroy on unmodified entry
mgr.begin();
custPR.invalidate(custId);
orderPR.put(orderId, order);
mgr.commit();
commitedCust = (Customer) custPR.get(custId);
Assert.assertTrue(commitedCust == null, "Expected Customer to be null but was:" + commitedCust);
Order commitedOrder = (Order) orderPR.get(orderId);
Assert.assertTrue(order.equals(commitedOrder), "Expected Order to be:" + order + " but was:" + commitedOrder);
// test destroy on new entry
// TODO: This throws EntryNotFound
/*
* OrderId newOrderId = new OrderId(5000,custId); mgr.begin(); orderPR.put(newOrderId, new
* Order("New Order to be destroyed")); orderPR.invalidate(newOrderId); mgr.commit();
* Assert.assertTrue(orderPR.get(newOrderId)==null,"Did not expect orderId to be present");
*/
}
Aggregations