use of org.apache.geode.internal.cache.execute.data.CustId in project geode by apache.
the class WANTestBase method putOrderPartitionedRegion.
public static Map putOrderPartitionedRegion(int numPuts) {
assertNotNull(cache);
assertNotNull(orderRegion);
Map orderKeyValues = new HashMap();
for (int i = 1; i <= numPuts; i++) {
CustId custid = new CustId(i);
int oid = i + 1;
OrderId orderId = new OrderId(oid, custid);
Order order = new Order("ORDER" + oid);
try {
orderRegion.put(orderId, order);
orderKeyValues.put(orderId, order);
assertTrue(orderRegion.containsKey(orderId));
assertEquals(order, orderRegion.get(orderId));
} catch (Exception e) {
org.apache.geode.test.dunit.Assert.fail("putOrderPartitionedRegion : failed while doing put operation in OrderPartitionedRegion ", e);
}
LogWriterUtils.getLogWriter().info("Order :- { " + orderId + " : " + order + " }");
}
return orderKeyValues;
}
use of org.apache.geode.internal.cache.execute.data.CustId in project geode by apache.
the class WANTestBase method updateShipmentPartitionedRegion.
public static Map updateShipmentPartitionedRegion(int numPuts) {
assertNotNull(cache);
assertNotNull(shipmentRegion);
Map shipmentKeyValue = new HashMap();
for (int i = 1; i <= numPuts; i++) {
CustId custid = new CustId(i);
int oid = i + 1;
OrderId orderId = new OrderId(oid, custid);
int sid = oid + 1;
ShipmentId shipmentId = new ShipmentId(sid, orderId);
Shipment shipment = new Shipment("Shipment" + sid + "_update");
try {
shipmentRegion.put(shipmentId, shipment);
assertTrue(shipmentRegion.containsKey(shipmentId));
assertEquals(shipment, shipmentRegion.get(shipmentId));
shipmentKeyValue.put(shipmentId, shipment);
} catch (Exception e) {
org.apache.geode.test.dunit.Assert.fail("updateShipmentPartitionedRegion : failed while doing put operation in ShipmentPartitionedRegion ", e);
}
LogWriterUtils.getLogWriter().info("Shipment :- { " + shipmentId + " : " + shipment + " }");
}
return shipmentKeyValue;
}
use of org.apache.geode.internal.cache.execute.data.CustId in project geode by apache.
the class ClientServerTransactionDUnitTest method testPutallRollbackInServer.
@Test
public void testPutallRollbackInServer() throws Exception {
Host host = Host.getHost(0);
VM server = host.getVM(0);
VM client = host.getVM(1);
int port1 = createRegionsAndStartServer(server, false);
createClientRegionAndPopulateData(client, port1, false);
server.invoke(new SerializableCallable("verify tx") {
public Object call() throws Exception {
TXManagerImpl mgr = getGemfireCache().getTxManager();
Region<OrderId, Order> orderRegion = getCache().getRegion(ORDER);
mgr.begin();
CustId custId = new CustId(1);
OrderId orderId = new OrderId(1000, custId);
Order expectedOrder = new Order("fooOrder");
Map map = new HashMap();
map.put(orderId, expectedOrder);
orderRegion.putAll(map);
mgr.rollback();
assertNull(orderRegion.get(orderId));
return null;
}
});
}
use of org.apache.geode.internal.cache.execute.data.CustId in project geode by apache.
the class ClientServerTransactionDUnitTest method testClientRollsbackWithPutAllAndRI.
@Test
public void testClientRollsbackWithPutAllAndRI() 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;
}
});
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();
Map map = new HashMap();
map.put(custId, new Customer("foo", "bar"));
custRegion.putAll(map);
// orderRegion.put(orderId, new Order("fooOrder"));
// refRegion.put(custId, new Customer("foo", "bar"));
getCache().getCacheTransactionManager().rollback();
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);
ClientListener cl = (ClientListener) custRegion.getAttributes().getCacheListeners()[0];
getCache().getLogger().info("SWAP:CLIENTinvoked:" + cl.invoked);
assertTrue(!cl.invoked);
assertTrue(!cl.putAllOp);
assertEquals("it should be 0 but its:" + cl.invokeCount, 0, cl.invokeCount);
return null;
}
});
}
use of org.apache.geode.internal.cache.execute.data.CustId in project geode by apache.
the class ClientServerTransactionDUnitTest method testCallbacks.
// Disabled due to bug 47083
@Ignore
@Test
public void testCallbacks() {
Host host = Host.getHost(0);
VM datastore = host.getVM(1);
VM client = host.getVM(2);
int port = createRegionsAndStartServer(datastore, false);
createClientRegion(client, port, true);
class ClientTxListener extends TransactionListenerAdapter {
private boolean afterRollbackInvoked = false;
boolean afterCommitInvoked = false;
@Override
public void afterCommit(TransactionEvent event) {
afterCommitInvoked = true;
verifyEvent(event);
}
@Override
public void afterRollback(TransactionEvent event) {
afterRollbackInvoked = true;
verifyEvent(event);
}
protected void verifyEvent(TransactionEvent event) {
Iterator it = event.getEvents().iterator();
int i = 0;
while (it.hasNext()) {
EntryEvent ev = (EntryEvent) it.next();
if (i == 0)
assertNull(ev.getNewValue());
if (i > 1) {
assertEquals(new CustId(i), ev.getKey());
assertEquals(new Customer("name" + i, "address" + i), ev.getNewValue());
}
assertTrue(ev.isOriginRemote());
i++;
}
assertEquals(5, event.getEvents().size());
}
}
class ClientTxWriter implements TransactionWriter {
boolean txWriterCalled = false;
public void close() {
}
public void beforeCommit(TransactionEvent event) throws TransactionWriterException {
txWriterCalled = true;
Iterator it = event.getEvents().iterator();
int i = 0;
while (it.hasNext()) {
EntryEvent ev = (EntryEvent) it.next();
if (i == 0)
assertNull(ev.getNewValue());
if (i > 1) {
assertEquals(new CustId(i), ev.getKey());
assertEquals(new Customer("name" + i, "address" + i), ev.getNewValue());
}
assertTrue(ev.isOriginRemote());
i++;
}
assertEquals(5, event.getEvents().size());
}
}
class ClientListener extends CacheListenerAdapter {
boolean invoked = false;
@Override
public void afterCreate(EntryEvent event) {
CustId c = (CustId) event.getKey();
if (c.getCustId() > 1) {
invoked = true;
}
// we document that client transaction are proxied to the server
// and that the callback should be handled appropriately (hence true)
assertTrue(event.isOriginRemote());
assertTrue(event.isOriginRemote());
}
@Override
public void afterUpdate(EntryEvent event) {
assertFalse(event.isOriginRemote());
}
}
class ClientWriter extends CacheWriterAdapter {
@Override
public void beforeCreate(EntryEvent event) throws CacheWriterException {
CustId c = (CustId) event.getKey();
if (c.getCustId() < 2) {
return;
}
fail("cache writer should not be invoked");
}
@Override
public void beforeUpdate(EntryEvent event) throws CacheWriterException {
fail("cache writer should not be invoked");
}
}
datastore.invoke(new SerializableCallable() {
public Object call() throws Exception {
CacheTransactionManager mgr = getCache().getCacheTransactionManager();
mgr.addListener(new ClientTxListener());
mgr.setWriter(new ClientTxWriter());
Region<CustId, Customer> pr = getGemfireCache().getRegion(CUSTOMER);
pr.getAttributesMutator().addCacheListener(new ServerListener());
pr.getAttributesMutator().setCacheWriter(new ServerWriter());
return null;
}
});
client.invoke(new SerializableCallable() {
public Object call() throws Exception {
CacheTransactionManager mgr = getCache().getCacheTransactionManager();
mgr.addListener(new ClientTxListener());
try {
mgr.setWriter(new ClientTxWriter());
fail("expected exception not thrown");
} catch (IllegalStateException e) {
}
Region<CustId, Customer> pr = getGemfireCache().getRegion(CUSTOMER);
pr.getAttributesMutator().addCacheListener(new ClientListener());
pr.getAttributesMutator().setCacheWriter(new ClientWriter());
return null;
}
});
class doOps extends SerializableCallable {
public doOps(boolean commit) {
this.commit = commit;
}
boolean commit = false;
public Object call() throws Exception {
Region<CustId, Customer> pr = getGemfireCache().getRegion(CUSTOMER);
CacheTransactionManager mgr = getCache().getCacheTransactionManager();
pr.put(new CustId(0), new Customer("name0", "address0"));
pr.put(new CustId(1), new Customer("name1", "address1"));
mgr.begin();
pr.invalidate(new CustId(0));
pr.destroy(new CustId(1));
for (int i = 2; i < 5; i++) {
pr.put(new CustId(i), new Customer("name" + i, "address" + i));
}
if (commit) {
mgr.commit();
} else {
mgr.rollback();
}
return null;
}
}
client.invoke(new doOps(false));
datastore.invoke(new SerializableCallable() {
@SuppressWarnings("synthetic-access")
public Object call() throws Exception {
CacheTransactionManager mgr = getGemfireCache().getCacheTransactionManager();
ClientTxListener l = (ClientTxListener) mgr.getListeners()[0];
assertTrue(l.afterRollbackInvoked);
return null;
}
});
client.invoke(new doOps(true));
datastore.invoke(new SerializableCallable() {
public Object call() throws Exception {
CacheTransactionManager mgr = getGemfireCache().getCacheTransactionManager();
ClientTxListener l = (ClientTxListener) mgr.getListeners()[0];
assertTrue(l.afterCommitInvoked);
ClientTxWriter w = (ClientTxWriter) mgr.getWriter();
assertTrue(w.txWriterCalled);
return null;
}
});
client.invoke(new SerializableCallable() {
public Object call() throws Exception {
CacheTransactionManager mgr = getGemfireCache().getCacheTransactionManager();
ClientTxListener l = (ClientTxListener) mgr.getListeners()[0];
assertFalse(l.afterCommitInvoked);
Region<CustId, Customer> pr = getGemfireCache().getRegion(CUSTOMER);
ClientListener cl = (ClientListener) pr.getAttributes().getCacheListeners()[0];
assertTrue(cl.invoked);
return null;
}
});
}
Aggregations