You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by bs...@apache.org on 2020/04/06 16:29:27 UTC
[geode] branch develop updated: GEODE-7892: Code improvements in
ConnectionProxyJUnitTest
This is an automated email from the ASF dual-hosted git repository.
bschuchardt pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/develop by this push:
new 24203d8 GEODE-7892: Code improvements in ConnectionProxyJUnitTest
new 087e47a Merge pull request #4827 from Nordix/feature/GEODE-7892
24203d8 is described below
commit 24203d86f2cc99c686e042fd87d4359ad9389d56
Author: Alberto Bustamante Reyes <al...@users.noreply.github.com>
AuthorDate: Wed Mar 4 13:14:31 2020 +0100
GEODE-7892: Code improvements in ConnectionProxyJUnitTest
---
.../tier/sockets/ConnectionProxyJUnitTest.java | 97 ++++++----------------
1 file changed, 27 insertions(+), 70 deletions(-)
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/tier/sockets/ConnectionProxyJUnitTest.java b/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/tier/sockets/ConnectionProxyJUnitTest.java
index a731442..ecf87c4 100644
--- a/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/tier/sockets/ConnectionProxyJUnitTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/tier/sockets/ConnectionProxyJUnitTest.java
@@ -28,7 +28,9 @@ import static org.junit.Assert.fail;
import java.util.Map;
import java.util.Properties;
+import java.util.concurrent.TimeUnit;
+import org.awaitility.Duration;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
@@ -56,7 +58,6 @@ import org.apache.geode.internal.cache.EntryEventImpl;
import org.apache.geode.internal.cache.EventID;
import org.apache.geode.internal.cache.ha.ThreadIdentifier;
import org.apache.geode.test.awaitility.GeodeAwaitility;
-import org.apache.geode.test.dunit.WaitCriterion;
import org.apache.geode.test.junit.categories.ClientSubscriptionTest;
/**
@@ -78,6 +79,9 @@ public class ConnectionProxyJUnitTest {
SequenceIdAndExpirationObject seo = null;
+ final Duration timeoutToVerifyExpiry = new Duration(30, TimeUnit.SECONDS);
+ final Duration timeoutToVerifyAckSend = new Duration(30, TimeUnit.SECONDS);
+
@Before
public void setUp() throws Exception {
@@ -239,18 +243,9 @@ public class ConnectionProxyJUnitTest {
e.printStackTrace();
fail("Failed to create server");
}
- WaitCriterion ev = new WaitCriterion() {
- @Override
- public boolean done() {
- return proxy.getConnectedServerCount() == 1;
- }
-
- @Override
- public String description() {
- return null;
- }
- };
- GeodeAwaitility.await().untilAsserted(ev);
+ GeodeAwaitility.await().untilAsserted(() -> {
+ assertEquals(1, proxy.getConnectedServerCount());
+ });
} finally {
if (server != null) {
server.stop();
@@ -297,18 +292,9 @@ public class ConnectionProxyJUnitTest {
e.printStackTrace();
fail("Failed to create server");
}
- WaitCriterion ev = new WaitCriterion() {
- @Override
- public boolean done() {
- return proxy.getConnectedServerCount() == 1;
- }
-
- @Override
- public String description() {
- return null;
- }
- };
- GeodeAwaitility.await().untilAsserted(ev);
+ GeodeAwaitility.await().untilAsserted(() -> {
+ assertEquals(1, proxy.getConnectedServerCount());
+ });
} finally {
if (server != null) {
server.stop();
@@ -383,7 +369,7 @@ public class ConnectionProxyJUnitTest {
fail(" eid should not be duplicate as it is a new entry");
}
- verifyExpiry(60 * 1000);
+ verifyExpiry();
if (proxy.verifyIfDuplicate(eid)) {
fail(" eid should not be duplicate as the previous entry should have expired ");
@@ -429,18 +415,7 @@ public class ConnectionProxyJUnitTest {
fail(" eid should not be duplicate as it is a new entry");
}
- WaitCriterion ev = new WaitCriterion() {
- @Override
- public boolean done() {
- return proxy.verifyIfDuplicate(eid);
- }
-
- @Override
- public String description() {
- return null;
- }
- };
- GeodeAwaitility.await().untilAsserted(ev);
+ GeodeAwaitility.await().untilAsserted(() -> assertTrue(proxy.verifyIfDuplicate(eid)));
} catch (Exception ex) {
ex.printStackTrace();
fail("Failed to initialize client");
@@ -483,7 +458,7 @@ public class ConnectionProxyJUnitTest {
fail(" eid can never be duplicate, it is being created for the first time! ");
}
}
- verifyExpiry(30 * 1000);
+ verifyExpiry();
for (int i = 0; i < EVENT_ID_COUNT; i++) {
if (proxy.verifyIfDuplicate(eid[i])) {
@@ -697,7 +672,7 @@ public class ConnectionProxyJUnitTest {
// should send the ack to server
seo = (SequenceIdAndExpirationObject) proxy.getThreadIdToSequenceIdMap()
.get(new ThreadIdentifier(new byte[0], 1));
- verifyAckSend(60 * 1000, true);
+ verifyAckSend(true);
// New update on same threadId
eid = new EventID(new byte[0], 1, 2);
@@ -711,10 +686,10 @@ public class ConnectionProxyJUnitTest {
// should send another ack to server
seo = (SequenceIdAndExpirationObject) proxy.getThreadIdToSequenceIdMap()
.get(new ThreadIdentifier(new byte[0], 1));
- verifyAckSend(6000, true);
+ verifyAckSend(true);
// should expire with the this mentioned.
- verifyExpiry(15 * 1000);
+ verifyExpiry();
} catch (Exception ex) {
ex.printStackTrace();
fail("Test testPeriodicAckSendByClient Failed");
@@ -764,10 +739,10 @@ public class ConnectionProxyJUnitTest {
// should not send an ack as redundancy level = 0;
seo = (SequenceIdAndExpirationObject) proxy.getThreadIdToSequenceIdMap()
.get(new ThreadIdentifier(new byte[0], 1));
- verifyAckSend(30 * 1000, false);
+ verifyAckSend(false);
// should expire without sending an ack as redundancy level = 0.
- verifyExpiry(90 * 1000);
+ verifyExpiry();
}
catch (Exception ex) {
@@ -781,34 +756,16 @@ public class ConnectionProxyJUnitTest {
}
}
- private void verifyAckSend(long timeToWait, final boolean expectedAckSend) {
- WaitCriterion wc = new WaitCriterion() {
- @Override
- public boolean done() {
- return expectedAckSend == seo.getAckSend();
- }
-
- @Override
- public String description() {
- return "ack flag never became " + expectedAckSend;
- }
- };
- GeodeAwaitility.await().untilAsserted(wc);
+ private void verifyAckSend(final boolean expectedAckSend) {
+ GeodeAwaitility.await().timeout(timeoutToVerifyAckSend).untilAsserted(() -> {
+ assertEquals(expectedAckSend, seo.getAckSend());
+ });
}
- private void verifyExpiry(long timeToWait) {
- WaitCriterion wc = new WaitCriterion() {
- @Override
- public boolean done() {
- return 0 == proxy.getThreadIdToSequenceIdMap().size();
- }
-
- @Override
- public String description() {
- return "Entry never expired";
- }
- };
- GeodeAwaitility.await().untilAsserted(wc);
+ private void verifyExpiry() {
+ GeodeAwaitility.await().timeout(timeoutToVerifyExpiry).untilAsserted(() -> {
+ assertEquals(0, proxy.getThreadIdToSequenceIdMap().size());
+ });
}
}