Search in sources :

Example 66 with PoolFactory

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

the class DeltaPropagationDUnitTest method testBug40165ClientFailsOver.

@Test
public void testBug40165ClientFailsOver() throws Exception {
    PORT1 = ((Integer) VM0.invoke(() -> DeltaPropagationDUnitTest.createServerCache(HARegionQueue.HA_EVICTION_POLICY_MEMORY))).intValue();
    /**
     * 1. Create two cache servers with slow dispatcher 2. Start a durable client with a custom
     * cache listener 3. Do some puts on the server region 4. Let the dispatcher start dispatching
     * 5. Wait till the durable client receives marker from its primary. 6. Kill the primary server,
     * so that the second one becomes primary. 7. Wait till the durable client processes all its
     * events. 8. Verify that expected number of deltas are received by it.
     */
    // Step 0
    prepareDeltas();
    VM0.invoke(() -> DeltaPropagationDUnitTest.prepareDeltas());
    VM1.invoke(() -> DeltaPropagationDUnitTest.prepareDeltas());
    try {
        // Step 1
        VM0.invoke(() -> ConflationDUnitTest.setIsSlowStart("60000"));
        PORT2 = ((Integer) VM1.invoke(() -> DeltaPropagationDUnitTest.createServerCache(HARegionQueue.HA_EVICTION_POLICY_MEMORY))).intValue();
        VM1.invoke(() -> ConflationDUnitTest.setIsSlowStart("60000"));
        // Step 2
        String durableClientId = getName() + "_client";
        PoolFactory pf = PoolManager.createFactory();
        pf.addServer("localhost", PORT1).addServer("localhost", PORT2).setSubscriptionEnabled(true).setSubscriptionAckInterval(1).setSubscriptionRedundancy(2);
        ((PoolFactoryImpl) pf).getPoolAttributes();
        Properties properties = new Properties();
        properties.setProperty(MCAST_PORT, "0");
        properties.setProperty(LOCATORS, "");
        properties.setProperty(DURABLE_CLIENT_ID, durableClientId);
        properties.setProperty(DURABLE_CLIENT_TIMEOUT, String.valueOf(60));
        createDurableCacheClient(((PoolFactoryImpl) pf).getPoolAttributes(), regionName, properties, new Integer(DURABLE_CLIENT_LISTENER), Boolean.FALSE);
        // Step 3
        VM0.invoke(() -> DeltaPropagationDUnitTest.doPuts());
    } finally {
        // Step 4
        VM0.invoke(() -> ConflationDUnitTest.unsetIsSlowStart());
        VM1.invoke(() -> ConflationDUnitTest.unsetIsSlowStart());
    }
    // Step 5
    VM pVM = (((PoolImpl) pool).getPrimaryPort() == PORT1) ? VM0 : VM1;
    while (!markerReceived) {
        Thread.sleep(50);
    }
    // Step 6
    pVM.invoke(() -> DeltaPropagationDUnitTest.closeCache());
    Thread.sleep(5000);
    // Step 7
    waitForLastKey();
    // Step 8
    long fromDeltasOnClient = DeltaTestImpl.getFromDeltaInvokations().longValue();
    assertTrue("Atleast 99 deltas were to be received but received: " + fromDeltasOnClient, fromDeltasOnClient >= 99);
}
Also used : PoolFactory(org.apache.geode.cache.client.PoolFactory) VM(org.apache.geode.test.dunit.VM) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) ConflationDUnitTest(org.apache.geode.internal.cache.tier.sockets.ConflationDUnitTest) Test(org.junit.Test)

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