use of org.apache.geode.internal.cache.execute.data.Order in project geode by apache.
the class RemoteTransactionDUnitTest method populateData.
void populateData() {
Region custRegion = getCache().getRegion(CUSTOMER);
Region orderRegion = getCache().getRegion(ORDER);
Region refRegion = getCache().getRegion(D_REFERENCE);
for (int i = 0; i < 5; i++) {
CustId custId = new CustId(i);
Customer customer = new Customer("customer" + i, "address" + i);
OrderId orderId = new OrderId(i, custId);
Order order = new Order("order" + i);
custRegion.put(custId, customer);
orderRegion.put(orderId, order);
refRegion.put(custId, customer);
}
}
use of org.apache.geode.internal.cache.execute.data.Order in project geode by apache.
the class RemoteTransactionDUnitTest method doTestIterator.
private void doTestIterator(final OP iteratorType, final int redundancy, final OP op) {
Host host = Host.getHost(0);
VM accessor = host.getVM(0);
VM datastore1 = host.getVM(1);
VM datastore2 = host.getVM(2);
initAccessorAndDataStore(accessor, datastore1, datastore2, redundancy);
accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
Region custRegion = getCache().getRegion(CUSTOMER);
Set originalSet;
TXManagerImpl mgr = getGemfireCache().getTxManager();
mgr.begin();
switch(iteratorType) {
case KEYS:
originalSet = getCustIdSet(5);
assertTrue(originalSet.containsAll(custRegion.keySet()));
assertEquals(5, custRegion.keySet().size());
break;
case VALUES:
originalSet = getCustomerSet(5);
assertTrue(originalSet.containsAll(custRegion.values()));
assertEquals(5, custRegion.values().size());
break;
case ENTRIES:
Set originalKeySet = getCustIdSet(5);
Set originalValueSet = getCustomerSet(5);
Set entrySet = new HashSet();
Region.Entry entry;
for (Iterator it = custRegion.entrySet().iterator(); it.hasNext(); ) {
entrySet.add(it.next());
}
for (Iterator it = entrySet.iterator(); it.hasNext(); ) {
entry = (Entry) it.next();
assertTrue(originalKeySet.contains(entry.getKey()));
assertTrue(originalValueSet.contains(entry.getValue()));
}
assertEquals(5, custRegion.entrySet().size());
break;
default:
throw new IllegalArgumentException();
}
assertNotNull(mgr.getTXState());
return null;
}
});
datastore1.invoke(verifyNoTxState);
datastore2.invoke(verifyNoTxState);
accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
Region custRegion = getCache().getRegion(CUSTOMER);
Region orderRegion = getCache().getRegion(ORDER);
TXManagerImpl mgr = getGemfireCache().getTxManager();
assertNotNull(mgr.getTXState());
int expectedSetSize = 0;
switch(op) {
case PUT:
CustId custId = new CustId(5);
OrderId orderId = new OrderId(5, custId);
custRegion.put(custId, new Customer("customer5", "address5"));
orderRegion.put(orderId, new Order("order5"));
expectedSetSize = 6;
break;
case DESTROY:
CustId custId1 = new CustId(4);
OrderId orderId1 = new OrderId(4, custId1);
custRegion.destroy(custId1);
orderRegion.destroy(orderId1);
expectedSetSize = 4;
break;
default:
throw new IllegalStateException();
}
Set expectedSet;
switch(iteratorType) {
case KEYS:
expectedSet = getCustIdSet(expectedSetSize);
assertTrue(expectedSet.containsAll(custRegion.keySet()));
assertEquals(expectedSetSize, custRegion.keySet().size());
break;
case VALUES:
expectedSet = getCustomerSet(expectedSetSize);
assertTrue(expectedSet.containsAll(custRegion.values()));
assertEquals(expectedSetSize, custRegion.values().size());
break;
case ENTRIES:
Set originalKeySet = getCustIdSet(expectedSetSize);
Set originalValueSet = getCustomerSet(expectedSetSize);
Set entrySet = new HashSet();
Region.Entry entry;
for (Iterator it = custRegion.entrySet().iterator(); it.hasNext(); ) {
entrySet.add(it.next());
}
for (Iterator it = entrySet.iterator(); it.hasNext(); ) {
entry = (Entry) it.next();
assertTrue(originalKeySet.contains(entry.getKey()));
assertTrue(originalValueSet.contains(entry.getValue()));
}
assertEquals(expectedSetSize, custRegion.entrySet().size());
break;
default:
throw new IllegalArgumentException();
}
return null;
}
});
final Integer txOnDatastore1 = (Integer) datastore1.invoke(getNumberOfTXInProgress);
final Integer txOnDatastore2 = (Integer) datastore2.invoke(getNumberOfTXInProgress);
assertEquals(1, txOnDatastore1 + txOnDatastore2);
accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
CacheTransactionManager mgr = getGemfireCache().getTxManager();
mgr.commit();
return null;
}
});
final Integer txOnDatastore1_1 = (Integer) datastore1.invoke(getNumberOfTXInProgress);
final Integer txOnDatastore2_2 = (Integer) datastore2.invoke(getNumberOfTXInProgress);
assertEquals(0, txOnDatastore1_1 + txOnDatastore2_2);
datastore1.invoke(new SerializableCallable() {
CustId custId;
Customer customer;
PartitionedRegion custRegion;
int originalSetSize;
int expectedSetSize;
public Object call() throws Exception {
TXManagerImpl mgr = getGemfireCache().getTXMgr();
custRegion = (PartitionedRegion) getGemfireCache().getRegion(CUSTOMER);
mgr.begin();
doLocalOp();
Set expectedSet;
switch(iteratorType) {
case KEYS:
expectedSet = getExpectedCustIdSet();
assertEquals(expectedSet, custRegion.keySet());
assertEquals(expectedSetSize, custRegion.keySet().size());
break;
case VALUES:
expectedSet = getExpectedCustomerSet();
assertEquals(expectedSet, custRegion.values());
assertEquals(expectedSetSize, custRegion.values().size());
break;
case ENTRIES:
Set originalKeySet = getExpectedCustIdSet();
Set originalValueSet = getExpectedCustomerSet();
Set entrySet = new HashSet();
Region.Entry entry;
for (Iterator it = custRegion.entrySet().iterator(); it.hasNext(); ) {
entrySet.add(it.next());
}
for (Iterator it = entrySet.iterator(); it.hasNext(); ) {
entry = (Entry) it.next();
assertTrue(originalKeySet.contains(entry.getKey()));
assertTrue(originalValueSet.contains(entry.getValue()));
}
assertEquals(expectedSetSize, custRegion.entrySet().size());
break;
default:
throw new IllegalArgumentException();
}
mgr.commit();
return null;
}
private void doLocalOp() {
switch(op) {
case PUT:
for (int i = 6; ; i++) {
custId = new CustId(i);
customer = new Customer("customer" + i, "address" + i);
int bucketId = PartitionedRegionHelper.getHashKey(custRegion, custId);
InternalDistributedMember primary = custRegion.getBucketPrimary(bucketId);
if (primary.equals(getGemfireCache().getMyId())) {
custRegion.put(custId, customer);
break;
}
}
originalSetSize = 6;
expectedSetSize = 7;
break;
case DESTROY:
for (int i = 3; ; i--) {
custId = new CustId(i);
customer = new Customer("customer" + i, "address" + i);
int bucketId = PartitionedRegionHelper.getHashKey(custRegion, custId);
InternalDistributedMember primary = custRegion.getBucketPrimary(bucketId);
if (primary.equals(getGemfireCache().getMyId())) {
custRegion.destroy(custId);
break;
}
}
originalSetSize = 4;
expectedSetSize = 3;
break;
default:
throw new IllegalStateException();
}
}
private Set getExpectedCustIdSet() {
Set retVal = getCustIdSet(originalSetSize);
switch(op) {
case PUT:
retVal.add(custId);
break;
case DESTROY:
retVal.remove(custId);
break;
default:
throw new IllegalStateException();
}
return retVal;
}
private Set getExpectedCustomerSet() {
Set retVal = getCustomerSet(originalSetSize);
switch(op) {
case PUT:
retVal.add(customer);
break;
case DESTROY:
retVal.remove(customer);
break;
default:
throw new IllegalStateException();
}
return retVal;
}
});
}
use of org.apache.geode.internal.cache.execute.data.Order in project geode by apache.
the class RemoteTransactionDUnitTest method testNonColocatedTX.
/**
* When we have narrowed down on a target node for a transaction, test that we throw an exception
* if that node does not host primary for subsequent entries
*/
@Test
public void testNonColocatedTX() {
Host host = Host.getHost(0);
VM accessor = host.getVM(0);
VM datastore1 = host.getVM(1);
VM datastore2 = host.getVM(2);
datastore2.invoke(new SerializableCallable() {
public Object call() throws Exception {
createRegion(false, 1, null);
return null;
}
});
initAccessorAndDataStore(accessor, datastore1, 1);
accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
Region<CustId, Customer> custRegion = getCache().getRegion(CUSTOMER);
Region<OrderId, Order> orderRegion = getCache().getRegion(ORDER);
CacheTransactionManager mgr = getGemfireCache().getTxManager();
mgr.begin();
try {
put10Entries(custRegion, orderRegion);
fail("Expected TransactionDataNotColocatedException not thrown");
} catch (TransactionDataNotColocatedException e) {
}
mgr.rollback();
put10Entries(custRegion, orderRegion);
mgr.begin();
try {
put10Entries(custRegion, orderRegion);
fail("Expected TransactionDataNotColocatedException not thrown");
} catch (TransactionDataNotColocatedException e) {
}
mgr.rollback();
return null;
}
private void put10Entries(Region custRegion, Region orderRegion) {
for (int i = 0; i < 10; i++) {
CustId custId = new CustId(i);
Customer customer = new Customer("customer" + i, "address" + i);
OrderId orderId = new OrderId(i, custId);
Order order = new Order("order" + i);
custRegion.put(custId, customer);
orderRegion.put(orderId, order);
}
}
});
}
use of org.apache.geode.internal.cache.execute.data.Order in project geode by apache.
the class RemoteTransactionDUnitTest method validateContains.
void validateContains(CustId custId, Set<OrderId> ordersSet, boolean containsKey, boolean containsValue) {
Region<CustId, Customer> custRegion = getCache().getRegion(CUSTOMER);
Region<OrderId, Order> orderRegion = getCache().getRegion(ORDER);
Region<CustId, Order> refRegion = getCache().getRegion(D_REFERENCE);
boolean rContainsKC = custRegion.containsKey(custId);
boolean rContainsKO = containsKey;
for (OrderId o : ordersSet) {
getGemfireCache().getLoggerI18n().fine("SWAP:rContainsKO:" + rContainsKO + " containsKey:" + orderRegion.containsKey(o));
rContainsKO = rContainsKO && orderRegion.containsKey(o);
}
boolean rContainsKR = refRegion.containsKey(custId);
boolean rContainsVC = custRegion.containsValueForKey(custId);
boolean rContainsVO = containsValue;
for (OrderId o : ordersSet) {
rContainsVO = rContainsVO && orderRegion.containsValueForKey(o);
}
boolean rContainsVR = refRegion.containsValueForKey(custId);
assertEquals(containsKey, rContainsKC);
assertEquals(containsKey, rContainsKO);
assertEquals(containsKey, rContainsKR);
assertEquals(containsValue, rContainsVR);
assertEquals(containsValue, rContainsVC);
assertEquals(containsValue, rContainsVO);
if (containsKey) {
Region.Entry eC = custRegion.getEntry(custId);
for (OrderId o : ordersSet) {
assertNotNull(orderRegion.getEntry(o));
}
Region.Entry eR = refRegion.getEntry(custId);
assertNotNull(eC);
assertNotNull(eR);
// assertIndexDetailsEquals(1,custRegion.size());
// assertIndexDetailsEquals(1,orderRegion.size());
// assertIndexDetailsEquals(1,refRegion.size());
} else {
// assertIndexDetailsEquals(0,refRegion.size());
try {
Region.Entry eC = custRegion.getEntry(custId);
assertNull("should have had an EntryNotFoundException:" + eC, eC);
} catch (EntryNotFoundException enfe) {
// this is what we expect
}
try {
for (OrderId o : ordersSet) {
assertNull("should have had an EntryNotFoundException:" + orderRegion.getEntry(o), orderRegion.getEntry(o));
}
} catch (EntryNotFoundException enfe) {
// this is what we expect
}
try {
Region.Entry eR = refRegion.getEntry(custId);
assertNull("should have had an EntryNotFoundException:" + eR, eR);
} catch (EntryNotFoundException enfe) {
// this is what we expect
}
}
}
use of org.apache.geode.internal.cache.execute.data.Order in project geode by apache.
the class RemoteTransactionDUnitTest method testTXWithRI.
@Test
public void testTXWithRI() throws Exception {
Host host = Host.getHost(0);
VM accessor = host.getVM(0);
VM datastore = host.getVM(1);
VM client = host.getVM(2);
initAccessorAndDataStore(accessor, datastore, 0);
int port = startServer(datastore);
createClientRegion(client, port, false, true);
accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
Region<CustId, Customer> custRegion = getCache().getRegion(CUSTOMER);
Region<OrderId, Order> orderRegion = getCache().getRegion(ORDER);
Region<CustId, Customer> refRegion = getCache().getRegion(D_REFERENCE);
CustId custId = new CustId(1);
OrderId orderId = new OrderId(1, custId);
getCache().getCacheTransactionManager().begin();
custRegion.put(custId, new Customer("foo", "bar"));
orderRegion.put(orderId, new Order("fooOrder"));
refRegion.put(custId, new Customer("foo", "bar"));
getCache().getCacheTransactionManager().commit();
return null;
}
});
client.invoke(new SerializableCallable() {
public Object call() throws Exception {
Region<CustId, Customer> custRegion = getCache().getRegion(CUSTOMER);
Region<OrderId, Order> orderRegion = getCache().getRegion(ORDER);
Region<CustId, Customer> refRegion = getCache().getRegion(D_REFERENCE);
final ClientListener cl = (ClientListener) custRegion.getAttributes().getCacheListeners()[0];
WaitCriterion waitForListenerInvocation = new WaitCriterion() {
public boolean done() {
return cl.invoked;
}
public String description() {
return "listener was never invoked";
}
};
Wait.waitForCriterion(waitForListenerInvocation, 10 * 1000, 10, true);
return null;
}
});
}
Aggregations