use of org.apache.geode.internal.cache.execute.data.CustId in project geode by apache.
the class ClientServerTransactionDUnitTest method doFunctionWork.
private void doFunctionWork(final boolean commit) {
disconnectAllFromDS();
Host host = Host.getHost(0);
VM server1 = host.getVM(0);
VM server2 = host.getVM(1);
VM client = host.getVM(2);
final int port2 = createRegionsAndStartServer(server2, false);
final int port = createRegionsAndStartServer(server1, true);
IgnoredException.addIgnoredException("ClassCastException");
SerializableRunnable suspectStrings = new SerializableRunnable("suspect string") {
public void run() {
InternalDistributedSystem.getLoggerI18n().convertToLogWriter().info("<ExpectedException action=add>" + "ClassCastException" + "</ExpectedException>" + "<ExpectedException action=add>" + "TransactionDataNodeHasDeparted" + "</ExpectedException>");
}
};
server1.invoke(suspectStrings);
server2.invoke(suspectStrings);
try {
client.invoke(new SerializableCallable() {
public Object call() throws Exception {
System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "bridge.disableShufflingOfEndpoints", "true");
ClientCacheFactory ccf = new ClientCacheFactory();
ccf.addPoolServer("localhost", /* getServerHostName(Host.getHost(0)) */
port);
setCCF(port2, ccf);
// these settings were used to manually check that tx operation stats were being updated
// ccf.set(STATISTIC_SAMPLING_ENABLED, "true");
// ccf.set(STATISTIC_ARCHIVE_FILE, "clientStats.gfs");
ClientCache cCache = getClientCache(ccf);
ClientRegionFactory<Integer, String> crf = cCache.createClientRegionFactory(ClientRegionShortcut.PROXY);
Region<Integer, String> customer = crf.create(CUSTOMER);
cCache.getLogger().info("<ExpectedException action=add>" + "ClassCastException" + "</ExpectedException>" + "<ExpectedException action=add>" + "TransactionDataNodeHasDeparted" + "</ExpectedException>");
Region cust = getCache().getRegion(CUSTOMER);
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().fine("SWAP:doing first get from client");
assertNull(cust.get(new CustId(0)));
assertNull(cust.get(new CustId(1)));
ArrayList args = new ArrayList();
args.add(new CustId(0));
args.add(new Customer("name0", "address0"));
args.add(null);
List result = (List) FunctionService.onRegion(cust).setArguments(args).execute(new TXFunction()).getResult();
TransactionId txId = (TransactionId) result.get(0);
assertNotNull(txId);
args = new ArrayList();
args.add(new CustId(1));
args.add(new Customer("name1", "address1"));
args.add(txId);
result = (List) FunctionService.onRegion(cust).setArguments(args).execute(new TXFunction()).getResult();
TransactionId txId2 = (TransactionId) result.get(0);
assertEquals(txId, txId2);
// invoke ClientCommitFunction
try {
if (commit) {
FunctionService.onServer(getCache()).setArguments(new CustId(0)).execute(new CommitFunction()).getResult();
} else {
FunctionService.onServer(getCache()).setArguments(new CustId(0)).execute(new RollbackFunction()).getResult();
}
fail("expected exception not thrown");
} catch (FunctionException e) {
assertTrue(e.getCause() instanceof ClassCastException);
}
List list = null;
if (commit) {
list = (List) FunctionService.onServer(getCache()).setArguments(txId).execute(new CommitFunction()).getResult();
} else {
list = (List) FunctionService.onServer(getCache()).setArguments(txId).execute(new RollbackFunction()).getResult();
}
assertEquals(Boolean.TRUE, list.get(0));
if (commit) {
assertEquals(new Customer("name0", "address0"), cust.get(new CustId(0)));
assertEquals(new Customer("name1", "address1"), cust.get(new CustId(1)));
} else {
assertNull(cust.get(new CustId(0)));
assertNull(cust.get(new CustId(1)));
}
return null;
}
});
} finally {
suspectStrings = new SerializableRunnable("suspect string") {
public void run() {
InternalDistributedSystem.getLoggerI18n().convertToLogWriter().info("<ExpectedException action=remove>" + "ClassCastException" + "</ExpectedException>" + "<ExpectedException action=remove>" + "TransactionDataNodeHasDeparted" + "</ExpectedException>");
}
};
server1.invoke(suspectStrings);
server2.invoke(suspectStrings);
client.invoke(suspectStrings);
}
}
use of org.apache.geode.internal.cache.execute.data.CustId in project geode by apache.
the class ClientServerTransactionDUnitTest method doTestFunctionFromPeer.
private void doTestFunctionFromPeer(final boolean commit) {
Host host = Host.getHost(0);
VM accessor = host.getVM(0);
VM peer1 = host.getVM(1);
VM peer2 = host.getVM(2);
createRegionOnServer(peer1);
createRegionOnServer(peer2);
createRegionOnServer(accessor, false, true);
final TransactionId txId = (TransactionId) peer1.invoke(new SerializableCallable() {
public Object call() throws Exception {
PartitionedRegion r = (PartitionedRegion) getCache().getRegion(CUSTOMER);
CustId cust = null;
DistributedMember myId = getCache().getDistributedSystem().getDistributedMember();
List<CustId> keys = new ArrayList<CustId>();
for (int i = 0; i < 10; i++) {
cust = new CustId(i);
int bucketId = PartitionedRegionHelper.getHashKey(r, cust);
if (!myId.equals(r.getBucketPrimary(bucketId))) {
keys.add(cust);
}
}
assertTrue(keys.size() > 2);
CacheTransactionManager mgr = getCache().getCacheTransactionManager();
mgr.begin();
for (CustId custId : keys) {
r.put(cust, new Customer("newname", "newaddress"));
}
return mgr.suspend();
}
});
assertNotNull(txId);
accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
Execution exe = FunctionService.onMember(((TXId) txId).getMemberId()).setArguments(txId);
List list = null;
if (commit) {
list = (List) exe.execute(new CommitFunction()).getResult();
} else {
list = (List) exe.execute(new RollbackFunction()).getResult();
}
assertEquals(1, list.size());
assertTrue((Boolean) list.get(0));
return null;
}
});
}
use of org.apache.geode.internal.cache.execute.data.CustId in project geode by apache.
the class ClientServerTransactionDUnitTest method testGetAllRollbackInServer.
@Ignore
@Test
public void testGetAllRollbackInServer() throws Exception {
Host host = Host.getHost(0);
VM server = host.getVM(0);
createRegionsAndStartServer(server, false);
server.invoke(new SerializableCallable("verify getAll tx") {
public Object call() throws Exception {
TXManagerImpl mgr = getGemfireCache().getTxManager();
Region<OrderId, Order> orderRegion = getCache().getRegion(ORDER);
orderRegion.getAttributesMutator().setCacheLoader(new CacheLoader() {
public void close() {
}
public Object load(LoaderHelper helper) throws CacheLoaderException {
return new Order(helper.getKey() + "_loaded");
}
});
mgr.begin();
CustId custId = new CustId(1);
OrderId orderId = new OrderId(1000, custId);
Set<OrderId> keys = new HashSet();
keys.add(orderId);
Order order = (orderRegion.getAll(keys)).get(orderId);
assertNotNull(order);
mgr.rollback();
assertNull(orderRegion.getEntry(orderId));
return null;
}
});
}
use of org.apache.geode.internal.cache.execute.data.CustId in project geode by apache.
the class ClientServerTransactionDUnitTest method testClientInitiatedInvalidates.
@Test
public void testClientInitiatedInvalidates() 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(accessor);
createClientRegion(client, port, false, true);
datastore.invoke(new SerializableCallable() {
public Object call() throws Exception {
Region custRegion = getCache().getRegion(CUSTOMER);
custRegion.getAttributesMutator().addCacheListener(new ClientListener());
return null;
}
});
/*
* Test a no-op commit: put/invalidate
*/
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);
CustId custId = new CustId(1777777777);
getCache().getCacheTransactionManager().begin();
custRegion.put(custId, new Customer("foo", "bar"));
custRegion.invalidate(custId);
// orderRegion.put(orderId, new Order("fooOrder"));
// refRegion.put(custId, new Customer("foo", "bar"));
getCache().getCacheTransactionManager().commit();
return null;
}
});
/*
* Validate nothing came through
*/
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);
ClientListener cl = (ClientListener) custRegion.getAttributes().getCacheListeners()[0];
getCache().getLogger().info("SWAP:CLIENTinvoked:" + cl.invoked);
assertTrue(cl.invoked);
assertEquals(1, cl.putCount);
assertEquals(1, cl.invokeCount);
assertEquals(0, cl.invalidateCount);
CustId custId = new CustId(1777777777);
assertTrue(custRegion.containsKey(custId));
assertTrue(!custRegion.containsValueForKey(custId));
cl.reset();
return null;
}
});
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);
ClientListener cl = (ClientListener) custRegion.getAttributes().getCacheListeners()[0];
getCache().getLogger().info("SWAP:CLIENTinvoked:" + cl.invoked);
assertTrue(cl.invoked);
assertEquals(1, cl.putCount);
assertEquals(1, cl.invokeCount);
CustId custId = new CustId(1777777777);
assertTrue(custRegion.containsKey(custId));
assertTrue(!custRegion.containsValueForKey(custId));
cl.reset();
return null;
}
});
/*
* Ok lets do a put in tx, then an invalidate in a another tx and make sure it invalidates on
* client and server
*/
client.invoke(doAPutInTx);
client.invoke(doAnInvalidateInTx);
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);
ClientListener cl = (ClientListener) custRegion.getAttributes().getCacheListeners()[0];
getCache().getLogger().info("SWAP:CLIENTinvoked:" + cl.invoked);
assertTrue(cl.invoked);
assertEquals("totalEvents should be 2 but its:" + cl.invokeCount, 2, cl.invokeCount);
assertEquals("it should be 1 but its:" + cl.invalidateCount, 1, cl.invalidateCount);
assertEquals("it should be 1 but its:" + cl.putCount, 1, cl.putCount);
CustId custId = new CustId(1);
assertTrue(custRegion.containsKey(custId));
assertFalse(custRegion.containsValueForKey(custId));
return null;
}
});
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);
ClientListener cl = (ClientListener) custRegion.getAttributes().getCacheListeners()[0];
getCache().getLogger().info("SWAP:CLIENTinvoked:" + cl.invoked);
assertTrue(cl.invoked);
assertEquals("totalEvents should be 2 but its:" + cl.invokeCount, 2, cl.invokeCount);
assertEquals("it should be 1 but its:" + cl.invalidateCount, 1, cl.invalidateCount);
assertEquals("it should be 1 but its:" + cl.putCount, 1, cl.putCount);
return null;
}
});
}
use of org.apache.geode.internal.cache.execute.data.CustId in project geode by apache.
the class ClientServerTransactionDUnitTest method doBasicFunctionExecution.
private void doBasicFunctionExecution(VM client, VM accessor, VM datastore) {
int datastorePort = createRegionsAndStartServer(datastore, false);
int accessorPort = accessor == null ? 0 : createRegionsAndStartServer(accessor, true);
final int port = accessorPort == 0 ? datastorePort : accessorPort;
createClientRegion(client, port, true);
class BasicTransactionalFunction extends FunctionAdapter {
static final String ID = "BasicTransactionalFunction";
@Override
public void execute(FunctionContext context) {
getGemfireCache().getLogger().info("SWAP:in function");
RegionFunctionContext ctx = (RegionFunctionContext) context;
Region pr = ctx.getDataSet();
pr.put(new CustId(0), new Customer("name0", "address0"));
pr.replace(new CustId(1), new Customer("name1", "address1"));
pr.put(new CustId(10), new Customer("name10", "address10"));
pr.put(new CustId(11), new Customer("name11", "address11"));
Region r = ctx.getDataSet().getRegionService().getRegion(D_REFERENCE);
r.put(new CustId(10), new Customer("name10", "address10"));
r.put(new CustId(11), new Customer("name11", "address11"));
ctx.getResultSender().lastResult(Boolean.TRUE);
}
@Override
public String getId() {
return ID;
}
}
SerializableCallable registerFunction = new SerializableCallable() {
public Object call() throws Exception {
FunctionService.registerFunction(new BasicTransactionalFunction());
return null;
}
};
datastore.invoke(registerFunction);
if (accessor != null) {
accessor.invoke(registerFunction);
}
client.invoke(new SerializableCallable() {
public Object call() throws Exception {
FunctionService.registerFunction(new BasicTransactionalFunction());
Region<CustId, Customer> pr = getGemfireCache().getRegion(CUSTOMER);
Region<CustId, Customer> r = getGemfireCache().getRegion(D_REFERENCE);
TXManagerImpl mgr = getGemfireCache().getTxManager();
pr.put(new CustId(0), new Customer("oldname0", "oldaddress0"));
pr.put(new CustId(1), new Customer("oldname1", "oldaddress1"));
mgr.begin();
final Set filter = new HashSet();
filter.add(new CustId(0));
filter.add(new CustId(1));
getGemfireCache().getLogger().info("SWAP:calling execute");
FunctionService.onRegion(pr).withFilter(filter).execute(BasicTransactionalFunction.ID).getResult();
assertEquals(new Customer("name0", "address0"), pr.get(new CustId(0)));
assertEquals(new Customer("name10", "address10"), pr.get(new CustId(10)));
assertEquals(new Customer("name10", "address10"), r.get(new CustId(10)));
TXStateProxy tx = mgr.internalSuspend();
assertEquals(new Customer("oldname0", "oldaddress0"), pr.get(new CustId(0)));
assertEquals(new Customer("oldname1", "oldaddress1"), pr.get(new CustId(1)));
assertNull(pr.get(new CustId(10)));
assertNull(r.get(new CustId(10)));
mgr.internalResume(tx);
mgr.commit();
assertEquals(new Customer("name0", "address0"), pr.get(new CustId(0)));
assertEquals(new Customer("name1", "address1"), pr.get(new CustId(1)));
assertEquals(new Customer("name10", "address10"), pr.get(new CustId(10)));
assertEquals(new Customer("name10", "address10"), r.get(new CustId(10)));
return null;
}
});
}
Aggregations