use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.
the class RemoteTransactionDUnitTest method testPRTXGet.
@Test
public void testPRTXGet() {
Host host = Host.getHost(0);
VM accessor = host.getVM(0);
VM datastore = host.getVM(1);
initAccessorAndDataStore(accessor, datastore, 0);
final TXId txId = (TXId) accessor.invoke(new DoOpsInTX(OP.GET));
datastore.invoke(new SerializableCallable() {
public Object call() throws Exception {
TXManagerImpl mgr = getGemfireCache().getTxManager();
assertTrue(mgr.isHostedTxInProgress(txId));
TXStateProxy tx = mgr.getHostedTXState(txId);
System.out.println("TXRS:" + tx.getRegions());
// 2 buckets for the two puts we
assertEquals(3, tx.getRegions().size());
// plus the dist. region
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);
assertNotNull(es.getValue(key, r, false));
assertFalse(es.isDirty());
}
}
return null;
}
});
accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
CacheTransactionManager mgr = getGemfireCache().getTxManager();
mgr.commit();
verifyAfterCommit(OP.GET);
return null;
}
});
}
use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.
the class RemoteTransactionDUnitTest method testRemoteExceptionThrown.
@Test
public void testRemoteExceptionThrown() {
Host host = Host.getHost(0);
VM acc = host.getVM(0);
VM datastore = host.getVM(1);
initAccessorAndDataStore(acc, datastore, 0);
VM accessor = getVMForTransactions(acc, datastore);
datastore.invoke(new SerializableCallable() {
public Object call() throws Exception {
getGemfireCache().getTxManager().setWriter(new TransactionWriter() {
public void close() {
}
public void beforeCommit(TransactionEvent event) throws TransactionWriterException {
throw new TransactionWriterException("AssertionError");
}
});
return null;
}
});
accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
getGemfireCache().getTxManager().begin();
Region r = getCache().getRegion(CUSTOMER);
r.put(new CustId(8), new Customer("name8", "address8"));
try {
getGemfireCache().getTxManager().commit();
fail("Expected exception not thrown");
} catch (Exception e) {
assertEquals("AssertionError", e.getCause().getMessage());
}
return null;
}
});
}
use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.
the class TransactionsWithDeltaDUnitTest method createRegionOnServer.
private Integer createRegionOnServer(VM vm, final boolean startServer, final boolean accessor) {
return (Integer) vm.invoke(new SerializableCallable() {
public Object call() throws Exception {
createRegion(accessor, 0, null);
if (startServer) {
int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
CacheServer s = getCache().addCacheServer();
s.setPort(port);
s.start();
return port;
}
return 0;
}
});
}
use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.
the class TransactionsWithDeltaDUnitTest method testExceptionThrown.
@Test
public void testExceptionThrown() {
AttributesFactory af = new AttributesFactory();
af.setDataPolicy(DataPolicy.REPLICATE);
af.setScope(Scope.DISTRIBUTED_ACK);
final RegionAttributes attr = af.create();
Host host = Host.getHost(0);
VM vm1 = host.getVM(0);
VM vm2 = host.getVM(1);
final String regionName = getUniqueName();
SerializableCallable createRegion = new SerializableCallable() {
public Object call() throws Exception {
getCache().createRegion(regionName, attr);
return null;
}
};
vm1.invoke(createRegion);
vm2.invoke(createRegion);
final String key = "cust1";
vm1.invoke(new SerializableCallable() {
public Object call() throws Exception {
TXManagerImpl mgr = getGemfireCache().getTxManager();
Region r = getCache().getRegion(regionName);
Customer cust = new Customer(1, "cust1");
r.put(key, cust);
mgr.begin();
cust.setName("");
try {
r.put(key, cust);
fail("exception not thrown");
} catch (UnsupportedOperationInTransactionException expected) {
}
mgr.rollback();
return null;
}
});
}
use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.
the class RemoteTransactionDUnitTest method testTxRemoveAllNotColocated.
@Test
public void testTxRemoveAllNotColocated() {
Host host = Host.getHost(0);
VM acc = host.getVM(0);
VM datastore1 = host.getVM(1);
VM datastore2 = host.getVM(3);
datastore2.invoke(new SerializableCallable() {
public Object call() throws Exception {
createRegion(false, /* accessor */
0, null);
return null;
}
});
initAccessorAndDataStore(acc, datastore1, 0);
VM accessor = getVMForTransactions(acc, datastore1);
final CustId custId0 = new CustId(0);
final CustId custId1 = new CustId(1);
final CustId custId2 = new CustId(2);
final CustId custId3 = new CustId(3);
final CustId custId4 = new CustId(4);
final CustId custId20 = new CustId(20);
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 customer2 = new Customer("customer2", "address2");
Customer fakeCust = new Customer("foo2", "bar2");
try {
cust.removeAll(Arrays.asList(custId0, custId4, custId1, custId2, custId3, custId20));
fail("expected exception not thrown");
} catch (TransactionDataNotColocatedException e) {
mgr.rollback();
}
assertNotNull(cust.get(custId0));
assertNotNull(cust.get(custId1));
assertNotNull(cust.get(custId2));
assertNotNull(cust.get(custId3));
assertNotNull(cust.get(custId4));
return mgr.getTransactionId();
}
});
}
Aggregations