Search in sources :

Example 76 with PoolImpl

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

the class DeltaPropagationDUnitTest method testS2CDeltaPropagationWithGIIAndFailover.

@Test
public void testS2CDeltaPropagationWithGIIAndFailover() throws Exception {
    prepareDeltas();
    VM0.invoke(() -> DeltaPropagationDUnitTest.prepareDeltas());
    VM1.invoke(() -> DeltaPropagationDUnitTest.prepareDeltas());
    VM2.invoke(() -> DeltaPropagationDUnitTest.prepareDeltas());
    VM0.invoke(() -> DeltaPropagationDUnitTest.closeCache());
    PORT1 = ((Integer) VM0.invoke(() -> DeltaPropagationDUnitTest.createServerCache(HARegionQueue.HA_EVICTION_POLICY_NONE, new Integer(1), new Integer(NO_LISTENER)))).intValue();
    PORT2 = ((Integer) VM1.invoke(() -> DeltaPropagationDUnitTest.createServerCache(HARegionQueue.HA_EVICTION_POLICY_NONE, new Integer(1), new Integer(NO_LISTENER)))).intValue();
    int port3 = ((Integer) VM2.invoke(() -> DeltaPropagationDUnitTest.createServerCache(HARegionQueue.HA_EVICTION_POLICY_NONE, new Integer(1), new Integer(NO_LISTENER)))).intValue();
    // Do puts after slowing the dispatcher.
    try {
        VM0.invoke(() -> ConflationDUnitTest.setIsSlowStart("60000"));
        VM1.invoke(() -> ConflationDUnitTest.setIsSlowStart("60000"));
        VM2.invoke(() -> ConflationDUnitTest.setIsSlowStart("60000"));
        createClientCache(new int[] { PORT1, PORT2, port3 }, "1", DistributionConfig.CLIENT_CONFLATION_PROP_VALUE_DEFAULT, new Integer(CLIENT_LISTENER), null, null);
        Region r = cache.getRegion("/" + regionName);
        assertNotNull(r);
        r.registerInterest("ALL_KEYS");
        VM primary = (((PoolImpl) pool).getPrimaryPort() == PORT1) ? VM0 : ((((PoolImpl) pool).getPrimaryPort() == PORT2) ? VM1 : VM2);
        primary.invoke(() -> DeltaPropagationDUnitTest.createAndUpdateDeltas());
        Thread.sleep(5000);
        primary.invoke(() -> DeltaPropagationDUnitTest.closeCache());
        Thread.sleep(5000);
        primary = (((PoolImpl) pool).getPrimaryPort() == PORT1) ? VM0 : ((((PoolImpl) pool).getPrimaryPort() == PORT2) ? VM1 : VM2);
        VM0.invoke(() -> ConflationDUnitTest.unsetIsSlowStart());
        VM1.invoke(() -> ConflationDUnitTest.unsetIsSlowStart());
        VM2.invoke(() -> ConflationDUnitTest.unsetIsSlowStart());
        primary.invoke(() -> DeltaPropagationDUnitTest.closeCache());
        Thread.sleep(5000);
        primary = (((PoolImpl) pool).getPrimaryPort() == PORT1) ? VM0 : ((((PoolImpl) pool).getPrimaryPort() == PORT2) ? VM1 : VM2);
        org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("waiting for client to receive last_key");
        waitForLastKey();
        long fromDeltasOnClient = DeltaTestImpl.getFromDeltaInvokations().longValue();
        assertTrue((EVENTS_SIZE - 1) + " deltas were to be received but were " + fromDeltasOnClient, fromDeltasOnClient == (EVENTS_SIZE - 1));
    } finally {
        VM0.invoke(() -> ConflationDUnitTest.unsetIsSlowStart());
        VM1.invoke(() -> ConflationDUnitTest.unsetIsSlowStart());
        VM2.invoke(() -> ConflationDUnitTest.unsetIsSlowStart());
    }
}
Also used : VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) ConflationDUnitTest(org.apache.geode.internal.cache.tier.sockets.ConflationDUnitTest) Test(org.junit.Test)

Example 77 with PoolImpl

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

the class DurableClientSimpleDUnitTest method testReadyForEventsNotCalledImplicitly.

@Test
public void testReadyForEventsNotCalledImplicitly() {
    // Start a server
    int serverPort = ((Integer) this.server1VM.invoke(() -> CacheServerTestUtil.createCacheServer(regionName, new Boolean(true)))).intValue();
    // Start a durable client that is not kept alive on the server when it
    // stops normally
    final String durableClientId = getName() + "_client";
    // make the client use ClientCacheFactory so it will have a default pool
    this.durableClientVM.invoke(() -> CacheServerTestUtil.createClientCache(getClientPool(getServerHostName(durableClientVM.getHost()), serverPort, true), regionName, getClientDistributedSystemProperties(durableClientId)));
    // verify that readyForEvents has not yet been called on the client's default pool
    this.durableClientVM.invoke(new CacheSerializableRunnable("check readyForEvents not called") {

        @Override
        public void run2() throws CacheException {
            for (Pool p : PoolManager.getAll().values()) {
                assertEquals(false, ((PoolImpl) p).getReadyForEventsCalled());
            }
        }
    });
    // Send clientReady message
    this.durableClientVM.invoke(new CacheSerializableRunnable("Send clientReady") {

        @Override
        public void run2() throws CacheException {
            CacheServerTestUtil.getCache().readyForEvents();
        }
    });
    // Verify durable clients on server
    this.server1VM.invoke(new CacheSerializableRunnable("Verify durable client") {

        @Override
        public void run2() throws CacheException {
            // Get the CacheClientNotifier
            CacheClientNotifier notifier = getBridgeServer().getAcceptor().getCacheClientNotifier();
            // Iterate the CacheClientProxies and verify they are correct
            checkNumberOfClientProxies(1);
            boolean durableClient1Found = false, durableClient2Found = false;
            for (Iterator i = notifier.getClientProxies().iterator(); i.hasNext(); ) {
                CacheClientProxy proxy = (CacheClientProxy) i.next();
                assertTrue(proxy.isDurable());
                if (proxy.getDurableId().equals(durableClientId)) {
                    durableClient1Found = true;
                }
                assertEquals(DistributionConfig.DEFAULT_DURABLE_CLIENT_TIMEOUT, proxy.getDurableTimeout());
            }
            assertTrue(durableClient1Found);
        }
    });
    // Stop the durable clients
    this.durableClientVM.invoke(() -> CacheServerTestUtil.closeCache());
    // Stop the server
    this.server1VM.invoke(() -> CacheServerTestUtil.closeCache());
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) Iterator(java.util.Iterator) Pool(org.apache.geode.cache.client.Pool) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 78 with PoolImpl

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

the class HAInterestTestCase method createClientPoolCacheWithSmallRetryInterval.

public static void createClientPoolCacheWithSmallRetryInterval(String testName, String host) throws Exception {
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, "");
    new HAInterestTestCase().createCache(props);
    CacheServerTestUtil.disableShufflingOfEndpoints();
    PoolImpl p;
    try {
        p = (PoolImpl) PoolManager.createFactory().addServer(host, PORT1).addServer(host, PORT2).setSubscriptionEnabled(true).setSubscriptionRedundancy(-1).setReadTimeout(10000).setSocketBufferSize(32768).setMinConnections(6).setPingInterval(200).create("HAInterestBaseTestPool");
    } finally {
        CacheServerTestUtil.enableShufflingOfEndpoints();
    }
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.LOCAL);
    factory.setConcurrencyChecksEnabled(true);
    factory.setPoolName(p.getName());
    cache.createRegion(REGION_NAME, factory.create());
    pool = p;
    conn = pool.acquireConnection();
    assertNotNull(conn);
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl)

Example 79 with PoolImpl

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

the class HAStartupAndFailoverDUnitTest method createClientCacheWithLargeRetryInterval.

public static void createClientCacheWithLargeRetryInterval(String testName, String host) throws Exception {
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, "");
    new HAStartupAndFailoverDUnitTest().createCache(props);
    PoolImpl p = (PoolImpl) PoolManager.createFactory().addServer(host, PORT1.intValue()).addServer(host, PORT2.intValue()).addServer(host, PORT3.intValue()).setSubscriptionEnabled(true).setSubscriptionRedundancy(-1).setReadTimeout(10000).create("HAStartupAndFailoverDUnitTestPool");
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.LOCAL);
    factory.setPoolName(p.getName());
    RegionAttributes attrs = factory.create();
    cache.createRegion(REGION_NAME, attrs);
    pool = p;
    conn = pool.acquireConnection();
    assertNotNull(conn);
}
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 80 with PoolImpl

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

the class HAStartupAndFailoverDUnitTest method createClientCacheWithLargeRetryIntervalAndWithoutCallbackConnection.

public static void createClientCacheWithLargeRetryIntervalAndWithoutCallbackConnection(String testName, String host) throws Exception {
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, "");
    new HAStartupAndFailoverDUnitTest().createCache(props);
    CacheServerTestUtil.disableShufflingOfEndpoints();
    PoolImpl p;
    try {
        p = (PoolImpl) PoolManager.createFactory().addServer(host, PORT1.intValue()).addServer(host, PORT2.intValue()).addServer(host, PORT3.intValue()).setPingInterval(500).create("HAStartupAndFailoverDUnitTestPool");
    } finally {
        CacheServerTestUtil.enableShufflingOfEndpoints();
    }
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.LOCAL);
    factory.setPoolName(p.getName());
    RegionAttributes attrs = factory.create();
    cache.createRegion(REGION_NAME, attrs);
    pool = p;
    // since the default minConnections is 1 we currently have a connection to
    // server1 (vm_0). Now we create a connection to server2 (vm_1)
    conn = pool.acquireConnection(new ServerLocation(Host.getHost(0).getHostName(), PORT2));
    // assert that the conn is to server2 since the tests assume that this is so
    assertNotNull(conn);
    assertTrue(conn.getEndpoint().getLocation().getPort() == PORT2);
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) 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