use of org.apache.geode.internal.cache.execute.data.Customer in project geode by apache.
the class DistributedTransactionDUnitTest method testRegionAndEntryVersionsPR.
@Test
public void testRegionAndEntryVersionsPR() throws Exception {
Host host = Host.getHost(0);
VM server1 = host.getVM(0);
VM server2 = host.getVM(1);
createPersistentPR(new VM[] { server1, server2 });
execute(server2, new SerializableCallable() {
@Override
public Object call() throws Exception {
CacheTransactionManager mgr = getGemfireCache().getTxManager();
mgr.setDistributed(true);
getGemfireCache().getLoggerI18n().fine("TEST:DISTTX=" + mgr.isDistributed());
getGemfireCache().getLoggerI18n().fine("TEST:TX BEGIN");
mgr.begin();
Region<CustId, Customer> prRegion = getCache().getRegion(PERSISTENT_CUSTOMER_PR);
CustId custIdOne = new CustId(1);
Customer customerOne = new Customer("name1", "addr1");
getGemfireCache().getLoggerI18n().fine("TEST:TX PUT 1");
prRegion.put(custIdOne, customerOne);
BucketRegion br = ((PartitionedRegion) prRegion).getBucketRegion(custIdOne);
assertEquals(0L, br.getVersionVector().getCurrentVersion());
getGemfireCache().getLoggerI18n().fine("TEST:TX COMMIT 1");
mgr.commit();
// Verify region version on the region
assertEquals(1L, br.getVersionVector().getCurrentVersion());
RegionEntry re = br.getRegionEntry(custIdOne);
getGemfireCache().getLoggerI18n().fine("TEST:VERSION-STAMP:" + re.getVersionStamp());
// Verify region version on the region entry
assertEquals(1L, re.getVersionStamp().getRegionVersion());
// Verify entry version
assertEquals(1, re.getVersionStamp().getEntryVersion());
mgr.begin();
prRegion.put(custIdOne, new Customer("name1_1", "addr1"));
getGemfireCache().getLoggerI18n().fine("TEST:TX COMMIT 2");
assertEquals(1L, br.getVersionVector().getCurrentVersion());
mgr.commit();
// Verify region version on the region
assertEquals(2L, br.getVersionVector().getCurrentVersion());
re = br.getRegionEntry(custIdOne);
getGemfireCache().getLoggerI18n().fine("TEST:VERSION-STAMP:" + re.getVersionStamp());
// Verify region version on the region entry
assertEquals(2L, re.getVersionStamp().getRegionVersion());
// Verify entry version
assertEquals(2, re.getVersionStamp().getEntryVersion());
return null;
}
});
execute(server1, new SerializableCallable() {
@Override
public Object call() throws Exception {
Region<CustId, Customer> prRegion = getCache().getRegion(PERSISTENT_CUSTOMER_PR);
CustId custIdOne = new CustId(1);
BucketRegion br = ((PartitionedRegion) prRegion).getBucketRegion(custIdOne);
// Verify region version on the region
assertEquals(2L, br.getVersionVector().getCurrentVersion());
// Verify region version ont the region entry
RegionEntry re = br.getRegionEntry(custIdOne);
assertEquals(2L, re.getVersionStamp().getRegionVersion());
// Verify entry version
assertEquals(2, re.getVersionStamp().getEntryVersion());
return null;
}
});
}
use of org.apache.geode.internal.cache.execute.data.Customer in project geode by apache.
the class DistributedTransactionDUnitTest method testTransactionalPutOnPartitionedRegion.
@Test
public void testTransactionalPutOnPartitionedRegion() throws Exception {
Host host = Host.getHost(0);
VM server1 = host.getVM(0);
VM server2 = host.getVM(1);
VM server3 = host.getVM(2);
createPR(new VM[] { server1, server2, server3 });
execute(server1, new SerializableCallable() {
@Override
public Object call() throws Exception {
CacheTransactionManager mgr = getGemfireCache().getTxManager();
mgr.setDistributed(true);
LogWriterI18n logger = getGemfireCache().getLoggerI18n();
mgr.begin();
logger.fine("TEST:Commit-1");
mgr.commit();
mgr.begin();
Region<CustId, Customer> custRegion = getCache().getRegion(CUSTOMER_PR);
CustId custId = new CustId(1);
Customer expectedCustomer = custRegion.get(custId);
assertNull(expectedCustomer);
// Perform a put
CustId custIdOne = new CustId(1);
Customer customerOne = new Customer("name1", "addr1");
logger.fine("TEST:Put-1");
custRegion.put(custIdOne, customerOne);
// Rollback the transaction
logger.fine("TEST:Rollback-1");
mgr.rollback();
mgr.begin();
// Verify that the entry is rolled back
expectedCustomer = custRegion.get(custId);
assertNull(expectedCustomer);
// Perform two more puts and a commit
CustId custIdTwo = new CustId(2);
Customer customerTwo = new Customer("name2", "addr2");
CustId custIdThree = new CustId(3);
Customer customerThree = new Customer("name3", "addr3");
logger.fine("TEST:Put-2");
custRegion.put(custIdTwo, customerTwo);
logger.fine("TEST:Put-3");
custRegion.put(custIdThree, customerThree);
logger.fine("TEST:Commit-2");
mgr.commit();
mgr.begin();
// Verify data
assertEquals(2, custRegion.size());
assertTrue(custRegion.containsKey(custIdTwo));
assertTrue(custRegion.containsKey(custIdThree));
assertEquals(customerTwo, custRegion.get(custIdTwo));
assertEquals(customerThree, custRegion.get(custIdThree));
// Perform one more put but don't commit
logger.fine("TEST:Put-4");
Customer customerOneMod = new Customer("name1", "addr11");
custRegion.put(custIdOne, customerOneMod);
// Verify data
assertEquals(3, custRegion.size());
assertTrue(custRegion.containsKey(custIdOne));
assertEquals(customerOneMod, custRegion.get(custIdOne));
logger.fine("TEST:Commit-3");
mgr.commit();
return null;
}
});
}
use of org.apache.geode.internal.cache.execute.data.Customer in project geode by apache.
the class DistributedTransactionDUnitTest method testTxWorksWithNewNodeJoining.
@Test
public void testTxWorksWithNewNodeJoining() throws Exception {
Host host = Host.getHost(0);
VM server1 = host.getVM(0);
VM server2 = host.getVM(1);
VM server3 = host.getVM(2);
createPR(new VM[] { server1, server2 });
class Ops extends SerializableCallable {
private boolean flag = false;
public void setWaitFlag(boolean value) {
flag = value;
}
@Override
public Object call() throws Exception {
CacheTransactionManager mgr = getGemfireCache().getTxManager();
mgr.setDistributed(true);
mgr.begin();
Region<CustId, Customer> prRegion = getCache().getRegion(CUSTOMER_PR);
CustId custIdOne = new CustId(1);
Customer customerOne = new Customer("name1", "addr1");
prRegion.put(custIdOne, customerOne);
// Install the hook at this point
TestObserver o = TestObserver.getInstance();
o.setFlag(true);
while (o.getFlag()) {
Thread.currentThread().sleep(1000);
}
mgr.commit();
// Verify
assertEquals(1, prRegion.size());
assertTrue(prRegion.containsKey(custIdOne));
return null;
}
}
server1.invokeAsync(() -> new Ops().call());
// Now create cache on the third server and let it join the distributed system.
createPR(new VM[] { server3 });
// Let the original thread move on by signalling the flag
execute(server1, new SerializableCallable() {
@Override
public Object call() throws Exception {
TestObserver o = TestObserver.getInstance();
o.setFlag(false);
return null;
}
});
}
use of org.apache.geode.internal.cache.execute.data.Customer in project geode by apache.
the class DistributedTransactionDUnitTest method testGetIsolated.
@Test
public void testGetIsolated() throws Exception {
Host host = Host.getHost(0);
VM server1 = host.getVM(0);
VM server2 = host.getVM(1);
VM server3 = host.getVM(2);
createPR(new VM[] { server1, server2, server3 });
createRR(new VM[] { server1, server2, server3 });
execute(server1, new SerializableCallable() {
@Override
public Object call() throws Exception {
CacheTransactionManager mgr = getGemfireCache().getTxManager();
mgr.setDistributed(true);
mgr.begin();
mgr.commit();
mgr.begin();
Region<CustId, Customer> custPR = getCache().getRegion(CUSTOMER_PR);
CustId custIdOne = new CustId(1);
Customer customerOne = new Customer("name1", "addr1");
custPR.put(custIdOne, customerOne);
Region<CustId, Customer> replicatedRegion = getCache().getRegion(CUSTOMER_RR);
replicatedRegion.put(custIdOne, customerOne);
CustId custIdTwo = new CustId(2);
Customer customerTwo = new Customer("name2", "addr2");
replicatedRegion.put(custIdTwo, customerTwo);
// Verify before commit
assertEquals(2, replicatedRegion.size());
assertEquals(customerOne, replicatedRegion.get(custIdOne));
assertEquals(customerTwo, replicatedRegion.get(custIdTwo));
// Perform commit
mgr.commit();
// Verify after commit
assertEquals(2, replicatedRegion.size());
assertEquals(customerOne, replicatedRegion.get(custIdOne));
assertEquals(customerTwo, replicatedRegion.get(custIdTwo));
return null;
}
});
}
use of org.apache.geode.internal.cache.execute.data.Customer in project geode by apache.
the class PRTransactionDUnitTest method testCacheListenerCallbacks.
@Ignore("BUG46661")
@Test
public void testCacheListenerCallbacks() {
createPopulateAndVerifyCoLocatedPRs(1);
SerializableCallable registerListeners = new SerializableCallable() {
public Object call() throws Exception {
Region custRegion = basicGetCache().getRegion(Region.SEPARATOR + CustomerPartitionedRegionName);
custRegion.getAttributesMutator().addCacheListener(new TransactionListener2());
return null;
}
};
accessor.invoke(registerListeners);
dataStore1.invoke(registerListeners);
dataStore2.invoke(registerListeners);
dataStore3.invoke(registerListeners);
accessor.invoke(new SerializableCallable("run function") {
public Object call() throws Exception {
PartitionedRegion pr = (PartitionedRegion) basicGetCache().getRegion(Region.SEPARATOR + CustomerPartitionedRegionName);
PartitionedRegion orderpr = (PartitionedRegion) basicGetCache().getRegion(Region.SEPARATOR + OrderPartitionedRegionName);
CustId custId = new CustId(2);
Customer newCus = new Customer("foo", "bar");
Order order = new Order("fooOrder");
OrderId orderId = new OrderId(22, custId);
ArrayList args = new ArrayList();
Function txFunction = new MyTransactionFunction();
FunctionService.registerFunction(txFunction);
Execution e = FunctionService.onRegion(pr);
Set filter = new HashSet();
boolean caughtException = false;
// test transaction non-coLocated operations
filter.clear();
args.clear();
args.add(new Integer(VERIFY_LISTENER_CALLBACK));
LogWriterUtils.getLogWriter().info("VERIFY_LISTENER_CALLBACK");
args.add(custId);
args.add(newCus);
args.add(orderId);
args.add(order);
filter.add(custId);
caughtException = false;
e.withFilter(filter).setArguments(args).execute(txFunction.getId()).getResult();
return null;
}
});
}
Aggregations