use of org.apache.geode.internal.cache.execute.data.Customer in project geode by apache.
the class RemoteTransactionDUnitTest method verifyAfterCommit.
void verifyAfterCommit(OP op) {
Region<CustId, Customer> custRegion = getCache().getRegion(CUSTOMER);
Region<CustId, Customer> refRegion = getCache().getRegion(D_REFERENCE);
Region<OrderId, Order> orderRegion = getCache().getRegion(ORDER);
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;
Order expectedOrder2;
Order expectedOrder3;
Customer expectedRef;
switch(op) {
case PUT:
expectedCust = new Customer("foo", "bar");
expectedOrder = new Order("fooOrder");
expectedOrder2 = new Order("fooOrder2");
expectedOrder3 = new Order("fooOrder3");
expectedRef = expectedCust;
assertNotNull(custRegion.getEntry(custId));
assertEquals(expectedCust, custRegion.getEntry(custId).getValue());
/*
* assertNotNull(orderRegion.getEntry(orderId)); assertIndexDetailsEquals(expectedOrder,
* orderRegion.getEntry(orderId).getValue());
*
* assertNotNull(orderRegion.getEntry(orderId2)); assertIndexDetailsEquals(expectedOrder2,
* orderRegion.getEntry(orderId2).getValue());
*
* assertNotNull(orderRegion.getEntry(orderId3)); assertIndexDetailsEquals(expectedOrder3,
* orderRegion.getEntry(orderId3).getValue());
*/
assertNotNull(refRegion.getEntry(custId));
assertEquals(expectedRef, refRegion.getEntry(custId).getValue());
// validateContains(custId, ordersSet, true);
break;
case GET:
expectedCust = custRegion.get(custId);
expectedOrder = orderRegion.get(orderId);
expectedRef = refRegion.get(custId);
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), false);
break;
case INVALIDATE:
boolean validateContainsKey = true;
if (!((GemFireCacheImpl) custRegion.getCache()).isClient()) {
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), validateContainsKey, false);
break;
default:
throw new IllegalStateException();
}
}
use of org.apache.geode.internal.cache.execute.data.Customer in project geode by apache.
the class RemoteTransactionDUnitTest method testTxRemove.
@Test
public void testTxRemove() {
Host host = Host.getHost(0);
VM acc = host.getVM(0);
VM datastore = host.getVM(1);
initAccessorAndDataStore(acc, datastore, 0);
VM accessor = getVMForTransactions(acc, datastore);
final CustId custId = new CustId(1);
final TXId txId = (TXId) accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
Region<CustId, Customer> cust = getGemfireCache().getRegion(CUSTOMER);
Region<CustId, Customer> ref = getGemfireCache().getRegion(D_REFERENCE);
TXManagerImpl mgr = getGemfireCache().getTxManager();
mgr.begin();
Customer customer = new Customer("customer1", "address1");
Customer fakeCust = new Customer("foo", "bar");
assertFalse(cust.remove(custId, fakeCust));
assertTrue(cust.remove(custId, customer));
assertFalse(ref.remove(custId, fakeCust));
assertTrue(ref.remove(custId, customer));
TXStateProxy tx = mgr.internalSuspend();
assertNotNull(cust.get(custId));
assertNotNull(ref.get(custId));
mgr.internalResume(tx);
return mgr.getTransactionId();
}
});
datastore.invoke(new SerializableCallable() {
public Object call() throws Exception {
TXManagerImpl mgr = getGemfireCache().getTxManager();
assertTrue(mgr.isHostedTxInProgress(txId));
TXStateProxy tx = mgr.getHostedTXState(txId);
// 2 buckets for the two puts we
assertEquals(2, tx.getRegions().size());
// different buckets
for (LocalRegion r : tx.getRegions()) {
assertTrue(r instanceof BucketRegion || r instanceof DistributedRegion);
TXRegionState rs = tx.readRegion(r);
for (Object key : rs.getEntryKeys()) {
TXEntryState es = rs.readEntry(key);
assertNull(es.getValue(key, r, false));
assertTrue("key:" + key + " r:" + r.getFullPath(), es.isDirty());
}
}
return null;
}
});
accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
TXManagerImpl mgr = getGemfireCache().getTxManager();
mgr.commit();
Region<CustId, Customer> cust = getGemfireCache().getRegion(CUSTOMER);
Region<CustId, Customer> rr = getGemfireCache().getRegion(D_REFERENCE);
assertNull(cust.get(custId));
assertNull(rr.get(custId));
// check conflict
mgr.begin();
CustId conflictCust = new CustId(2);
Customer customer = new Customer("customer2", "address2");
getGemfireCache().getLoggerI18n().fine("SWAP:removeConflict");
assertTrue(cust.remove(conflictCust, customer));
TXStateProxy tx = mgr.internalSuspend();
cust.put(conflictCust, new Customer("foo", "bar"));
mgr.internalResume(tx);
try {
mgr.commit();
fail("expected exception not thrown");
} catch (CommitConflictException e) {
}
return null;
}
});
}
use of org.apache.geode.internal.cache.execute.data.Customer in project geode by apache.
the class RemoteTransactionDUnitTest method testPRTXGetOnLocalWithLoader.
@Test
public void testPRTXGetOnLocalWithLoader() {
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 {
AttributesMutator am = getCache().getRegion(CUSTOMER).getAttributesMutator();
am.setCacheLoader(new CacheLoader() {
public Object load(LoaderHelper helper) throws CacheLoaderException {
return new Customer("sup dawg", "addr");
}
public void close() {
}
});
CacheTransactionManager mgr = getGemfireCache().getTxManager();
mgr.begin();
Region cust = getCache().getRegion(CUSTOMER);
CustId custId = new CustId(6);
Customer s = (Customer) cust.get(custId);
mgr.commit();
Customer s2 = (Customer) cust.get(custId);
Customer expectedCust = new Customer("sup dawg", "addr");
assertEquals(s, expectedCust);
assertEquals(s2, expectedCust);
return null;
}
});
accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
return null;
}
});
}
use of org.apache.geode.internal.cache.execute.data.Customer in project geode by apache.
the class RemoteTransactionDUnitTest method testPRTXGetOnRemoteWithLoader.
@Test
public void testPRTXGetOnRemoteWithLoader() {
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 {
AttributesMutator am = getCache().getRegion(CUSTOMER).getAttributesMutator();
am.setCacheLoader(new CacheLoader() {
public Object load(LoaderHelper helper) throws CacheLoaderException {
return new Customer("sup dawg", "add");
}
public void close() {
}
});
return null;
}
});
accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
CacheTransactionManager mgr = getGemfireCache().getTxManager();
mgr.begin();
Region cust = getCache().getRegion(CUSTOMER);
Customer s = (Customer) cust.get(new CustId(8));
assertEquals(new Customer("sup dawg", "add"), s);
assertTrue(cust.containsKey(new CustId(8)));
TXStateProxy tx = ((TXManagerImpl) mgr).internalSuspend();
assertFalse(cust.containsKey(new CustId(8)));
((TXManagerImpl) mgr).internalResume(tx);
mgr.commit();
Customer s2 = (Customer) cust.get(new CustId(8));
Customer ex = new Customer("sup dawg", "add");
assertEquals(ex, s);
assertEquals(ex, s2);
return null;
}
});
}
use of org.apache.geode.internal.cache.execute.data.Customer in project geode by apache.
the class RemoteTransactionDUnitTest method testValuesIterationOnRR.
@Test
public void testValuesIterationOnRR() {
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 = (Set) rr.values();
Iterator it = set.iterator();
int i = 0;
while (it.hasNext()) {
i++;
it.next();
}
assertEquals(5, i);
assertTrue(getCustomerSet(5).equals(set));
assertEquals(5, rr.values().size());
rr.put(custId, customer);
set = (Set) rr.values();
assertTrue(getCustomerSet(6).equals(set));
it = set.iterator();
i = 0;
while (it.hasNext()) {
i++;
it.next();
}
assertEquals(6, i);
assertEquals(6, rr.values().size());
assertNotNull(rr.get(custId));
TXStateProxy tx = mgr.internalSuspend();
assertEquals(getCustomerSet(5), rr.values());
assertEquals(5, rr.values().size());
assertNull(rr.get(custId));
mgr.internalResume(tx);
mgr.commit();
return null;
}
});
}
Aggregations