Skip to content

Commit

Permalink
Renamed to assertWaitUntil
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Segismont <tsegismont@gmail.com>
  • Loading branch information
tsegismont committed Mar 20, 2017
1 parent 06fbf2a commit 5757213
Show file tree
Hide file tree
Showing 12 changed files with 145 additions and 111 deletions.
14 changes: 7 additions & 7 deletions src/test/java/io/vertx/test/core/AsyncTestBase.java
Expand Up @@ -592,21 +592,21 @@ protected void awaitLatch(CountDownLatch latch) throws InterruptedException {
assertTrue(latch.await(10, TimeUnit.SECONDS)); assertTrue(latch.await(10, TimeUnit.SECONDS));
} }


protected void waitUntil(BooleanSupplier supplier) { protected void assertWaitUntil(BooleanSupplier supplier) {
waitUntil(supplier, 10000); assertWaitUntil(supplier, 10000);
} }


protected void waitUntilNoFail(BooleanSupplier supplier) { protected void waitUntil(BooleanSupplier supplier) {
waitUntilNoFail(supplier, 10000); waitUntil(supplier, 10000);
} }


protected void waitUntil(BooleanSupplier supplier, long timeout) { protected void assertWaitUntil(BooleanSupplier supplier, long timeout) {
if (!waitUntilNoFail(supplier, timeout)) { if (!waitUntil(supplier, timeout)) {
throw new IllegalStateException("Timed out"); throw new IllegalStateException("Timed out");
} }
} }


protected boolean waitUntilNoFail(BooleanSupplier supplier, long timeout) { protected boolean waitUntil(BooleanSupplier supplier, long timeout) {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
while (true) { while (true) {
if (supplier.getAsBoolean()) { if (supplier.getAsBoolean()) {
Expand Down
31 changes: 23 additions & 8 deletions src/test/java/io/vertx/test/core/DeploymentTest.java
Expand Up @@ -16,9 +16,19 @@


package io.vertx.test.core; package io.vertx.test.core;


import io.vertx.core.*; import io.vertx.core.AbstractVerticle;
import io.vertx.core.AsyncResult;
import io.vertx.core.Closeable;
import io.vertx.core.Context;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Future;
import io.vertx.core.Verticle;
import io.vertx.core.Vertx;
import io.vertx.core.eventbus.Message; import io.vertx.core.eventbus.Message;
import io.vertx.core.impl.*; import io.vertx.core.impl.ContextImpl;
import io.vertx.core.impl.Deployment;
import io.vertx.core.impl.VertxInternal;
import io.vertx.core.impl.WorkerContext;
import io.vertx.core.impl.verticle.CompilingClassLoader; import io.vertx.core.impl.verticle.CompilingClassLoader;
import io.vertx.core.json.JsonArray; import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject; import io.vertx.core.json.JsonObject;
Expand All @@ -29,7 +39,12 @@
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.*; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -235,7 +250,7 @@ public void testDeployFromTestThread() throws Exception {
public void testDeployFromTestThreadNoHandler() throws Exception { public void testDeployFromTestThreadNoHandler() throws Exception {
MyVerticle verticle = new MyVerticle(); MyVerticle verticle = new MyVerticle();
vertx.deployVerticle(verticle); vertx.deployVerticle(verticle);
waitUntil(() -> vertx.deploymentIDs().size() == 1); assertWaitUntil(() -> vertx.deploymentIDs().size() == 1);
} }


@Test @Test
Expand Down Expand Up @@ -513,7 +528,7 @@ public void testUndeployNoHandler() throws Exception {
assertTrue(ar.succeeded()); assertTrue(ar.succeeded());
vertx.undeploy(ar.result()); vertx.undeploy(ar.result());
}); });
waitUntil(() -> vertx.deploymentIDs().isEmpty()); assertWaitUntil(() -> vertx.deploymentIDs().isEmpty());
} }


@Test @Test
Expand Down Expand Up @@ -686,7 +701,7 @@ public void testDeployUndeployMultipleInstancesUsingClassName() throws Exception
deployLatch.countDown(); deployLatch.countDown();
})); }));
awaitLatch(deployLatch); awaitLatch(deployLatch);
waitUntil(() -> deployCount.get() == numInstances); assertWaitUntil(() -> deployCount.get() == numInstances);
assertEquals(1, vertx.deploymentIDs().size()); assertEquals(1, vertx.deploymentIDs().size());
Deployment deployment = ((VertxInternal) vertx).getDeployment(vertx.deploymentIDs().iterator().next()); Deployment deployment = ((VertxInternal) vertx).getDeployment(vertx.deploymentIDs().iterator().next());
Set<Verticle> verticles = deployment.getVerticles(); Set<Verticle> verticles = deployment.getVerticles();
Expand All @@ -698,7 +713,7 @@ public void testDeployUndeployMultipleInstancesUsingClassName() throws Exception
undeployLatch.countDown(); undeployLatch.countDown();
})); }));
awaitLatch(undeployLatch); awaitLatch(undeployLatch);
waitUntil(() -> deployCount.get() == numInstances); assertWaitUntil(() -> deployCount.get() == numInstances);
assertTrue(vertx.deploymentIDs().isEmpty()); assertTrue(vertx.deploymentIDs().isEmpty());
} }


Expand Down Expand Up @@ -1292,7 +1307,7 @@ private void testIsolationGroup(String group1, String group2, int count1, int co
}); });
awaitLatch(latch); awaitLatch(latch);
// Wait until two entries in the map // Wait until two entries in the map
waitUntil(() -> countMap.size() == 2); assertWaitUntil(() -> countMap.size() == 2);
assertEquals(count1, countMap.get(deploymentID1.get()).intValue()); assertEquals(count1, countMap.get(deploymentID1.get()).intValue());
assertEquals(count2, countMap.get(deploymentID2.get()).intValue()); assertEquals(count2, countMap.get(deploymentID2.get()).intValue());
} }
Expand Down
6 changes: 2 additions & 4 deletions src/test/java/io/vertx/test/core/EventBusFlowControlTest.java
Expand Up @@ -8,9 +8,7 @@
import io.vertx.core.eventbus.MessageProducer; import io.vertx.core.eventbus.MessageProducer;
import org.junit.Test; import org.junit.Test;


import java.util.ArrayList;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -162,9 +160,9 @@ public void testResumePausedProducer() {
prod.send(val); prod.send(val);
} }
consumer.resume(); consumer.resume();
waitUntil(() -> !prod.writeQueueFull()); assertWaitUntil(() -> !prod.writeQueueFull());
int theCount = count; int theCount = count;
waitUntil(() -> sequence.size() == theCount); assertWaitUntil(() -> sequence.size() == theCount);
while (expected.size() > 0) { while (expected.size() > 0) {
assertEquals(expected.removeFirst(), sequence.poll()); assertEquals(expected.removeFirst(), sequence.poll());
} }
Expand Down
20 changes: 10 additions & 10 deletions src/test/java/io/vertx/test/core/HATest.java
Expand Up @@ -62,7 +62,7 @@ public void testSimpleFailover() throws Exception {
}); });
awaitLatch(latch); awaitLatch(latch);
kill(0); kill(0);
waitUntil(() -> vertices[1].deploymentIDs().size() == 1); assertWaitUntil(() -> vertices[1].deploymentIDs().size() == 1);
checkDeploymentExists(1, "java:" + HAVerticle1.class.getName(), options); checkDeploymentExists(1, "java:" + HAVerticle1.class.getName(), options);
} }


Expand All @@ -78,7 +78,7 @@ public void testQuorum() throws Exception {
testComplete(); testComplete();
}); });
// Shouldn't deploy until a quorum is obtained // Shouldn't deploy until a quorum is obtained
waitUntil(() -> vertx1.deploymentIDs().isEmpty()); assertWaitUntil(() -> vertx1.deploymentIDs().isEmpty());
vertx2 = startVertx(2); vertx2 = startVertx(2);
// Now should be deployed // Now should be deployed
await(); await();
Expand All @@ -102,17 +102,17 @@ public void testQuorumLost() throws Exception {
assertTrue(vertx2.deploymentIDs().contains(ar.result())); assertTrue(vertx2.deploymentIDs().contains(ar.result()));
; ;
}); });
waitUntil(() -> vertx1.deploymentIDs().size() == 1 && vertx2.deploymentIDs().size() == 1); assertWaitUntil(() -> vertx1.deploymentIDs().size() == 1 && vertx2.deploymentIDs().size() == 1);
// Now close vertx3 - quorum should then be lost and verticles undeployed // Now close vertx3 - quorum should then be lost and verticles undeployed
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
vertx3.close(ar -> { vertx3.close(ar -> {
latch.countDown(); latch.countDown();
}); });
awaitLatch(latch); awaitLatch(latch);
waitUntil(() -> vertx1.deploymentIDs().isEmpty() && vertx2.deploymentIDs().isEmpty()); assertWaitUntil(() -> vertx1.deploymentIDs().isEmpty() && vertx2.deploymentIDs().isEmpty());
// Now re-instate the quorum // Now re-instate the quorum
vertx4 = startVertx(3); vertx4 = startVertx(3);
waitUntil(() -> vertx1.deploymentIDs().size() == 1 && vertx2.deploymentIDs().size() == 1); assertWaitUntil(() -> vertx1.deploymentIDs().size() == 1 && vertx2.deploymentIDs().size() == 1);


} }


Expand Down Expand Up @@ -180,7 +180,7 @@ public void testFailureInFailover() throws Exception {
}); });
((VertxInternal)vertx3).simulateKill(); ((VertxInternal)vertx3).simulateKill();
awaitLatch(latch3); awaitLatch(latch3);
waitUntil(() -> vertx2.deploymentIDs().size() == 1); assertWaitUntil(() -> vertx2.deploymentIDs().size() == 1);
} }


@Test @Test
Expand Down Expand Up @@ -335,7 +335,7 @@ public void testQuorumWithHaGroups() throws Exception {


vertx3 = startVertx("group1", 2); vertx3 = startVertx("group1", 2);
// Now should deploy // Now should deploy
waitUntil(() -> vertx1.deploymentIDs().size() == 1); assertWaitUntil(() -> vertx1.deploymentIDs().size() == 1);


vertx2.deployVerticle("java:" + HAVerticle1.class.getName(), new DeploymentOptions().setHa(true), ar -> { vertx2.deployVerticle("java:" + HAVerticle1.class.getName(), new DeploymentOptions().setHa(true), ar -> {
assertTrue(ar.succeeded()); assertTrue(ar.succeeded());
Expand All @@ -349,7 +349,7 @@ public void testQuorumWithHaGroups() throws Exception {


vertx4 = startVertx("group2", 2); vertx4 = startVertx("group2", 2);
// Now should deploy // Now should deploy
waitUntil(() -> vertx2.deploymentIDs().size() == 1); assertWaitUntil(() -> vertx2.deploymentIDs().size() == 1);


// Noow stop vertx4 // Noow stop vertx4
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
Expand All @@ -358,7 +358,7 @@ public void testQuorumWithHaGroups() throws Exception {
}); });


awaitLatch(latch); awaitLatch(latch);
waitUntil(() -> vertx2.deploymentIDs().isEmpty()); assertWaitUntil(() -> vertx2.deploymentIDs().isEmpty());


assertTrue(vertx1.deploymentIDs().size() == 1); assertTrue(vertx1.deploymentIDs().size() == 1);


Expand All @@ -369,7 +369,7 @@ public void testQuorumWithHaGroups() throws Exception {


awaitLatch(latch2); awaitLatch(latch2);


waitUntil(() -> vertx1.deploymentIDs().isEmpty()); assertWaitUntil(() -> vertx1.deploymentIDs().isEmpty());
} }


protected Vertx startVertx() throws Exception { protected Vertx startVertx() throws Exception {
Expand Down
13 changes: 9 additions & 4 deletions src/test/java/io/vertx/test/core/Http2ClientTest.java
Expand Up @@ -46,7 +46,13 @@
import io.netty.handler.ssl.ApplicationProtocolNegotiationHandler; import io.netty.handler.ssl.ApplicationProtocolNegotiationHandler;
import io.netty.handler.ssl.SslHandler; import io.netty.handler.ssl.SslHandler;
import io.netty.util.AsciiString; import io.netty.util.AsciiString;
import io.vertx.core.*; import io.vertx.core.AbstractVerticle;
import io.vertx.core.Context;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.Verticle;
import io.vertx.core.Vertx;
import io.vertx.core.buffer.Buffer; import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.HttpClientOptions; import io.vertx.core.http.HttpClientOptions;
import io.vertx.core.http.HttpClientRequest; import io.vertx.core.http.HttpClientRequest;
Expand All @@ -58,7 +64,6 @@
import io.vertx.core.http.HttpVersion; import io.vertx.core.http.HttpVersion;
import io.vertx.core.http.StreamResetException; import io.vertx.core.http.StreamResetException;
import io.vertx.core.impl.VertxInternal; import io.vertx.core.impl.VertxInternal;
import io.vertx.core.net.JksOptions;
import io.vertx.core.net.NetSocket; import io.vertx.core.net.NetSocket;
import io.vertx.core.net.SocketAddress; import io.vertx.core.net.SocketAddress;
import io.vertx.core.net.impl.SSLHelper; import io.vertx.core.net.impl.SSLHelper;
Expand All @@ -84,7 +89,7 @@
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;


import static io.vertx.test.core.TestUtils.assertIllegalStateException; import static io.vertx.test.core.TestUtils.*;


/** /**
* @author <a href="mailto:julien@julienviet.com">Julien Viet</a> * @author <a href="mailto:julien@julienviet.com">Julien Viet</a>
Expand Down Expand Up @@ -1744,7 +1749,7 @@ private void testMaxConcurrency(int poolSize, int maxConcurrency) throws Excepti
} }
if (j < poolSize) { if (j < poolSize) {
int threshold = j + 1; int threshold = j + 1;
waitUntil(() -> clientConnections.size() == threshold); assertWaitUntil(() -> clientConnections.size() == threshold);
} }
} }


Expand Down
4 changes: 1 addition & 3 deletions src/test/java/io/vertx/test/core/Http2Test.java
Expand Up @@ -24,9 +24,7 @@
import io.vertx.core.http.HttpServerOptions; import io.vertx.core.http.HttpServerOptions;
import io.vertx.core.http.HttpServerResponse; import io.vertx.core.http.HttpServerResponse;
import io.vertx.core.http.StreamResetException; import io.vertx.core.http.StreamResetException;
import io.vertx.core.net.NetServer;
import io.vertx.core.net.OpenSSLEngineOptions; import io.vertx.core.net.OpenSSLEngineOptions;
import io.vertx.core.net.PemKeyCertOptions;
import io.vertx.test.core.tls.Cert; import io.vertx.test.core.tls.Cert;
import org.junit.Test; import org.junit.Test;


Expand Down Expand Up @@ -257,7 +255,7 @@ public void testClientStreamPausedWhenConnectionIsPaused() throws Exception {
resumeLatch.complete(null); resumeLatch.complete(null);
}); });
resumeLatch.get(20, TimeUnit.SECONDS); resumeLatch.get(20, TimeUnit.SECONDS);
waitUntil(() -> !req2.writeQueueFull()); assertWaitUntil(() -> !req2.writeQueueFull());
req1.end(); req1.end();
req2.end(buffer); req2.end(buffer);
await(); await();
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/io/vertx/test/core/HttpMetricsTest.java
Expand Up @@ -118,10 +118,10 @@ private void testHttpMetricsLifecycle(HttpVersion protocol) throws Exception {
}); });
awaitLatch(latch); awaitLatch(latch);
client.close(); client.close();
waitUntil(() -> !serverMetric.get().socket.connected.get()); assertWaitUntil(() -> !serverMetric.get().socket.connected.get());
assertEquals(contentLength, serverMetric.get().socket.bytesRead.get()); assertEquals(contentLength, serverMetric.get().socket.bytesRead.get());
assertEquals(contentLength, serverMetric.get().socket.bytesWritten.get()); assertEquals(contentLength, serverMetric.get().socket.bytesWritten.get());
waitUntil(() -> !clientMetric.get().socket.connected.get()); assertWaitUntil(() -> !clientMetric.get().socket.connected.get());
assertEquals(contentLength, clientMetric.get().socket.bytesRead.get()); assertEquals(contentLength, clientMetric.get().socket.bytesRead.get());
assertEquals(contentLength, clientMetric.get().socket.bytesWritten.get()); assertEquals(contentLength, clientMetric.get().socket.bytesWritten.get());
} }
Expand Down

0 comments on commit 5757213

Please sign in to comment.