Search in sources :

Example 16 with Connection

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

the class ConnectionProxyJUnitTest method testListenerOnServerSitForever.

/**
   * This test verifies the behaviour of client request when the listener on the server sits
   * forever. This is done in following steps:<br>
   * 1)create server<br>
   * 2)initialize proxy object and create region for client having a CacheListener and make
   * afterCreate in the listener to wait infinitely<br>
   * 3)perform a PUT on client by acquiring Connection through proxy<br>
   * 4)Verify that exception occurs due to infinite wait in the listener<br>
   * 5)Verify that above exception occurs sometime after the readTimeout configured for the client
   * <br>
   *
   */
@Ignore
@Test
public void testListenerOnServerSitForever() throws Exception {
    int port3 = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    Region testRegion = null;
    CacheServer server = this.cache.addCacheServer();
    server.setMaximumTimeBetweenPings(10000);
    server.setPort(port3);
    server.start();
    try {
        PoolFactory pf = PoolManager.createFactory();
        pf.addServer("localhost", port3);
        pf.setSubscriptionEnabled(false);
        pf.setSubscriptionRedundancy(-1);
        pf.setReadTimeout(2000);
        pf.setThreadLocalConnections(true);
        pf.setSocketBufferSize(32768);
        pf.setRetryAttempts(1);
        pf.setPingInterval(10000);
        proxy = (PoolImpl) pf.create("clientPool");
        AttributesFactory factory = new AttributesFactory();
        factory.setScope(Scope.DISTRIBUTED_ACK);
        factory.setCacheListener(new CacheListenerAdapter() {

            public void afterCreate(EntryEvent event) {
                synchronized (ConnectionProxyJUnitTest.this) {
                    try {
                        ConnectionProxyJUnitTest.this.wait();
                    } catch (InterruptedException e) {
                        fail("interrupted");
                    }
                }
            }
        });
        RegionAttributes attrs = factory.create();
        testRegion = cache.createRegion("testregion", attrs);
    } catch (Exception ex) {
        ex.printStackTrace();
        fail("Failed to initialize client");
    }
    Connection conn = (proxy).acquireConnection();
    long t1 = 0;
    try {
        t1 = System.currentTimeMillis();
        EntryEventImpl event = new EntryEventImpl((Object) null);
        try {
            event.setEventId(new EventID(new byte[] { 1 }, 1, 1));
            PutOp.execute(conn, proxy, testRegion.getFullPath(), "key1", "val1", event, null, false);
        } finally {
            event.release();
        }
        fail("Test failed as exception was expected");
    } catch (Exception e) {
        long t2 = System.currentTimeMillis();
        long net = (t2 - t1);
        assertTrue(net / 1000 < 5);
    }
    synchronized (ConnectionProxyJUnitTest.this) {
        ConnectionProxyJUnitTest.this.notify();
    }
}
Also used : EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) Connection(org.apache.geode.cache.client.internal.Connection) PoolFactory(org.apache.geode.cache.client.PoolFactory) CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) CacheServer(org.apache.geode.cache.server.CacheServer) EventID(org.apache.geode.internal.cache.EventID) Ignore(org.junit.Ignore) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 17 with Connection

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

the class EventIdOptimizationDUnitTest method generateEventsByPutOperation.

/**
   * Generates events having specific values of threadId and sequenceId, via put operation through
   * connection object
   * 
   * @throws Exception - thrown if any problem occurs in put operation
   */
public static void generateEventsByPutOperation() 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++) {
        srp.putOnForTestsOnly(connection, "KEY-" + i, "VAL-" + i, eventIds[i], null);
    }
    srp.putOnForTestsOnly(connection, LAST_KEY, "LAST_VAL", eventIdForLastKey, null);
}
Also used : ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) Connection(org.apache.geode.cache.client.internal.Connection)

Example 18 with Connection

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

the class EventIdOptimizationDUnitTest method generateEventsByClearRegionOperation.

/**
   * Generates events having specific values of threadId and sequenceId, via clearRegionOperation
   * through connection object
   * 
   * @throws Exception - thrown if any problem occurs in clearRegionOperation
   */
public static void generateEventsByClearRegionOperation() 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++) {
        srp.clearOnForTestsOnly(connection, eventIds[i], null);
    }
    srp.clearOnForTestsOnly(connection, eventIdForLastKey, null);
}
Also used : ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) Connection(org.apache.geode.cache.client.internal.Connection)

Example 19 with Connection

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

the class EventIdOptimizationDUnitTest method generateEventsByDestroyRegionOperation.

/**
   * Generates events having specific values of threadId and sequenceId, via destroyRegionOperation
   * through connection object
   * 
   * @throws Exception - thrown if any problem occurs in destroyRegionOperation
   */
public static void generateEventsByDestroyRegionOperation() throws Exception {
    Connection connection = pool.acquireConnection();
    String regionName = Region.SEPARATOR + REGION_NAME;
    for (int i = 0; i < 1; i++) {
        ServerRegionProxy srp = new ServerRegionProxy(regionName + i, pool);
        srp.destroyRegionOnForTestsOnly(connection, eventIds[i], null);
    }
    {
        ServerRegionProxy srp = new ServerRegionProxy(regionName, pool);
        srp.destroyRegionOnForTestsOnly(connection, eventIdForLastKey, null);
    }
}
Also used : ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) Connection(org.apache.geode.cache.client.internal.Connection)

Example 20 with Connection

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

the class RemoteParallelGatewaySenderEventProcessor method shouldSendVersionEvents.

/**
   * Returns if corresponding receiver WAN site of this GatewaySender has GemfireVersion > 7.0.1
   * 
   * @param disp
   * @return true if remote site Gemfire Version is >= 7.0.1
   */
private boolean shouldSendVersionEvents(GatewaySenderEventDispatcher disp) throws GatewaySenderException {
    try {
        GatewaySenderEventRemoteDispatcher remoteDispatcher = (GatewaySenderEventRemoteDispatcher) disp;
        // This will create a new connection if no batch has been sent till
        // now.
        Connection conn = remoteDispatcher.getConnection(false);
        if (conn != null) {
            short remoteSiteVersion = conn.getWanSiteVersion();
            if (Version.GFE_701.compareTo(remoteSiteVersion) <= 0) {
                return true;
            }
        }
    } catch (GatewaySenderException e) {
        Throwable cause = e.getCause();
        if (cause instanceof IOException || e instanceof GatewaySenderConfigurationException || cause instanceof ConnectionDestroyedException) {
            try {
                int sleepInterval = GatewaySender.CONNECTION_RETRY_INTERVAL;
                if (logger.isDebugEnabled()) {
                    logger.debug("Sleeping for {} milliseconds", sleepInterval);
                }
                Thread.sleep(sleepInterval);
            } catch (InterruptedException ie) {
                // log the exception
                if (logger.isDebugEnabled()) {
                    logger.debug(ie.getMessage(), ie);
                }
            }
        }
        throw e;
    }
    return false;
}
Also used : GatewaySenderEventRemoteDispatcher(org.apache.geode.internal.cache.wan.GatewaySenderEventRemoteDispatcher) GatewaySenderConfigurationException(org.apache.geode.internal.cache.wan.GatewaySenderConfigurationException) Connection(org.apache.geode.cache.client.internal.Connection) GatewaySenderException(org.apache.geode.internal.cache.wan.GatewaySenderException) IOException(java.io.IOException) ConnectionDestroyedException(org.apache.geode.cache.client.internal.pooling.ConnectionDestroyedException)

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