use of org.apache.geode.internal.cache.CacheServerImpl in project geode by apache.
the class ConnectionPoolDUnitTest method test022ClientRegisterUnregisterRequests.
@Test
public void test022ClientRegisterUnregisterRequests() throws CacheException {
final String regionName1 = this.getName() + "-1";
final Host host = Host.getHost(0);
VM server1 = host.getVM(0);
VM client = host.getVM(2);
SerializableRunnable createServer = new CacheSerializableRunnable("Create Cache Server") {
public void run2() throws CacheException {
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setDataPolicy(DataPolicy.REPLICATE);
factory.setConcurrencyChecksEnabled(false);
createRegion(regionName1, factory.create());
// pause(1000);
try {
startBridgeServer(0);
} catch (Exception ex) {
org.apache.geode.test.dunit.Assert.fail("While starting CacheServer", ex);
}
}
};
// Create server1.
server1.invoke(createServer);
final int port = server1.invoke(() -> ConnectionPoolDUnitTest.getCacheServerPort());
final String host0 = NetworkUtils.getServerHostName(server1.getHost());
SerializableRunnable createPool = new CacheSerializableRunnable("Create region") {
public void run2() throws CacheException {
getLonerSystem();
getCache();
Region region1 = null;
AttributesFactory regionFactory = new AttributesFactory();
regionFactory.setScope(Scope.LOCAL);
regionFactory.setConcurrencyChecksEnabled(false);
ClientServerTestCase.configureConnectionPool(regionFactory, host0, port, -1, true, -1, -1, null);
region1 = createRegion(regionName1, regionFactory.create());
region1.getAttributesMutator().setCacheListener(new CertifiableTestCacheListener(org.apache.geode.test.dunit.LogWriterUtils.getLogWriter()));
}
};
// Create client.
client.invoke(createPool);
// Init values at server.
server1.invoke(new CacheSerializableRunnable("Create values") {
public void run2() throws CacheException {
Region region1 = getRootRegion().getSubregion(regionName1);
for (int i = 0; i < 20; i++) {
region1.put("key-string-" + i, "value-" + i);
}
}
});
// Put some values on the client.
client.invoke(new CacheSerializableRunnable("Put values client") {
public void run2() throws CacheException {
Region region1 = getRootRegion().getSubregion(regionName1);
for (int i = 0; i < 10; i++) {
region1.put("key-string-" + i, "client-value-" + i);
}
}
});
SerializableRunnable closePool = new CacheSerializableRunnable("Close Pool") {
public void run2() throws CacheException {
Region region1 = getRootRegion().getSubregion(regionName1);
String pName = region1.getAttributes().getPoolName();
region1.localDestroyRegion();
PoolImpl p = (PoolImpl) PoolManager.find(pName);
p.destroy();
}
};
client.invoke(closePool);
SerializableRunnable validateClientRegisterUnRegister = new CacheSerializableRunnable("validate Client Register UnRegister") {
public void run2() throws CacheException {
for (Iterator bi = getCache().getCacheServers().iterator(); bi.hasNext(); ) {
CacheServerImpl bsi = (CacheServerImpl) bi.next();
final CacheClientNotifierStats ccnStats = bsi.getAcceptor().getCacheClientNotifier().getStats();
WaitCriterion ev = new WaitCriterion() {
public boolean done() {
return ccnStats.getClientRegisterRequests() == ccnStats.getClientUnRegisterRequests();
}
public String description() {
return null;
}
};
Wait.waitForCriterion(ev, 62 * 1000, 200, true);
assertEquals("HealthMonitor Client Register/UnRegister mismatch.", ccnStats.getClientRegisterRequests(), ccnStats.getClientUnRegisterRequests());
}
}
};
server1.invoke(validateClientRegisterUnRegister);
server1.invoke(new SerializableRunnable("Stop CacheServer") {
public void run() {
stopBridgeServer(getCache());
}
});
}
use of org.apache.geode.internal.cache.CacheServerImpl in project geode by apache.
the class HABugInPutDUnitTest method createServerCache.
public static Integer createServerCache() throws Exception {
new HABugInPutDUnitTest().createCache(new Properties());
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setDataPolicy(DataPolicy.REPLICATE);
RegionAttributes attrs = factory.create();
cache.createRegion(REGION_NAME, attrs);
CacheServerImpl server = (CacheServerImpl) cache.addCacheServer();
assertNotNull(server);
int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
server.setPort(port);
server.setNotifyBySubscription(false);
server.start();
return new Integer(server.getPort());
}
use of org.apache.geode.internal.cache.CacheServerImpl in project geode by apache.
the class CacheClientNotifierDUnitTest method createCacheServerWithCSC.
private int createCacheServerWithCSC(VM vm, final boolean withCSC, final int capacity, final String policy, final String diskStoreName) {
final int serverPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
SerializableRunnable createCacheServer = new SerializableRunnable() {
@Override
public void run() throws Exception {
CacheServerImpl server = (CacheServerImpl) cache.addCacheServer();
server.setPort(serverPort);
if (withCSC) {
if (diskStoreName != null) {
DiskStore ds = cache.findDiskStore(diskStoreName);
if (ds == null) {
ds = cache.createDiskStoreFactory().create(diskStoreName);
}
}
ClientSubscriptionConfig csc = server.getClientSubscriptionConfig();
csc.setCapacity(capacity);
csc.setEvictionPolicy(policy);
csc.setDiskStoreName(diskStoreName);
server.setHostnameForClients("localhost");
// server.setGroups(new String[]{"serv"});
}
try {
server.start();
} catch (IOException e) {
org.apache.geode.test.dunit.Assert.fail("Failed to start server ", e);
}
}
};
vm.invoke(createCacheServer);
return serverPort;
}
use of org.apache.geode.internal.cache.CacheServerImpl in project geode by apache.
the class ClientInterestNotifyDUnitTest method waitForQueuesToDrain.
public static void waitForQueuesToDrain() {
WaitCriterion wc = new WaitCriterion() {
String excuse;
public boolean done() {
// assume a single cache server as configured in this test
CacheServerImpl bridgeServer = (CacheServerImpl) cacheServer.getCacheServers().iterator().next();
if (bridgeServer == null) {
excuse = "No Cache Server";
return false;
}
Iterator proxies = bridgeServer.getAcceptor().getCacheClientNotifier().getClientProxies().iterator();
if (!proxies.hasNext()) {
excuse = "No CacheClientProxy";
return false;
}
while (proxies.hasNext()) {
CacheClientProxy proxy = (CacheClientProxy) proxies.next();
if (proxy == null) {
excuse = "No CacheClientProxy";
return false;
}
// Verify the queue size
int sz = proxy.getQueueSize();
if (0 != sz) {
excuse = "Queue did not drain. Expected size = 0, actual = " + sz + "for " + proxy;
return false;
}
}
return true;
}
public String description() {
return excuse;
}
};
Wait.waitForCriterion(wc, 60 * 1000, 1000, true);
}
use of org.apache.geode.internal.cache.CacheServerImpl in project geode by apache.
the class CacheCreationJUnitTest method defaultCacheServerIsNotCreatedWithDefaultPortWhenNoDeclarativeServerIsConfigured.
@Test
public void defaultCacheServerIsNotCreatedWithDefaultPortWhenNoDeclarativeServerIsConfigured() {
CacheCreation cacheCreation = new CacheCreation();
CacheServerImpl mockServer = mock(CacheServerImpl.class);
when(this.cache.addCacheServer()).thenReturn(mockServer);
List<CacheServer> cacheServers = new ArrayList<>();
when(this.cache.getCacheServers()).thenReturn(cacheServers);
Boolean disableDefaultCacheServer = false;
Integer configuredServerPort = null;
String configuredServerBindAddress = null;
cacheCreation.startCacheServers(cacheCreation.getCacheServers(), this.cache, configuredServerPort, configuredServerBindAddress, disableDefaultCacheServer);
verify(this.cache, never()).addCacheServer();
}
Aggregations