Search in sources :

Example 1 with ServerRegionProxy

use of org.apache.geode.cache.client.internal.ServerRegionProxy in project geode by apache.

the class ClientCQImpl method initConnectionProxy.

/**
   * Initializes the connection using the pool from the client region. Also sets the cqBaseRegion
   * value of this CQ.
   */
private void initConnectionProxy() throws CqException, RegionNotFoundException {
    cqBaseRegion = (LocalRegion) cqService.getCache().getRegion(regionName);
    // is obtained by the Bridge Client/writer/loader on the local region.
    if (cqBaseRegion == null) {
        throw new RegionNotFoundException(LocalizedStrings.CqQueryImpl_REGION_ON_WHICH_QUERY_IS_SPECIFIED_NOT_FOUND_LOCALLY_REGIONNAME_0.toLocalizedString(regionName));
    }
    ServerRegionProxy srp = cqBaseRegion.getServerProxy();
    if (srp != null) {
        if (logger.isTraceEnabled()) {
            logger.trace("Found server region proxy on region. RegionName: {}", regionName);
        }
        this.cqProxy = new ServerCQProxyImpl(srp);
        if (!srp.getPool().getSubscriptionEnabled()) {
            throw new CqException("The 'queueEnabled' flag on Pool installed on Region " + regionName + " is set to false.");
        }
    } else {
        throw new CqException("Unable to get the connection pool. The Region does not have a pool configured.");
    }
}
Also used : RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) CqException(org.apache.geode.cache.query.CqException) ServerCQProxyImpl(org.apache.geode.cache.client.internal.ServerCQProxyImpl)

Example 2 with ServerRegionProxy

use of org.apache.geode.cache.client.internal.ServerRegionProxy 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)

Example 3 with ServerRegionProxy

use of org.apache.geode.cache.client.internal.ServerRegionProxy in project geode by apache.

the class ClientHealthMonitorJUnitTest method testDeadClientRemovalByServer.

/**
   * 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 testDeadClientRemovalByServer() throws Exception {
    PORT = createServer();
    createProxyAndRegionForClient();
    // String connection2String = null;
    StatisticsType st = this.system.findType("CacheServerStats");
    final Statistics s = this.system.findStatisticsByType(st)[0];
    assertEquals(0, s.getInt("currentClients"));
    assertEquals(0, s.getInt("currentClientConnections"));
    this.system.getLogWriter().info("beforeAcquireConnection clients=" + s.getInt("currentClients") + " cnxs=" + s.getInt("currentClientConnections"));
    Connection connection1 = proxy.acquireConnection();
    this.system.getLogWriter().info("afterAcquireConnection clients=" + s.getInt("currentClients") + " cnxs=" + s.getInt("currentClientConnections"));
    this.system.getLogWriter().info("acquired connection " + connection1);
    WaitCriterion ev = new WaitCriterion() {

        public boolean done() {
            return s.getInt("currentClients") != 0;
        }

        public String description() {
            return null;
        }
    };
    Wait.waitForCriterion(ev, 20 * 1000, 200, true);
    assertEquals(1, s.getInt("currentClients"));
    assertEquals(1, s.getInt("currentClientConnections"));
    // String connection1String = connection1.toString();
    ServerRegionProxy srp = new ServerRegionProxy("region1", proxy);
    srp.putOnForTestsOnly(connection1, "key-1", "value-1", new EventID(new byte[] { 1 }, 1, 1), null);
    this.system.getLogWriter().info("did put 1");
    // proxy.testfinalizeServerConnectionMonitor();
    ev = new WaitCriterion() {

        public boolean done() {
            return s.getInt("currentClients") == 0;
        }

        public String description() {
            return null;
        }
    };
    Wait.waitForCriterion(ev, TIME_BETWEEN_PINGS * 5, 200, true);
    {
        this.system.getLogWriter().info("currentClients=" + s.getInt("currentClients") + " currentClientConnections=" + s.getInt("currentClientConnections"));
        assertEquals(0, s.getInt("currentClients"));
        assertEquals(0, s.getInt("currentClientConnections"));
    }
    addExceptions();
    // the connection should now fail since the server timed it out
    try {
        srp.putOnForTestsOnly(connection1, "key-1", "fail", new EventID(new byte[] { 1 }, 1, 2), null);
        fail("expected EOF");
    } catch (ServerConnectivityException expected) {
    }
// The rest of this test no longer works.
// connection1.finalizeConnection();
// proxy.release();
// connection1 = proxy.acquireConnection();
// connection2String = connection1.toString();
// this.system.getLogWriter().info("connection is now " + connection2String);
// if (connection1String.equals(connection2String)) {
// fail("New connection object was not obtained");
// }
// connection1.putObject("region1", "key-1", "value-2", new EventID(new byte[] {1},1,3), null);
// this.system.getLogWriter().info("did put 2");
// assertIndexDetailsEquals(1, s.getInt("currentClients"));
// assertIndexDetailsEquals(1, s.getInt("currentClientConnections"));
// // now lets see what happens when we close our connection
// // note we use a nasty close which just closes the socket instead
// // of sending a nice message to the server telling him we are going away
// ((ConnectionImpl)connection1).finalizeConnection();
// {
// int retry = (TIME_BETWEEN_PINGS*5) / 100;
// while (s.getInt("currentClients") > 0 && retry-- > 0) {
// Thread.sleep(100);
// }
// this.system.getLogWriter().info("currentClients="
// + s.getInt("currentClients")
// + " currentClientConnections="
// + s.getInt("currentClientConnections"));
// assertIndexDetailsEquals(0, s.getInt("currentClients"));
// assertIndexDetailsEquals(0, s.getInt("currentClientConnections"));
// }
}
Also used : ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) StatisticsType(org.apache.geode.StatisticsType) ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) Connection(org.apache.geode.cache.client.internal.Connection) EventID(org.apache.geode.internal.cache.EventID) Statistics(org.apache.geode.Statistics) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 4 with ServerRegionProxy

use of org.apache.geode.cache.client.internal.ServerRegionProxy in project geode by apache.

the class ClearPropagationDUnitTest method acquireConnectionsAndDestroyRegion.

public static void acquireConnectionsAndDestroyRegion(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.destroyRegionOnForTestsOnly(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 5 with ServerRegionProxy

use of org.apache.geode.cache.client.internal.ServerRegionProxy in project geode by apache.

the class EventIdOptimizationDUnitTest method generateEventsByDestroyEntryOperation.

/**
   * Generates events having specific values of threadId and sequenceId, via destroyEntry operation
   * through connection object
   * 
   * @throws Exception - thrown if any problem occurs in destroyEntry operation
   */
public static void generateEventsByDestroyEntryOperation() throws Exception {
    Connection connection = pool.acquireConnection();
    String regionName = Region.SEPARATOR + REGION_NAME;
    ServerRegionProxy srp = new ServerRegionProxy(regionName, pool);
    for (int i = 0; i < eventIds.length; i++) {
        String key = "KEY-" + i;
        srp.putOnForTestsOnly(connection, key, "value-" + i, eventIds[i], null);
        srp.destroyOnForTestsOnly(connection, key, null, Operation.DESTROY, new EventIDHolder(eventIds[i]), null);
    }
    srp.putOnForTestsOnly(connection, LAST_KEY, "lastValue", eventIdForLastKey, null);
    srp.destroyOnForTestsOnly(connection, LAST_KEY, null, Operation.DESTROY, new EventIDHolder(eventIdForLastKey), null);
}
Also used : ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) EventIDHolder(org.apache.geode.internal.cache.EventIDHolder) Connection(org.apache.geode.cache.client.internal.Connection)

Aggregations

ServerRegionProxy (org.apache.geode.cache.client.internal.ServerRegionProxy)34 Connection (org.apache.geode.cache.client.internal.Connection)10 LocalRegion (org.apache.geode.internal.cache.LocalRegion)8 ArrayList (java.util.ArrayList)7 List (java.util.List)7 EventID (org.apache.geode.internal.cache.EventID)7 FunctionException (org.apache.geode.cache.execute.FunctionException)6 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)6 PoolImpl (org.apache.geode.cache.client.internal.PoolImpl)5 StoredObject (org.apache.geode.internal.offheap.StoredObject)5 CacheClosedException (org.apache.geode.cache.CacheClosedException)4 Region (org.apache.geode.cache.Region)4 ServerLocation (org.apache.geode.distributed.internal.ServerLocation)4 CacheException (org.apache.geode.cache.CacheException)3 CacheWriterException (org.apache.geode.cache.CacheWriterException)3 Operation (org.apache.geode.cache.Operation)3 VM (org.apache.geode.test.dunit.VM)3 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)2 EventIDHolder (org.apache.geode.internal.cache.EventIDHolder)2 ConcurrentCacheModificationException (org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException)2