use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.
the class DistributedTransactionDUnitTest method testTransactionalPutOnReplicatedRegion.
@Test
public void testTransactionalPutOnReplicatedRegion() throws Exception {
Host host = Host.getHost(0);
VM server1 = host.getVM(0);
VM server2 = host.getVM(1);
VM server3 = host.getVM(2);
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> custRegion = getCache().getRegion(CUSTOMER_RR);
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");
custRegion.put(custIdOne, customerOne);
// Rollback the transaction
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");
custRegion.put(custIdTwo, customerTwo);
custRegion.put(custIdThree, customerThree);
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
custRegion.put(custIdOne, customerOne);
// Verify data
assertEquals(3, custRegion.size());
assertTrue(custRegion.containsKey(custIdOne));
assertEquals(customerOne, custRegion.get(custIdOne));
mgr.commit();
return null;
}
});
}
use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.
the class Bug45934DUnitTest method unsetRemoteFlag.
private void unsetRemoteFlag(final VM remote) {
SerializableCallable create = new SerializableCallable() {
@Override
public Object call() throws Exception {
AbstractUpdateOperation.test_InvalidVersion = false;
return null;
}
};
remote.invoke(create);
}
use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.
the class Bug45934DUnitTest method verify.
private void verify(VM vm, final String name, final int count) {
SerializableCallable verify = new SerializableCallable() {
@Override
public Object call() throws Exception {
Region<Integer, Integer> r = getCache().getRegion(name);
assertEquals(count, r.size());
for (int i = 0; i < count; i++) {
assertEquals(i, (int) r.get(i));
}
return null;
}
};
vm.invoke(verify);
}
use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.
the class Bug45934DUnitTest method createRemoteRegion.
private void createRemoteRegion(final VM remote, final String name) {
SerializableCallable create = new SerializableCallable() {
@Override
public Object call() throws Exception {
CacheFactory cf = new CacheFactory();
cf.set(MCAST_PORT, "45934");
cf.set(CONSERVE_SOCKETS, "false");
getCache(cf).<Integer, Integer>createRegionFactory(RegionShortcut.REPLICATE_PERSISTENT).create(name);
AbstractUpdateOperation.test_InvalidVersion = true;
return null;
}
};
remote.invoke(create);
}
use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.
the class Bug41733DUnitTest method getBucketList.
protected Set<Integer> getBucketList(VM vm0, final String regionName) {
SerializableCallable getBuckets = new SerializableCallable("get buckets") {
public Object call() throws Exception {
Cache cache = getCache();
PartitionedRegion region = (PartitionedRegion) cache.getRegion(regionName);
return new TreeSet<Integer>(region.getDataStore().getAllLocalBucketIds());
}
};
return (Set<Integer>) vm0.invoke(getBuckets);
}
Aggregations