Search in sources :

Example 21 with PoolImpl

use of org.apache.geode.cache.client.internal.PoolImpl 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 22 with PoolImpl

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

the class InterestListEndpointDUnitTest method testInterestListEndpointAfterFailover.

@Test
public void testInterestListEndpointAfterFailover() throws Exception {
    final long maxWaitTime = 20000;
    client1.invoke(() -> createEntriesK1andK2());
    server2.invoke(() -> createEntriesK1andK2());
    server1.invoke(() -> createEntriesK1andK2());
    client1.invoke(() -> registerKey1());
    boolean firstIsPrimary = isVm0Primary();
    VM primary = firstIsPrimary ? server1 : server2;
    primary.invoke(() -> stopILEndpointServer());
    Wait.pause(5000);
    // Since the loadbalancing policy is roundrobin & there are two servers so
    // do two dumb puts, which will ensure that fail over happens from the
    // interest list end point in case Live ServerMonitor is not working
    client1.invoke(new CacheSerializableRunnable("Ensure that the failover from ILEP occurs") {

        public void run2() throws CacheException {
            Region r = cache.getRegion("/" + REGION_NAME);
            String poolName = r.getAttributes().getPoolName();
            assertNotNull(poolName);
            final PoolImpl pool = (PoolImpl) PoolManager.find(poolName);
            assertNotNull(pool);
            pool.acquireConnection();
            try {
                // Used in the case where we don't have a LiveServerMonitorThread
                r.put("ping", "pong1");
            } catch (CacheWriterException itsOK) {
            }
            try {
                // Used in the case where we don't have a LiveServerMonitorThread
                r.put("ping", "pong2");
            } catch (CacheWriterException itsOK) {
            }
            WaitCriterion ev = new WaitCriterion() {

                public boolean done() {
                    return pool.getConnectedServerCount() != 2;
                }

                public String description() {
                    return null;
                }
            };
            Wait.waitForCriterion(ev, maxWaitTime, 200, true);
        }
    });
    // put on stopped server
    primary.invoke(() -> put());
    client1.invoke(() -> verifyPut());
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) CacheWriterException(org.apache.geode.cache.CacheWriterException) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 23 with PoolImpl

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

the class InterestListFailoverDUnitTest method registerInterestList.

public static Integer registerInterestList() {
    try {
        Region r = CacheServerTestUtil.getCache().getRegion("/" + REGION_NAME);
        assertNotNull(r);
        r.registerInterest("key-1");
        r.registerInterest("key-2");
        r.registerInterest("key-3");
        r.registerInterest("key-4");
        r.registerInterest("key-5");
        // now return the port of the primary.
        PoolImpl p = (PoolImpl) PoolManager.find(r.getAttributes().getPoolName());
        return new Integer(p.getPrimaryPort());
    } catch (Exception ex) {
        Assert.fail("failed while registering keys k1 to k5", ex);
        return null;
    }
}
Also used : Region(org.apache.geode.cache.Region) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl)

Example 24 with PoolImpl

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

the class InterestListRecoveryDUnitTest method createClientCache.

public static void createClientCache(String host, Integer port1, Integer port2) throws Exception {
    InterestListRecoveryDUnitTest test = new InterestListRecoveryDUnitTest();
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, "");
    cache = test.createCache(props);
    PoolImpl p = (PoolImpl) PoolManager.createFactory().addServer(host, port1.intValue()).addServer(host, port2.intValue()).setSubscriptionEnabled(true).setSubscriptionRedundancy(-1).setReadTimeout(250).setThreadLocalConnections(true).setSocketBufferSize(32768).setMinConnections(4).create("InterestListRecoveryDUnitTestPool");
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_ACK);
    factory.setPoolName(p.getName());
    RegionAttributes attrs = factory.create();
    cache.createRegion(REGION_NAME, attrs);
    pool = p;
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl)

Example 25 with PoolImpl

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

the class Bug39079DUnitTest method createClientCache.

private void createClientCache(String host, Integer port1) {
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, "");
    createCache(props);
    PoolImpl pool = (PoolImpl) PoolManager.createFactory().addServer(host, port1.intValue()).setSubscriptionEnabled(true).setSubscriptionRedundancy(0).setThreadLocalConnections(true).setMinConnections(0).setReadTimeout(20000).setRetryAttempts(1).create(getClass().getSimpleName());
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_ACK);
    factory.setPoolName(pool.getName());
    RegionAttributes attrs = factory.create();
    Region region = getCache().createRegion(REGION_NAME_testBridgeServerStoppingInSynchPersistOnlyForIOExceptionCase, attrs);
    region.registerInterest("ALL_KEYS");
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) Region(org.apache.geode.cache.Region) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl)

Aggregations

PoolImpl (org.apache.geode.cache.client.internal.PoolImpl)91 Properties (java.util.Properties)43 AttributesFactory (org.apache.geode.cache.AttributesFactory)40 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)39 Region (org.apache.geode.cache.Region)30 RegionAttributes (org.apache.geode.cache.RegionAttributes)29 Test (org.junit.Test)17 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)16 IOException (java.io.IOException)14 Pool (org.apache.geode.cache.client.Pool)14 VM (org.apache.geode.test.dunit.VM)14 Host (org.apache.geode.test.dunit.Host)13 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)12 LocalRegion (org.apache.geode.internal.cache.LocalRegion)11 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)11 CacheException (org.apache.geode.cache.CacheException)10 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)9 ClientSubscriptionTest (org.apache.geode.test.junit.categories.ClientSubscriptionTest)9 NoAvailableServersException (org.apache.geode.cache.client.NoAvailableServersException)8 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)8