use of org.apache.geode.internal.cache.execute.data.CustId 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.CustId 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.CustId 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.CustId 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.internal.cache.execute.data.CustId in project geode by apache.
the class SingleHopStatsDUnitTest method createdColocatedPRData.
private void createdColocatedPRData(GemFireCacheImpl cache) {
Region customerRegion = cache.getRegion(CUSTOMER_REGION_NAME);
Region orderRegion = cache.getRegion(ORDER_REGION_NAME);
Region shipmentRegion = cache.getRegion(SHIPMENT_REGION_NAME);
for (int i = 0; i <= 20; i++) {
CustId custid = new CustId(i);
Customer customer = new Customer("name" + i, "Address" + i);
customerRegion.put(custid, customer);
for (int j = 1; j <= 10; j++) {
int oid = (i * 10) + j;
OrderId orderId = new OrderId(oid, custid);
Order order = new Order(ORDER_REGION_NAME + oid);
orderRegion.put(orderId, order);
for (int k = 1; k <= 10; k++) {
int sid = (oid * 10) + k;
ShipmentId shipmentId = new ShipmentId(sid, orderId);
Shipment shipment = new Shipment("Shipment" + sid);
shipmentRegion.put(shipmentId, shipment);
}
}
}
ClientMetadataService cms = cache.getClientMetadataService();
Map<String, ClientPartitionAdvisor> regionMetaData = cms.getClientPRMetadata_TEST_ONLY();
assertEquals(3, regionMetaData.size());
assertTrue(regionMetaData.containsKey(customerRegion.getFullPath()));
regionMetaData.get(customerRegion.getFullPath());
metaDataRefreshCount_Customer = ((LocalRegion) customerRegion).getCachePerfStats().getMetaDataRefreshCount();
// hops are not predictable
assertTrue(metaDataRefreshCount_Customer != 0);
regionMetaData.get(orderRegion.getFullPath());
metaDataRefreshCount_Order = ((LocalRegion) orderRegion).getCachePerfStats().getMetaDataRefreshCount();
assertTrue(metaDataRefreshCount_Order == 0);
regionMetaData.get(shipmentRegion.getFullPath());
metaDataRefreshCount_Shipment = ((LocalRegion) shipmentRegion).getCachePerfStats().getMetaDataRefreshCount();
assertTrue(metaDataRefreshCount_Shipment == 0);
}
Aggregations