use of org.apache.geode.internal.cache.execute.data.Customer in project geode by apache.
the class ClientServerTransactionDUnitTest method testSuspendResumeOnDifferentThreads.
@Test
public void testSuspendResumeOnDifferentThreads() {
Host host = Host.getHost(0);
VM server1 = host.getVM(0);
VM server2 = host.getVM(1);
VM client = host.getVM(2);
final int port1 = createRegionsAndStartServer(server1, false);
final int port2 = createRegionsAndStartServer(server2, false);
client.invoke(new SerializableCallable() {
public Object call() throws Exception {
ClientCacheFactory ccf = new ClientCacheFactory();
ccf.addPoolServer("localhost", /* getServerHostName(Host.getHost(0)) */
port1);
ccf.addPoolServer("localhost", port2);
ccf.setPoolSubscriptionEnabled(false);
ccf.setPoolLoadConditioningInterval(1);
ccf.set(LOG_LEVEL, getDUnitLogLevel());
ClientCache cCache = getClientCache(ccf);
ClientRegionFactory<CustId, Customer> custrf = cCache.createClientRegionFactory(ClientRegionShortcut.PROXY);
ClientRegionFactory<Integer, String> refrf = cCache.createClientRegionFactory(ClientRegionShortcut.PROXY);
Region<Integer, String> r = refrf.create(D_REFERENCE);
Region<CustId, Customer> pr = custrf.create(CUSTOMER);
final TXManagerImpl mgr = getGemfireCache().getTxManager();
CustId custId = new CustId(10);
mgr.begin();
pr.put(custId, new Customer("name10", "address10"));
r.put(10, "value10");
final TXStateProxy txState = mgr.internalSuspend();
assertNull(pr.get(custId));
assertNull(r.get(10));
final CountDownLatch latch = new CountDownLatch(1);
Thread t = new Thread(new Runnable() {
public void run() {
mgr.internalResume(txState);
mgr.commit();
latch.countDown();
}
});
t.start();
latch.await();
assertEquals(new Customer("name10", "address10"), pr.get(custId));
assertEquals("value10", r.get(10));
return null;
}
});
}
use of org.apache.geode.internal.cache.execute.data.Customer in project geode by apache.
the class ClientServerTransactionDUnitTest method doTxOps.
void doTxOps(Region<Integer, String> r, Region<CustId, Customer> pr) {
for (int i = 0; i < 5; i++) {
CustId custId = new CustId(i);
Customer cust = new Customer("name" + i, "address" + i);
getGemfireCache().getLogger().info("putting:" + custId);
pr.put(custId, cust);
r.put(i, "value" + i);
}
}
use of org.apache.geode.internal.cache.execute.data.Customer in project geode by apache.
the class ClientServerTransactionDUnitTest method testCleanupAfterClientAndProxyFailure.
@Test
public void testCleanupAfterClientAndProxyFailure() {
Host host = Host.getHost(0);
VM accessor = host.getVM(0);
VM datastore = host.getVM(1);
final boolean cachingProxy = false;
// some other VMs seem to be hanging around and have the region this
disconnectAllFromDS();
// tests uses
final int port1 = createRegionsAndStartServerWithTimeout(accessor, true, 5);
createRegionOnServerWithTimeout(datastore, false, false, 5);
System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "bridge.disableShufflingOfEndpoints", "true");
ClientCacheFactory ccf = new ClientCacheFactory();
setCCF(port1, ccf);
ClientCache cCache = getClientCache(ccf);
ClientRegionFactory<CustId, Customer> custrf = cCache.createClientRegionFactory(cachingProxy ? ClientRegionShortcut.CACHING_PROXY : ClientRegionShortcut.PROXY);
ClientRegionFactory<Integer, String> refrf = cCache.createClientRegionFactory(cachingProxy ? ClientRegionShortcut.CACHING_PROXY : ClientRegionShortcut.PROXY);
Region<Integer, String> r = refrf.create(D_REFERENCE);
Region<CustId, Customer> pr = custrf.create(CUSTOMER);
TXManagerImpl mgr = getGemfireCache().getTxManager();
mgr.begin();
doTxOps(r, pr);
final DistributedMember myId = cCache.getDistributedSystem().getDistributedMember();
SerializableCallable verifyExists = new SerializableCallable("verify txstate for client exists") {
public Object call() throws Exception {
TXManagerImpl txmgr = getGemfireCache().getTxManager();
Set states = txmgr.getTransactionsForClient((InternalDistributedMember) myId);
// only one in-progress transaction
assertEquals(1, states.size());
return null;
}
};
accessor.invoke(verifyExists);
datastore.invoke(verifyExists);
accessor.invoke(() -> closeCache());
accessor.invoke(() -> disconnectFromDS());
SerializableCallable verifyExpired = new SerializableCallable("verify txstate is expired") {
public Object call() throws Exception {
final TXManagerImpl txmgr = getGemfireCache().getTxManager();
return verifyTXStateExpired(myId, txmgr);
}
};
try {
datastore.invoke(verifyExpired);
} finally {
cCache.close();
}
}
use of org.apache.geode.internal.cache.execute.data.Customer in project geode by apache.
the class ClientServerTransactionDUnitTest method testClientCommitAndDataStoreGetsEvent.
@Test
public void testClientCommitAndDataStoreGetsEvent() 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 ServerListener());
return null;
}
});
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(1);
// OrderId orderId = new OrderId(1, custId);
getCache().getCacheTransactionManager().begin();
custRegion.put(custId, new Customer("foo", "bar"));
// orderRegion.put(orderId, new Order("fooOrder"));
// refRegion.put(custId, new Customer("foo", "bar"));
getCache().getCacheTransactionManager().commit();
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);
ServerListener l = (ServerListener) custRegion.getAttributes().getCacheListeners()[0];
getCache().getLogger().info("SWAP:CLIENTinvoked:" + l.invoked);
assertTrue(l.invoked);
return null;
}
});
}
use of org.apache.geode.internal.cache.execute.data.Customer 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;
}
});
}
Aggregations