use of org.apache.geode.cache.client.internal.PoolImpl in project geode by apache.
the class DurableClientSimpleDUnitTest method verifyDurableCqs.
public static void verifyDurableCqs(final List<String> durableCqNames, final String registeredCqName) {
// Verify the number of durable CQ names is one, and it matches the registered name
assertEquals(1, durableCqNames.size());
String returnedCqName = durableCqNames.get(0);
assertEquals(registeredCqName, returnedCqName);
// Get client's primary server
PoolImpl pool = CacheServerTestUtil.getPool();
ServerLocation primaryServerLocation = pool.getPrimary();
// Verify the primary server was used and no other server was used
Map<ServerLocation, ConnectionStats> statistics = pool.getEndpointManager().getAllStats();
for (Map.Entry<ServerLocation, ConnectionStats> entry : statistics.entrySet()) {
int expectedGetDurableCqInvocations = entry.getKey().equals(primaryServerLocation) ? 1 : 0;
assertEquals(expectedGetDurableCqInvocations, entry.getValue().getGetDurableCqs());
}
}
use of org.apache.geode.cache.client.internal.PoolImpl in project geode by apache.
the class DurableClientSimpleDUnitTest method testReadyForEventsNotCalledImplicitlyWithCacheXML.
/**
* This test method is disabled because it is failing periodically and causing cruise control
* failures See bug #47060 (test seems to be enabled now!)
*/
@Test
public void testReadyForEventsNotCalledImplicitlyWithCacheXML() {
try {
setPeriodicACKObserver(durableClientVM);
final String cqName = "cqTest";
// Start a server
int serverPort = (Integer) this.server1VM.invoke(() -> CacheServerTestUtil.createCacheServerFromXml(DurableClientTestCase.class.getResource("durablecq-server-cache.xml")));
// Start a durable client that is not kept alive on the server when it
// stops normally
final String durableClientId = getName() + "_client";
// create client cache from xml
this.durableClientVM.invoke(() -> CacheServerTestUtil.createCacheClientFromXml(DurableClientTestCase.class.getResource("durablecq-client-cache.xml"), "client", durableClientId, 45, Boolean.FALSE));
// verify that readyForEvents has not yet been called on all the client's pools
this.durableClientVM.invoke(new CacheSerializableRunnable("check readyForEvents not called") {
@Override
public void run2() throws CacheException {
for (Pool p : PoolManager.getAll().values()) {
assertEquals(false, ((PoolImpl) p).getReadyForEventsCalled());
}
}
});
// Send clientReady message
this.durableClientVM.invoke(new CacheSerializableRunnable("Send clientReady") {
@Override
public void run2() throws CacheException {
CacheServerTestUtil.getCache().readyForEvents();
}
});
registerDurableCq(cqName);
// Verify durable client on server1
this.server1VM.invoke(new CacheSerializableRunnable("Verify durable client") {
@Override
public void run2() throws CacheException {
// Find the proxy
checkNumberOfClientProxies(1);
CacheClientProxy proxy = getClientProxy();
assertNotNull(proxy);
// Verify that it is durable
assertTrue(proxy.isDurable());
assertEquals(durableClientId, proxy.getDurableId());
}
});
// Start normal publisher client
this.publisherClientVM.invoke(() -> CacheServerTestUtil.createCacheClient(getClientPool(getServerHostName(publisherClientVM.getHost()), serverPort, false), regionName));
// Publish some entries
final int numberOfEntries = 10;
publishEntries(numberOfEntries);
// Verify the durable client received the updates
this.durableClientVM.invoke(new CacheSerializableRunnable("Verify updates") {
@Override
public void run2() throws CacheException {
// Get the region
Region region = CacheServerTestUtil.getCache().getRegion(regionName);
assertNotNull(region);
// Get the listener and wait for the appropriate number of events
QueryService queryService = CacheServerTestUtil.getPool().getQueryService();
CqQuery cqQuery = queryService.getCq(cqName);
CacheServerTestUtil.ControlCqListener cqlistener = (CacheServerTestUtil.ControlCqListener) cqQuery.getCqAttributes().getCqListener();
cqlistener.waitWhileNotEnoughEvents(30000, numberOfEntries);
assertEquals(numberOfEntries, cqlistener.events.size());
}
});
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
fail("interrupted", e);
}
// Stop the durable client
this.durableClientVM.invoke(() -> CacheServerTestUtil.closeCache(new Boolean(true)));
// Verify the durable client still exists on the server
this.server1VM.invoke(new CacheSerializableRunnable("Verify durable client") {
@Override
public void run2() throws CacheException {
// Find the proxy
CacheClientProxy proxy = getClientProxy();
assertNotNull(proxy);
}
});
// Publish some more entries
publishEntries(numberOfEntries);
this.publisherClientVM.invoke(() -> CacheServerTestUtil.closeCache());
// Re-start the durable client
this.durableClientVM.invoke(() -> CacheServerTestUtil.createCacheClientFromXml(DurableClientTestCase.class.getResource("durablecq-client-cache.xml"), "client", durableClientId, 45, Boolean.FALSE));
// Durable client registers durable cq on server
this.durableClientVM.invoke(new CacheSerializableRunnable("Register cq") {
@Override
public void run2() throws CacheException {
// Get the region
Region region = CacheServerTestUtil.getCache().getRegion(regionName);
assertNotNull(region);
// Create CQ Attributes.
CqAttributesFactory cqAf = new CqAttributesFactory();
// Initialize and set CqListener.
CqListener[] cqListeners = { new CacheServerTestUtil.ControlCqListener() };
cqAf.initCqListeners(cqListeners);
CqAttributes cqa = cqAf.create();
// Create cq's
// Get the query service for the Pool
QueryService queryService = CacheServerTestUtil.getPool().getQueryService();
try {
CqQuery query = queryService.newCq(cqName, "Select * from /" + regionName, cqa, true);
query.execute();
} catch (CqExistsException e) {
fail("Failed due to ", e);
} catch (CqException e) {
fail("Failed due to ", e);
} catch (RegionNotFoundException e) {
fail("Could not find specified region:" + regionName + ":", e);
}
}
});
// Send clientReady message
this.durableClientVM.invoke(new CacheSerializableRunnable("Send clientReady") {
@Override
public void run2() throws CacheException {
CacheServerTestUtil.getCache().readyForEvents();
}
});
// Verify durable client on server
this.server1VM.invoke(new CacheSerializableRunnable("Verify durable client") {
@Override
public void run2() throws CacheException {
// Find the proxy
checkNumberOfClientProxies(1);
CacheClientProxy proxy = getClientProxy();
assertNotNull(proxy);
// Verify that it is durable and its properties are correct
assertTrue(proxy.isDurable());
assertEquals(durableClientId, proxy.getDurableId());
}
});
// Verify the durable client received the updates held for it on the server
this.durableClientVM.invoke(new CacheSerializableRunnable("Verify updates") {
@Override
public void run2() throws CacheException {
// Get the region
Region region = CacheServerTestUtil.getCache().getRegion(regionName);
assertNotNull(region);
QueryService queryService = CacheServerTestUtil.getPool().getQueryService();
CqQuery cqQuery = queryService.getCq(cqName);
CacheServerTestUtil.ControlCqListener cqlistener = (CacheServerTestUtil.ControlCqListener) cqQuery.getCqAttributes().getCqListener();
cqlistener.waitWhileNotEnoughEvents(30000, numberOfEntries);
assertEquals(numberOfEntries, cqlistener.events.size());
}
});
// Stop the durable client
this.durableClientVM.invoke(() -> CacheServerTestUtil.closeCache());
// Stop the server
this.server1VM.invoke(() -> CacheServerTestUtil.closeCache());
} finally {
unsetPeriodicACKObserver(durableClientVM);
}
}
use of org.apache.geode.cache.client.internal.PoolImpl in project geode by apache.
the class DurableClientSimpleDUnitTest method testReadyForEventsNotCalledImplicitlyForRegisterInterestWithCacheXML.
@Test
public void testReadyForEventsNotCalledImplicitlyForRegisterInterestWithCacheXML() {
final String cqName = "cqTest";
regionName = "testReadyForEventsNotCalledImplicitlyWithCacheXML_region";
// Start a server
int serverPort = (Integer) this.server1VM.invoke(() -> CacheServerTestUtil.createCacheServerFromXmlN(DurableClientTestCase.class.getResource("durablecq-server-cache.xml")));
// Start a durable client that is not kept alive on the server when it
// stops normally
final String durableClientId = getName() + "_client";
// create client cache from xml
this.durableClientVM.invoke(() -> CacheServerTestUtil.createCacheClientFromXmlN(DurableClientTestCase.class.getResource("durablecq-client-cache.xml"), "client", durableClientId, 45, Boolean.TRUE));
// verify that readyForEvents has not yet been called on all the client's pools
this.durableClientVM.invoke(new CacheSerializableRunnable("check readyForEvents not called") {
@Override
public void run2() throws CacheException {
for (Pool p : PoolManager.getAll().values()) {
assertEquals(false, ((PoolImpl) p).getReadyForEventsCalled());
}
}
});
// Send clientReady message
this.durableClientVM.invoke(new CacheSerializableRunnable("Send clientReady") {
@Override
public void run2() throws CacheException {
CacheServerTestUtil.getCache().readyForEvents();
}
});
// Durable client registers durable cq on server
this.durableClientVM.invoke(new CacheSerializableRunnable("Register Interest") {
@Override
public void run2() throws CacheException {
// Get the region
Region region = CacheServerTestUtil.getCache().getRegion(regionName);
assertNotNull(region);
// Register interest in all keys
region.registerInterestRegex(".*", InterestResultPolicy.KEYS_VALUES, true);
}
});
// Verify durable client on server1
this.server1VM.invoke(new CacheSerializableRunnable("Verify durable client") {
@Override
public void run2() throws CacheException {
// Find the proxy
checkNumberOfClientProxies(1);
CacheClientProxy proxy = getClientProxy();
assertNotNull(proxy);
// Verify that it is durable
assertTrue(proxy.isDurable());
assertEquals(durableClientId, proxy.getDurableId());
}
});
// Start normal publisher client
this.publisherClientVM.invoke(() -> CacheServerTestUtil.createCacheClient(getClientPool(getServerHostName(publisherClientVM.getHost()), serverPort, false), regionName));
// Publish some entries
final int numberOfEntries = 10;
publishEntries(numberOfEntries);
// Verify the durable client received the updates
this.durableClientVM.invoke(new CacheSerializableRunnable("Verify updates") {
@Override
public void run2() throws CacheException {
// Get the region
Region region = CacheServerTestUtil.getCache().getRegion(regionName);
assertNotNull(region);
// Get the listener and wait for the appropriate number of events
CacheServerTestUtil.ControlListener listener = (CacheServerTestUtil.ControlListener) region.getAttributes().getCacheListeners()[0];
listener.waitWhileNotEnoughEvents(30000, numberOfEntries);
assertEquals(numberOfEntries, listener.events.size());
}
});
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
fail("interrupted", e);
}
// Stop the durable client
this.durableClientVM.invoke(() -> CacheServerTestUtil.closeCache(new Boolean(true)));
// Verify the durable client still exists on the server
this.server1VM.invoke(new CacheSerializableRunnable("Verify durable client") {
@Override
public void run2() throws CacheException {
// Find the proxy
CacheClientProxy proxy = getClientProxy();
assertNotNull(proxy);
}
});
// Publish some more entries
this.publisherClientVM.invoke(new CacheSerializableRunnable("Publish additional updates") {
@Override
public void run2() throws CacheException {
// Get the region
Region region = CacheServerTestUtil.getCache().getRegion(regionName);
assertNotNull(region);
// Publish some entries
for (int i = 0; i < numberOfEntries; i++) {
String keyAndValue = String.valueOf(i);
region.put(keyAndValue, keyAndValue + "lkj");
}
}
});
this.publisherClientVM.invoke(() -> CacheServerTestUtil.closeCache());
// Re-start the durable client
this.durableClientVM.invoke(() -> CacheServerTestUtil.createCacheClientFromXmlN(DurableClientTestCase.class.getResource("durablecq-client-cache.xml"), "client", durableClientId, 45, Boolean.TRUE));
// Durable client registers durable cq on server
this.durableClientVM.invoke(new CacheSerializableRunnable("Register interest") {
@Override
public void run2() throws CacheException {
// Get the region
Region region = CacheServerTestUtil.getCache().getRegion(regionName);
assertNotNull(region);
// Register interest in all keys
region.registerInterestRegex(".*", InterestResultPolicy.KEYS_VALUES, true);
}
});
// Send clientReady message
this.durableClientVM.invoke(new CacheSerializableRunnable("Send clientReady") {
@Override
public void run2() throws CacheException {
CacheServerTestUtil.getCache().readyForEvents();
}
});
// Verify durable client on server
this.server1VM.invoke(new CacheSerializableRunnable("Verify durable client") {
@Override
public void run2() throws CacheException {
// Find the proxy
checkNumberOfClientProxies(1);
CacheClientProxy proxy = getClientProxy();
assertNotNull(proxy);
// Verify that it is durable and its properties are correct
assertTrue(proxy.isDurable());
assertEquals(durableClientId, proxy.getDurableId());
}
});
// Verify the durable client received the updates held for it on the server
this.durableClientVM.invoke(new CacheSerializableRunnable("Verify updates") {
@Override
public void run2() throws CacheException {
// Get the region
Region region = CacheServerTestUtil.getCache().getRegion(regionName);
assertNotNull(region);
// Get the listener and wait for the appropriate number of events
CacheServerTestUtil.ControlListener listener = (CacheServerTestUtil.ControlListener) region.getAttributes().getCacheListeners()[0];
listener.waitWhileNotEnoughEvents(30000, numberOfEntries);
assertEquals(numberOfEntries, listener.events.size());
}
});
// Stop the durable client
this.durableClientVM.invoke(() -> CacheServerTestUtil.closeCache());
// Stop the server
this.server1VM.invoke(() -> CacheServerTestUtil.closeCache());
}
use of org.apache.geode.cache.client.internal.PoolImpl in project geode by apache.
the class DeltaToRegionRelationCQRegistrationDUnitTest method createClientCache2.
/*
* create client cache and return's primary server location object (primary)
*/
public static Integer createClientCache2(String host1, String host2, Integer port1, Integer port2) throws Exception {
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
new DeltaToRegionRelationCQRegistrationDUnitTest().createCache(props);
PoolImpl p = (PoolImpl) PoolManager.createFactory().addServer(host1, port1.intValue()).addServer(host2, port2.intValue()).setThreadLocalConnections(true).setMinConnections(3).setSubscriptionEnabled(true).setSubscriptionRedundancy(0).setReadTimeout(10000).setSocketBufferSize(32768).create("DeltaToRegionRelationCQRegistrationTestPool");
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setDataPolicy(DataPolicy.EMPTY);
factory.setPoolName(p.getName());
// region with empty data policy
RegionAttributes attrs = factory.create();
cache.createRegion(REGION_NAME1, attrs);
factory.setDataPolicy(DataPolicy.NORMAL);
attrs = factory.create();
// region with non empty data policy
cache.createRegion(REGION_NAME2, attrs);
return new Integer(p.getPrimaryPort());
}
use of org.apache.geode.cache.client.internal.PoolImpl in project geode by apache.
the class VerifyUpdatesFromNonInterestEndPointDUnitTest method acquireConnectionsAndPut.
public static void acquireConnectionsAndPut(Integer port) {
try {
Region r1 = cache.getRegion(Region.SEPARATOR + REGION_NAME);
String poolName = r1.getAttributes().getPoolName();
assertNotNull(poolName);
PoolImpl pool = (PoolImpl) PoolManager.find(poolName);
assertNotNull(pool);
Connection conn1 = pool.acquireConnection();
Connection conn2 = pool.acquireConnection();
ServerRegionProxy srp = new ServerRegionProxy(Region.SEPARATOR + REGION_NAME, pool);
// put on a connection which is is not interest list ep
if (conn1.getServer().getPort() == port.intValue()) {
srp.putOnForTestsOnly(conn1, "key-1", "server-value1", new EventID(new byte[] { 1 }, 1, 1), null);
srp.putOnForTestsOnly(conn1, "key-2", "server-value2", new EventID(new byte[] { 1 }, 1, 2), null);
} else if (conn2.getServer().getPort() == port.intValue()) {
srp.putOnForTestsOnly(conn2, "key-1", "server-value1", new EventID(new byte[] { 1 }, 1, 1), null);
srp.putOnForTestsOnly(conn2, "key-2", "server-value2", new EventID(new byte[] { 1 }, 1, 2), null);
}
} catch (Exception ex) {
fail("while setting acquireConnections " + ex);
}
}
Aggregations