Search in sources :

Example 16 with PoolFactory

use of org.apache.geode.cache.client.PoolFactory in project geode by apache.

the class ConnectionProxyJUnitTest method testDuplicateSeqIdLesserThanCurrentSeqIdBeingIgnored.

@Test
public void testDuplicateSeqIdLesserThanCurrentSeqIdBeingIgnored() {
    int port3 = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    CacheServer server = null;
    try {
        try {
            server = this.cache.addCacheServer();
            server.setMaximumTimeBetweenPings(10000);
            server.setPort(port3);
            server.start();
        } catch (Exception e) {
            e.printStackTrace();
            fail("Failed to create server");
        }
        try {
            PoolFactory pf = PoolManager.createFactory();
            pf.addServer("localhost", port3);
            pf.setSubscriptionEnabled(true);
            pf.setSubscriptionRedundancy(-1);
            pf.setSubscriptionMessageTrackingTimeout(100000);
            proxy = (PoolImpl) pf.create("clientPool");
            EventID eid1 = new EventID(new byte[0], 1, 5);
            if (proxy.verifyIfDuplicate(eid1)) {
                fail(" eid1 can never be duplicate, it is being created for the first time! ");
            }
            EventID eid2 = new EventID(new byte[0], 1, 2);
            if (!proxy.verifyIfDuplicate(eid2)) {
                fail(" eid2 should be duplicate, seqId is less than highest (5)");
            }
            EventID eid3 = new EventID(new byte[0], 1, 3);
            if (!proxy.verifyIfDuplicate(eid3)) {
                fail(" eid3 should be duplicate, seqId is less than highest (5)");
            }
            assertTrue(!proxy.getThreadIdToSequenceIdMap().isEmpty());
            proxy.destroy();
        } catch (Exception ex) {
            ex.printStackTrace();
            fail("Failed to initialize client");
        }
    } finally {
        if (server != null) {
            server.stop();
        }
    }
}
Also used : PoolFactory(org.apache.geode.cache.client.PoolFactory) CacheServer(org.apache.geode.cache.server.CacheServer) EventID(org.apache.geode.internal.cache.EventID) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 17 with PoolFactory

use of org.apache.geode.cache.client.PoolFactory in project geode by apache.

the class ConnectionProxyJUnitTest method testTwoClientsHavingDifferentThreadIdMaps.

@Test
public void testTwoClientsHavingDifferentThreadIdMaps() {
    int port3 = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    CacheServer server = null;
    try {
        try {
            server = this.cache.addCacheServer();
            server.setMaximumTimeBetweenPings(10000);
            server.setPort(port3);
            server.start();
        } catch (Exception e) {
            e.printStackTrace();
            fail("Failed to create server");
        }
        try {
            PoolFactory pf = PoolManager.createFactory();
            pf.addServer("localhost", port3);
            pf.setSubscriptionEnabled(true);
            pf.setSubscriptionRedundancy(-1);
            pf.setSubscriptionMessageTrackingTimeout(100000);
            PoolImpl proxy1 = (PoolImpl) pf.create("clientPool1");
            try {
                PoolImpl proxy2 = (PoolImpl) pf.create("clientPool2");
                try {
                    Map map1 = proxy1.getThreadIdToSequenceIdMap();
                    Map map2 = proxy2.getThreadIdToSequenceIdMap();
                    assertTrue(!(map1 == map2));
                } finally {
                    proxy2.destroy();
                }
            } finally {
                proxy1.destroy();
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            fail("Failed to initialize client");
        }
    } finally {
        if (server != null) {
            server.stop();
        }
    }
}
Also used : PoolFactory(org.apache.geode.cache.client.PoolFactory) CacheServer(org.apache.geode.cache.server.CacheServer) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) Map(java.util.Map) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 18 with PoolFactory

use of org.apache.geode.cache.client.PoolFactory in project geode by apache.

the class InterestListFailoverDUnitTest method getClientPool.

private Pool getClientPool(String host, int redundancyLevel) {
    PoolFactory pf = PoolManager.createFactory();
    pf.addServer(host, PORT1).addServer(host, PORT2).setSubscriptionEnabled(true).setReadTimeout(500).setSocketBufferSize(32768).setMinConnections(4).setSubscriptionRedundancy(redundancyLevel);
    return ((PoolFactoryImpl) pf).getPoolAttributes();
}
Also used : PoolFactory(org.apache.geode.cache.client.PoolFactory) PoolFactoryImpl(org.apache.geode.internal.cache.PoolFactoryImpl)

Example 19 with PoolFactory

use of org.apache.geode.cache.client.PoolFactory in project geode by apache.

the class InterestListDUnitTest method createClientCache.

private static DistributedMember createClientCache(String host, int port, int port2) throws Exception {
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, "");
    props.setProperty(DELTA_PROPAGATION, "false");
    new InterestListDUnitTest().createCache(props);
    PoolFactory pfactory = PoolManager.createFactory().addServer(host, port).setThreadLocalConnections(true).setMinConnections(3).setSubscriptionEnabled(true).setSubscriptionRedundancy(-1).setReadTimeout(10000).setSocketBufferSize(32768);
    // .setRetryAttempts(5)
    if (port2 > 0) {
        pfactory.addServer(host, port2);
    }
    Pool p = pfactory.create("InterestListDUnitTestPool");
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_ACK);
    factory.setPoolName(p.getName());
    RegionAttributes attrs = factory.create();
    cache.createRegion(REGION_NAME, attrs);
    return cache.getDistributedSystem().getDistributedMember();
}
Also used : PoolFactory(org.apache.geode.cache.client.PoolFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) Pool(org.apache.geode.cache.client.Pool) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties)

Example 20 with PoolFactory

use of org.apache.geode.cache.client.PoolFactory in project geode by apache.

the class DurableClientQueueSizeDUnitTest method createClientCache.

@SuppressWarnings("deprecation")
public static void createClientCache(Host host, Integer[] ports, String timeoutSeconds, Boolean durable, Boolean multiPool, CacheListener cacheListener) throws Exception {
    if (multiPool) {
        System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "SPECIAL_DURABLE", "true");
    }
    Properties props = new Properties();
    if (durable) {
        props.setProperty(DURABLE_CLIENT_ID, MY_DURABLE_CLIENT);
        props.setProperty(DURABLE_CLIENT_TIMEOUT, timeoutSeconds);
    }
    DistributedSystem ds = new DurableClientQueueSizeDUnitTest().getSystem(props);
    ds.disconnect();
    ClientCacheFactory ccf = new ClientCacheFactory(props);
    ccf.setPoolSubscriptionEnabled(true);
    ccf.setPoolSubscriptionAckInterval(50);
    ccf.setPoolSubscriptionRedundancy(1);
    ccf.setPoolMaxConnections(1);
    for (int port : ports) {
        ccf.addPoolServer(host.getHostName(), port);
    }
    cache = (GemFireCacheImpl) ccf.create();
    ClientRegionFactory<String, String> crf = cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY);
    if (cacheListener != null) {
        crf.addCacheListener(cacheListener);
    }
    crf.setPoolName(cache.getDefaultPool().getName());
    crf.create(REGION_NAME);
    if (multiPool) {
        String poolName = POOL_NAME;
        PoolFactory pf = PoolManager.createFactory();
        for (int port : ports) {
            pf.addServer(host.getHostName(), port);
        }
        pf.setSubscriptionEnabled(true);
        pf.create(poolName);
        crf.setPoolName(poolName);
        crf.create(NEW_REGION);
    }
}
Also used : PoolFactory(org.apache.geode.cache.client.PoolFactory) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) DistributedSystem(org.apache.geode.distributed.DistributedSystem) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory)

Aggregations

PoolFactory (org.apache.geode.cache.client.PoolFactory)66 Test (org.junit.Test)34 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)21 CacheServer (org.apache.geode.cache.server.CacheServer)16 Properties (java.util.Properties)15 AttributesFactory (org.apache.geode.cache.AttributesFactory)14 Host (org.apache.geode.test.dunit.Host)13 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)12 ClientSubscriptionTest (org.apache.geode.test.junit.categories.ClientSubscriptionTest)12 Cache (org.apache.geode.cache.Cache)11 Pool (org.apache.geode.cache.client.Pool)11 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)11 PoolFactoryImpl (org.apache.geode.internal.cache.PoolFactoryImpl)10 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)10 VM (org.apache.geode.test.dunit.VM)9 Region (org.apache.geode.cache.Region)8 EventID (org.apache.geode.internal.cache.EventID)8 IOException (java.io.IOException)7 ClientCache (org.apache.geode.cache.client.ClientCache)7 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)7