Skip to content

Instantly share code, notes, and snippets.

@jotak
Last active January 26, 2018 09:50
Show Gist options
  • Save jotak/b72f2ea93428b5e6989ed11437e89ce5 to your computer and use it in GitHub Desktop.
Save jotak/b72f2ea93428b5e6989ed11437e89ce5 to your computer and use it in GitHub Desktop.
Hanging test
package io.vertx.monitoring;
import io.vertx.core.Vertx;
import io.vertx.ext.unit.Async;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.atomic.LongAdder;
/**
* @author Joel Takvorian
*/
@RunWith(VertxUnitRunner.class)
public class MyTest {
private static final int SENT_COUNT = 5;
private final int concurrentClients = ForkJoinPool.commonPool().getParallelism();
private Vertx vertx;
@Before
public void setUp(TestContext ctx) {
vertx = Vertx.vertx();
System.out.println("setUp complete");
}
@After
public void teardown() {
System.out.println("tearDown complete");
}
@Test
public void test(TestContext ctx) throws InterruptedException {
System.out.println("starting test [expecting " + concurrentClients*SENT_COUNT + " async tasks]");
Async clientsFinished = ctx.async(concurrentClients);
LongAdder la = new LongAdder();
for (int i = 0; i < concurrentClients; i++) {
ForkJoinPool.commonPool().execute(() -> {
for (int j = 0; j < SENT_COUNT; j++) {
Async async = ctx.async();
vertx.setTimer(30, h -> {
async.complete();
la.increment();
System.out.println("completed n." + la.intValue());
});
async.await();
}
clientsFinished.countDown();
});
}
System.out.println("awaiting...");
clientsFinished.awaitSuccess();
System.out.println("test finished");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment