Search in sources :

Example 1 with Connection

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;
}
Also used : Connection(org.apache.geode.cache.client.internal.Connection)

Example 2 with Connection

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"));
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) NoAvailableServersException(org.apache.geode.cache.client.NoAvailableServersException) StatisticsType(org.apache.geode.StatisticsType) Connection(org.apache.geode.cache.client.internal.Connection) Statistics(org.apache.geode.Statistics) NoAvailableServersException(org.apache.geode.cache.client.NoAvailableServersException) IOException(java.io.IOException) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 3 with Connection

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);
    }
}
Also used : ServerLocation(org.apache.geode.distributed.internal.ServerLocation) ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) Connection(org.apache.geode.cache.client.internal.Connection) Region(org.apache.geode.cache.Region) EventID(org.apache.geode.internal.cache.EventID) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) CacheException(org.apache.geode.cache.CacheException)

Example 4 with Connection

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);
    }
}
Also used : ServerLocation(org.apache.geode.distributed.internal.ServerLocation) ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) Connection(org.apache.geode.cache.client.internal.Connection) EventID(org.apache.geode.internal.cache.EventID)

Example 5 with Connection

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);
    }
}
Also used : ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) Connection(org.apache.geode.cache.client.internal.Connection) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) EventID(org.apache.geode.internal.cache.EventID) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl)

Aggregations

Connection (org.apache.geode.cache.client.internal.Connection)21 ServerRegionProxy (org.apache.geode.cache.client.internal.ServerRegionProxy)10 EventID (org.apache.geode.internal.cache.EventID)7 PoolImpl (org.apache.geode.cache.client.internal.PoolImpl)6 Region (org.apache.geode.cache.Region)5 Test (org.junit.Test)5 IOException (java.io.IOException)4 ServerLocation (org.apache.geode.distributed.internal.ServerLocation)4 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)4 CacheException (org.apache.geode.cache.CacheException)3 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)3 GemFireIOException (org.apache.geode.GemFireIOException)2 Statistics (org.apache.geode.Statistics)2 StatisticsType (org.apache.geode.StatisticsType)2 ServerConnectivityException (org.apache.geode.cache.client.ServerConnectivityException)2 ConnectionDestroyedException (org.apache.geode.cache.client.internal.pooling.ConnectionDestroyedException)2 EventIDHolder (org.apache.geode.internal.cache.EventIDHolder)2 LocalRegion (org.apache.geode.internal.cache.LocalRegion)2 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)2 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)2