Skip to content

Instantly share code, notes, and snippets.

@vietj
Created December 15, 2016 19:36
Show Gist options
  • Save vietj/331fa5fb73fae8e19ed4a0f1b178f4a3 to your computer and use it in GitHub Desktop.
Save vietj/331fa5fb73fae8e19ed4a0f1b178f4a3 to your computer and use it in GitHub Desktop.
package vertx.proxy.issue.proxy.bottleneck;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
import io.vertx.serviceproxy.ProxyHelper;
import service.issue.bottleneck.TestService;
import service.issue.bottleneck.TestVerticle;
@RunWith(VertxUnitRunner.class)
public class ServiceTest {
private static TestService service;
private Vertx vertx;
@Before
public void setUpBeforeClass(TestContext context) throws Exception {
vertx = Vertx.vertx();
DeploymentOptions options = new DeploymentOptions();
vertx.deployVerticle(TestVerticle.class.getName(), options, context.asyncAssertSuccess());
service = ProxyHelper.createProxy(TestService.class, vertx, TestService.SERVICE_ADDRESS);
}
@After
public void tearDownAfterClass(TestContext context) throws Exception {
vertx.close(context.asyncAssertSuccess());
}
@Test
public void test() throws Exception {
CountDownLatch latch = new CountDownLatch(100 * 100);
long[] latencies = new long[100 * 100];
long runStart = System.currentTimeMillis();
vertx.runOnContext(v1 -> {
for (int j = 0;j < 100;j++) {
int runNum = j;
vertx.runOnContext(v2 -> {
for (int i = 0; i < 100; i++) {
int index = runNum + i;
long startTime = System.currentTimeMillis();
service.test(handler -> {
long endTime = System.currentTimeMillis();
latencies[index] = endTime - startTime;
latch.countDown();
});
}
});
}
});
latch.await(100, TimeUnit.SECONDS);
long runEnd = System.currentTimeMillis();
// Find the max
long max = 0;
long min = Long.MAX_VALUE;
for (int i = 0; i < latencies.length; i++) {
max = Math.max(max, latencies[i]);
min = Math.min(min, latencies[i]);
}
System.out.println("################ Completed Test generated: " + (runEnd - runStart) + "ms ################");
System.out.println("max " + max);
System.out.println("min " + min);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment