use of org.apache.geode.internal.cache.execute.data.Customer in project geode by apache.
the class RemoteTransactionDUnitTest method testPRTXGetEntryOnRemoteSide.
/**
* Make sure that getEntry returns null properly and values when it should
*/
@Test
public void testPRTXGetEntryOnRemoteSide() {
Host host = Host.getHost(0);
VM accessor = host.getVM(0);
VM datastore = host.getVM(1);
initAccessorAndDataStore(accessor, datastore, 0);
datastore.invoke(new SerializableCallable() {
public Object call() throws Exception {
return null;
}
});
accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
Region cust = getCache().getRegion(CUSTOMER);
CustId sup = new CustId(7);
Region.Entry e = cust.getEntry(sup);
assertNull(e);
CustId custId = new CustId(5);
cust.put(custId, new Customer("customer5", "address5"));
Region.Entry ee = cust.getEntry(custId);
assertNotNull(ee);
CacheTransactionManager mgr = getGemfireCache().getTxManager();
mgr.begin();
Region.Entry e2 = cust.getEntry(sup);
assertNull(e2);
mgr.commit();
Region.Entry e3 = cust.getEntry(sup);
assertNull(e3);
mgr.begin();
Customer dawg = new Customer("dawg", "dawgaddr");
cust.put(sup, dawg);
Region.Entry e4 = cust.getEntry(sup);
assertNotNull(e4);
assertEquals(dawg, e4.getValue());
mgr.commit();
Region.Entry e5 = cust.getEntry(sup);
assertNotNull(e5);
assertEquals(dawg, e5.getValue());
return null;
}
});
}
use of org.apache.geode.internal.cache.execute.data.Customer in project geode by apache.
the class RemoteTransactionDUnitTest method doTestBasicBulkOP.
private void doTestBasicBulkOP(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, 1);
if (op.equals(OP.REMOVEALL)) {
// for remove all populate more data
accessor.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
Region<CustId, Customer> custRegion = getCache().getRegion(CUSTOMER);
for (int i = 0; i < 50; i++) {
custRegion.put(new CustId(i), new Customer("name" + i, "address" + i));
}
return null;
}
});
}
final List ds1Buckets = (List) datastore1.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
// do local operations with rollback and then commit
Map<CustId, Customer> custMap = new HashMap<>();
Region<CustId, Customer> custRegion = getCache().getRegion(CUSTOMER);
PartitionedRegion pr = ((PartitionedRegion) custRegion);
List localBuckets = pr.getLocalPrimaryBucketsListTestOnly();
System.out.println("localBuckets:" + localBuckets);
for (int i = 10; i < 20; i++) {
int hash = PartitionedRegionHelper.getHashKey(i, pr.getPartitionAttributes().getTotalNumBuckets());
if (localBuckets.contains(hash)) {
custMap.put(new CustId(i), new Customer("name" + i, "address" + i));
}
}
System.out.println("SWAP:custMap:" + custMap);
int regionSize = custRegion.size();
getCache().getCacheTransactionManager().begin();
if (op.equals(OP.PUTALL)) {
custRegion.putAll(custMap);
} else {
custRegion.removeAll(custMap.keySet());
}
getCache().getCacheTransactionManager().rollback();
assertEquals(regionSize, custRegion.size());
// now commit
getCache().getCacheTransactionManager().begin();
if (op.equals(OP.PUTALL)) {
custRegion.putAll(custMap);
} else {
custRegion.removeAll(custMap.keySet());
}
getCache().getCacheTransactionManager().commit();
assertEquals(getExpectedSize(custMap, regionSize), custRegion.size());
// bulk op on other member
custMap.clear();
for (int i = 10; i < 20; i++) {
int hash = PartitionedRegionHelper.getHashKey(i, pr.getPartitionAttributes().getTotalNumBuckets());
if (!localBuckets.contains(hash)) {
// not on local member
custMap.put(new CustId(i), new Customer("name" + i, "address" + i));
}
}
System.out.println("SWAP:custMap:" + custMap);
regionSize = custRegion.size();
getCache().getCacheTransactionManager().begin();
if (op.equals(OP.PUTALL)) {
custRegion.putAll(custMap);
} else {
custRegion.removeAll(custMap.keySet());
}
getCache().getCacheTransactionManager().rollback();
assertEquals(regionSize, custRegion.size());
// now commit
getCache().getCacheTransactionManager().begin();
if (op.equals(OP.PUTALL)) {
custRegion.putAll(custMap);
} else {
custRegion.removeAll(custMap.keySet());
}
getCache().getCacheTransactionManager().commit();
assertEquals(getExpectedSize(custMap, regionSize), custRegion.size());
return localBuckets;
}
private int getExpectedSize(Map<CustId, Customer> custMap, int regionSize) {
if (op.equals(OP.REMOVEALL)) {
return regionSize - custMap.size();
}
return regionSize + custMap.size();
}
});
accessor.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
// do a transaction on one of the nodes
Map<CustId, Customer> custMap = new HashMap<>();
Region<CustId, Customer> custRegion = getCache().getRegion(CUSTOMER);
for (int i = 20; i < 30; i++) {
int hash = PartitionedRegionHelper.getHashKey(i, custRegion.getAttributes().getPartitionAttributes().getTotalNumBuckets());
if (ds1Buckets.contains(hash)) {
custMap.put(new CustId(i), new Customer("name" + i, "address" + i));
}
}
System.out.println("SWAP:custMap:" + custMap);
int regionSize = custRegion.size();
getCache().getCacheTransactionManager().begin();
if (op.equals(OP.PUTALL)) {
custRegion.putAll(custMap);
} else {
custRegion.removeAll(custMap.keySet());
}
getCache().getCacheTransactionManager().rollback();
assertEquals(regionSize, custRegion.size());
// now commit
getCache().getCacheTransactionManager().begin();
if (op.equals(OP.PUTALL)) {
custRegion.putAll(custMap);
} else {
custRegion.removeAll(custMap.keySet());
}
getCache().getCacheTransactionManager().commit();
assertEquals(getExpectedSize(custMap, regionSize), custRegion.size());
return null;
}
private int getExpectedSize(Map<CustId, Customer> custMap, int regionSize) {
if (op.equals(OP.REMOVEALL)) {
return regionSize - custMap.size();
}
return regionSize + custMap.size();
}
});
}
use of org.apache.geode.internal.cache.execute.data.Customer in project geode by apache.
the class RemoteTransactionDUnitTest method testEntriesIterationOnRR.
@Test
public void testEntriesIterationOnRR() {
Host host = Host.getHost(0);
VM accessor = host.getVM(0);
VM datastore1 = host.getVM(1);
VM datastore2 = host.getVM(2);
initAccessorAndDataStore(accessor, datastore1, datastore2, 0);
accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
Region custRegion = getGemfireCache().getRegion(CUSTOMER);
Region rr = getGemfireCache().getRegion(D_REFERENCE);
TXManagerImpl mgr = getGemfireCache().getTxManager();
mgr.begin();
CustId custId = new CustId(5);
Customer customer = new Customer("customer5", "address5");
custRegion.put(custId, customer);
Set set = rr.entrySet();
Iterator it = set.iterator();
int i = 0;
while (it.hasNext()) {
i++;
it.next();
}
assertEquals(5, i);
// assertTrue(getCustIdSet(5).equals(set));
assertEquals(5, rr.entrySet().size());
rr.put(custId, customer);
set = rr.entrySet();
// assertTrue(getCustIdSet(6).equals(set));
it = set.iterator();
i = 0;
while (it.hasNext()) {
i++;
it.next();
}
assertEquals(6, i);
assertEquals(6, rr.entrySet().size());
assertNotNull(rr.get(custId));
TXStateProxy tx = mgr.internalSuspend();
// assertIndexDetailsEquals(getCustIdSet(5), rr.entrySet());
assertEquals(5, rr.entrySet().size());
assertNull(rr.get(custId));
mgr.internalResume(tx);
mgr.commit();
return null;
}
});
}
use of org.apache.geode.internal.cache.execute.data.Customer in project geode by apache.
the class RemoteTransactionDUnitTest method doNonColocatedbulkOp.
private void doNonColocatedbulkOp(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, 0);
accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
Map custMap = new HashMap();
for (int i = 0; i < 10; i++) {
CustId cId = new CustId(i);
Customer c = new Customer("name" + i, "addr" + i);
custMap.put(cId, c);
}
GemFireCacheImpl cache = getGemfireCache();
cache.getCacheTransactionManager().begin();
Region r = cache.getRegion(CUSTOMER);
try {
switch(op) {
case PUTALL:
r.putAll(custMap);
break;
case GETALL:
r.put(new CustId(1), new Customer("cust1", "addr1"));
r.getAll(custMap.keySet());
break;
default:
break;
}
fail("expected exception not thrown");
} catch (TransactionDataNotColocatedException e) {
}
cache.getCacheTransactionManager().rollback();
return null;
}
});
}
use of org.apache.geode.internal.cache.execute.data.Customer in project geode by apache.
the class RemoteTransactionDUnitTest method testTXWithRICommitInDatastore.
@Test
public void testTXWithRICommitInDatastore() 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);
datastore.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