Skip to content

Commit

Permalink
GEODE-4077: Replaced WaitCriterion and Thread.sleep() with Awaitility…
Browse files Browse the repository at this point in the history
….await().
  • Loading branch information
ladyVader committed Dec 21, 2017
1 parent 42974bf commit 20f0d99
Showing 1 changed file with 34 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,29 @@
*/
package org.apache.geode.internal.cache.ha;

import static org.apache.geode.distributed.ConfigurationProperties.*;
import static org.junit.Assert.*;
import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
import static org.apache.geode.distributed.ConfigurationProperties.REMOVE_UNRESPONSIVE_CLIENT;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.net.SocketException;
import java.util.Properties;
import java.util.concurrent.TimeUnit;

import org.awaitility.Awaitility;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import org.apache.geode.LogWriter;
import org.apache.geode.cache.*;
import org.apache.geode.cache.AttributesFactory;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.CacheFactory;
import org.apache.geode.cache.DataPolicy;
import org.apache.geode.cache.EntryEvent;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.RegionAttributes;
import org.apache.geode.cache.Scope;
import org.apache.geode.cache.client.PoolManager;
import org.apache.geode.cache.client.internal.PoolImpl;
import org.apache.geode.cache.server.CacheServer;
Expand All @@ -39,8 +51,6 @@
import org.apache.geode.test.dunit.IgnoredException;
import org.apache.geode.test.dunit.NetworkUtils;
import org.apache.geode.test.dunit.VM;
import org.apache.geode.test.dunit.Wait;
import org.apache.geode.test.dunit.WaitCriterion;
import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
import org.apache.geode.test.junit.categories.ClientSubscriptionTest;
import org.apache.geode.test.junit.categories.DistributedTest;
Expand Down Expand Up @@ -219,23 +229,19 @@ public static void createEntries(Long num) {
}

public static void checkRedundancyLevel(final Integer redundantServers) {
WaitCriterion wc = new WaitCriterion() {
public boolean done() {
return pool.getRedundantNames().size() == redundantServers.intValue();
}

public String description() {
return "Expected redundant count (" + pool.getRedundantNames().size() + ") to become "
+ redundantServers.intValue();
}
};
Wait.waitForCriterion(wc, 200 * 1000, 1000, true);
Awaitility.await().atMost(20, TimeUnit.SECONDS).until(() -> {
// check for slow client queue is removed or not.
assertTrue(
"Expected redundant count (" + pool.getRedundantNames().size() + ") to become "
+ redundantServers.intValue(),
pool.getRedundantNames().size() == redundantServers.intValue());
});
}

// Test slow client
@Test
public void testSlowClient() throws Exception {
setBridgeObeserverForAfterQueueDestroyMessage();
setBridgeObserverForAfterQueueDestroyMessage();
Host host = Host.getHost(0);
clientVM.invoke(
() -> HASlowReceiverDUnitTest.createClientCache(NetworkUtils.getServerHostName(host),
Expand All @@ -246,18 +252,23 @@ public void testSlowClient() throws Exception {
IgnoredException.addIgnoredException(SocketException.class.getName());
final IgnoredException ex2 =
IgnoredException.addIgnoredException(InterruptedException.class.getName());

putEntries();
Thread.sleep(20000);// wait for put to block and allow server to remove
// client queue

Awaitility.await().atMost(60, TimeUnit.SECONDS).until(() -> {
// check for slow client queue is removed or not.
assertTrue("isUnresponsiveClientRemoved is false, but should be true " + "after 60 seconds",
isUnresponsiveClientRemoved);
});

// verify that we get reconnected
clientVM.invoke(() -> HASlowReceiverDUnitTest.checkRedundancyLevel(new Integer(2)));
// check for slow client queue is removed or not.
assertTrue("isUnresponsiveClientRemoved is false, but should be true " + "after 20 seconds",
isUnresponsiveClientRemoved);

ex1.remove();
ex2.remove();
}

public static void setBridgeObeserverForAfterQueueDestroyMessage() throws Exception {
public static void setBridgeObserverForAfterQueueDestroyMessage() throws Exception {
PoolImpl.AFTER_QUEUE_DESTROY_MESSAGE_FLAG = true;
ClientServerObserverHolder.setInstance(new ClientServerObserverAdapter() {
@Override
Expand Down

0 comments on commit 20f0d99

Please sign in to comment.