use of org.apache.geode.cache.client.internal.Connection in project geode by apache.
the class PooledConnection method emergencyClose.
public void emergencyClose() {
Connection con = this.connection;
if (con != null) {
this.connection.emergencyClose();
}
this.connection = null;
}
use of org.apache.geode.cache.client.internal.Connection in project geode by apache.
the class CacheServerMaxConnectionsJUnitTest method testMaxCnxLimit.
/**
* This test performs the following:<br>
* 1)create server<br>
* 2)initialize proxy object and create region for client<br>
* 3)perform a PUT on client by acquiring Connection through proxy<br>
* 4)stop server monitor threads in client to ensure that server treats this as dead client <br>
* 5)wait for some time to allow server to clean up the dead client artifacts<br>
* 6)again perform a PUT on client through same Connection and verify after the put that the
* Connection object used was new one.
*/
@Test
public void testMaxCnxLimit() throws Exception {
PORT = createServer();
createProxyAndRegionForClient();
StatisticsType st = this.system.findType("CacheServerStats");
final Statistics s = this.system.findStatisticsByType(st)[0];
assertEquals(0, s.getInt("currentClients"));
assertEquals(0, s.getInt("currentClientConnections"));
Connection[] cnxs = new Connection[MAX_CNXS];
for (int i = 0; i < MAX_CNXS; i++) {
cnxs[i] = proxy.acquireConnection();
this.system.getLogWriter().info("acquired connection[" + i + "]=" + cnxs[i]);
}
WaitCriterion ev = new WaitCriterion() {
public boolean done() {
return s.getInt("currentClientConnections") == MAX_CNXS;
}
public String description() {
return null;
}
};
Wait.waitForCriterion(ev, 1000, 200, true);
assertEquals(MAX_CNXS, s.getInt("currentClientConnections"));
assertEquals(1, s.getInt("currentClients"));
this.system.getLogWriter().info("<ExpectedException action=add>" + "exceeded max-connections" + "</ExpectedException>");
try {
Connection cnx = proxy.acquireConnection();
if (cnx != null) {
fail("should not have been able to connect more than " + MAX_CNXS + " times but was able to connect " + s.getInt("currentClientConnections") + " times. Last connection=" + cnx);
}
this.system.getLogWriter().info("acquire connection returned null which is ok");
} catch (NoAvailableServersException expected) {
// This is expected but due to race conditions in server handshake
// we may get null back from acquireConnection instead.
this.system.getLogWriter().info("received expected " + expected.getMessage());
} catch (Exception ex) {
fail("expected acquireConnection to throw NoAvailableServersException but instead it threw " + ex);
} finally {
this.system.getLogWriter().info("<ExpectedException action=remove>" + "exceeded max-connections" + "</ExpectedException>");
}
// now lets see what happens we we close our connections
for (int i = 0; i < MAX_CNXS; i++) {
cnxs[i].close(false);
}
ev = new WaitCriterion() {
public boolean done() {
return s.getInt("currentClients") == 0;
}
public String description() {
return null;
}
};
Wait.waitForCriterion(ev, 3 * 1000, 200, true);
this.system.getLogWriter().info("currentClients=" + s.getInt("currentClients") + " currentClientConnections=" + s.getInt("currentClientConnections"));
assertEquals(0, s.getInt("currentClientConnections"));
assertEquals(0, s.getInt("currentClients"));
}
use of org.apache.geode.cache.client.internal.Connection in project geode by apache.
the class ClearPropagationDUnitTest method acquireConnectionsAndClear.
public static void acquireConnectionsAndClear(String host) {
try {
Region r1 = cache.getRegion(Region.SEPARATOR + REGION_NAME);
assertNotNull(r1);
String poolName = r1.getAttributes().getPoolName();
assertNotNull(poolName);
PoolImpl pool = (PoolImpl) PoolManager.find(poolName);
assertNotNull(pool);
Connection conn1 = pool.acquireConnection(new ServerLocation(host, PORT2));
assertNotNull(conn1);
assertEquals(PORT2, conn1.getServer().getPort());
ServerRegionProxy srp = new ServerRegionProxy(Region.SEPARATOR + REGION_NAME, pool);
srp.clearOnForTestsOnly(conn1, new EventID(new byte[] { 1 }, 1, 1), null);
} catch (Exception ex) {
ex.printStackTrace();
fail("while setting acquireConnections " + ex);
}
}
use of org.apache.geode.cache.client.internal.Connection in project geode by apache.
the class Bug36269DUnitTest method acquireConnectionsAndDestroyRegion.
public static void acquireConnectionsAndDestroyRegion(String host) {
try {
Connection desCon = pool.acquireConnection(new ServerLocation(host, PORT2));
ServerRegionProxy srp = new ServerRegionProxy(Region.SEPARATOR + REGION_NAME, pool);
srp.destroyRegionOnForTestsOnly(desCon, new EventID(new byte[] { 1 }, 1, 1), null);
} catch (Exception ex) {
Assert.fail("while setting acquireConnections", ex);
}
}
use of org.apache.geode.cache.client.internal.Connection 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