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);
}
Aggregations