use of org.apache.geode.internal.cache.execute.data.Order in project geode by apache.
the class RemoteTransactionDUnitTest method verifyAfterRollback.
void verifyAfterRollback(OP op) {
Region<CustId, Customer> custRegion = getCache().getRegion(CUSTOMER);
Region<OrderId, Order> orderRegion = getCache().getRegion(ORDER);
Region<CustId, Customer> refRegion = getCache().getRegion(D_REFERENCE);
assertNotNull(custRegion);
assertNotNull(orderRegion);
assertNotNull(refRegion);
CustId custId = new CustId(1);
OrderId orderId = new OrderId(1, custId);
OrderId orderId2 = new OrderId(2, custId);
OrderId orderId3 = new OrderId(3, custId);
Customer expectedCust;
Order expectedOrder;
Customer expectedRef;
switch(op) {
case PUT:
expectedCust = new Customer("customer1", "address1");
expectedOrder = new Order("order1");
expectedRef = new Customer("customer1", "address1");
assertEquals(expectedCust, custRegion.getEntry(custId).getValue());
assertEquals(expectedOrder, orderRegion.getEntry(orderId).getValue());
getCache().getLogger().info("SWAP:verifyRollback:" + orderRegion);
getCache().getLogger().info("SWAP:verifyRollback:" + orderRegion.getEntry(orderId2));
assertNull(getGemfireCache().getTXMgr().getTXState());
assertNull("" + orderRegion.getEntry(orderId2), orderRegion.getEntry(orderId2));
assertNull(orderRegion.getEntry(orderId3));
assertNull(orderRegion.get(orderId2));
assertNull(orderRegion.get(orderId3));
assertEquals(expectedRef, refRegion.getEntry(custId).getValue());
validateContains(custId, Collections.singleton(orderId), true);
break;
case GET:
expectedCust = custRegion.getEntry(custId).getValue();
expectedOrder = orderRegion.getEntry(orderId).getValue();
expectedRef = refRegion.getEntry(custId).getValue();
validateContains(custId, Collections.singleton(orderId), true);
break;
case DESTROY:
assertTrue(!custRegion.containsKey(custId));
assertTrue(!orderRegion.containsKey(orderId));
assertTrue(!refRegion.containsKey(custId));
validateContains(custId, Collections.singleton(orderId), true);
break;
case INVALIDATE:
assertTrue(custRegion.containsKey(custId));
assertTrue(orderRegion.containsKey(orderId));
assertTrue(refRegion.containsKey(custId));
assertNull(custRegion.get(custId));
assertNull(orderRegion.get(orderId));
assertNull(refRegion.get(custId));
validateContains(custId, Collections.singleton(orderId), true, true);
break;
default:
throw new IllegalStateException();
}
}
use of org.apache.geode.internal.cache.execute.data.Order in project geode by apache.
the class TransactionsWithDeltaDUnitTest method createRegion.
private void createRegion(boolean accessor, int redundantCopies, InterestPolicy interestPolicy) {
AttributesFactory af = new AttributesFactory();
af.setScope(Scope.DISTRIBUTED_ACK);
af.setDataPolicy(DataPolicy.REPLICATE);
af.setCloningEnabled(true);
getCache().createRegion(D_REFERENCE, af.create());
af = new AttributesFactory();
af.setCloningEnabled(true);
if (interestPolicy != null) {
af.setSubscriptionAttributes(new SubscriptionAttributes(interestPolicy));
}
af.setPartitionAttributes(new PartitionAttributesFactory<CustId, Customer>().setTotalNumBuckets(4).setLocalMaxMemory(accessor ? 0 : 1).setPartitionResolver(new CustomerIDPartitionResolver("resolver1")).setRedundantCopies(redundantCopies).create());
getCache().createRegion(CUSTOMER, af.create());
af.setPartitionAttributes(new PartitionAttributesFactory<OrderId, Order>().setTotalNumBuckets(4).setLocalMaxMemory(accessor ? 0 : 1).setPartitionResolver(new CustomerIDPartitionResolver("resolver2")).setRedundantCopies(redundantCopies).setColocatedWith(CUSTOMER).create());
getCache().createRegion(ORDER, af.create());
}
use of org.apache.geode.internal.cache.execute.data.Order in project geode by apache.
the class PRColocationDUnitTest method putOrderPartitionedRegion.
public static void putOrderPartitionedRegion(String partitionedRegionName, int numOfCust) {
assertNotNull(basicGetCache());
Region partitionedregion = basicGetCache().getRegion(Region.SEPARATOR + partitionedRegionName);
assertNotNull(partitionedregion);
for (int i = 1; i <= numOfCust; 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);
assertTrue(partitionedregion.containsKey(orderId));
assertEquals(order, partitionedregion.get(orderId));
} catch (Exception e) {
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.Order in project geode by apache.
the class PRColocationDUnitTest method putOrderPartitionedRegion2.
public static void putOrderPartitionedRegion2(String partitionedRegionName) {
assertNotNull(basicGetCache());
Region partitionedregion = basicGetCache().getRegion(Region.SEPARATOR + partitionedRegionName);
assertNotNull(partitionedregion);
for (int i = 11; i <= 100; 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);
assertTrue(partitionedregion.containsKey(orderId));
assertEquals(order, partitionedregion.get(orderId));
} catch (Exception e) {
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.Order in project geode by apache.
the class MyTransactionFunction method verifyTxStateAndConflicts.
private void verifyTxStateAndConflicts(RegionFunctionContext ctx) {
Region custPR = ctx.getDataSet();
Region orderPR = custPR.getCache().getRegion(PRTransactionDUnitTest.OrderPartitionedRegionName);
ArrayList args = (ArrayList) ctx.getArguments();
CustId custId = (CustId) args.get(1);
CacheTransactionManager mgr = custPR.getCache().getCacheTransactionManager();
OrderId vOrderId = new OrderId(3000, custId);
Order vOrder = new Order("vOrder");
TXManagerImpl mImp = (TXManagerImpl) mgr;
mImp.begin();
orderPR.put(vOrderId, vOrder);
TXStateProxy txState = mImp.internalSuspend();
Iterator it = txState.getRegions().iterator();
Assert.assertTrue(txState.getRegions().size() == 1, "Expected 1 region; " + "found:" + txState.getRegions().size());
LocalRegion lr = (LocalRegion) it.next();
Assert.assertTrue(lr instanceof BucketRegion);
TXRegionState txRegion = txState.readRegion(lr);
TXEntryState txEntry = txRegion.readEntry(txRegion.getEntryKeys().iterator().next());
mImp.internalResume(txState);
orderPR.put(vOrderId, new Order("foo"));
txState = mImp.internalSuspend();
// since both puts were on same key, verify that
// TxRegionState and TXEntryState are same
LocalRegion lr1 = (LocalRegion) txState.getRegions().iterator().next();
Assert.assertTrue(lr == lr1);
TXRegionState txRegion1 = txState.readRegion(lr);
TXEntryState txEntry1 = txRegion1.readEntry(txRegion.getEntryKeys().iterator().next());
Assert.assertTrue(txEntry == txEntry1);
// to check for conflicts, start a new transaction, operate on same key,
// commit the second and expect the first to fail
mImp.begin();
orderPR.put(vOrderId, new Order("foobar"));
mImp.commit();
// now begin the first
mImp.internalResume(txState);
boolean caughtException = false;
try {
mImp.commit();
} catch (CommitConflictException e) {
caughtException = true;
}
if (!caughtException) {
throw new TestException("An expected exception was not thrown");
}
}
Aggregations