本文整理汇总了Java中io.vertx.ext.unit.Async.awaitSuccess方法的典型用法代码示例。如果您正苦于以下问题:Java Async.awaitSuccess方法的具体用法?Java Async.awaitSuccess怎么用?Java Async.awaitSuccess使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.ext.unit.Async
的用法示例。
在下文中一共展示了Async.awaitSuccess方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSubscribe
import io.vertx.ext.unit.Async; //导入方法依赖的package包/类
@Test
public void testSubscribe(TestContext ctx) {
subscriber = PgSubscriber.subscriber(vertx, options);
Async connectLatch = ctx.async();
subscriber.connect(ctx.asyncAssertSuccess(v -> connectLatch.complete()));
connectLatch.awaitSuccess(10000);
PgChannel channel = subscriber.channel("the_channel");
Async subscribedLatch = ctx.async();
ctx.assertEquals(channel, channel.subscribeHandler(v -> subscribedLatch.complete()));
Async notifiedLatch = ctx.async();
channel.handler(notif -> {
ctx.assertEquals("msg", notif);
notifiedLatch.countDown();
});
subscribedLatch.awaitSuccess(10000);
subscriber.actualConnection().query("NOTIFY the_channel, 'msg'", ctx.asyncAssertSuccess());
notifiedLatch.awaitSuccess(10000);
}
示例2: testConnect
import io.vertx.ext.unit.Async; //导入方法依赖的package包/类
@Test
public void testConnect(TestContext ctx) {
subscriber = PgSubscriber.subscriber(vertx, options);
Async notifiedLatch = ctx.async();
PgChannel sub1 = subscriber.channel("channel1");
PgChannel sub2 = subscriber.channel("channel2");
sub1.handler(notif -> {
ctx.assertEquals("msg1", notif);
notifiedLatch.countDown();
});
sub2.handler(notif -> {
ctx.assertEquals("msg2", notif);
notifiedLatch.countDown();
});
Async connectLatch = ctx.async();
subscriber.connect(ctx.asyncAssertSuccess(v -> connectLatch.complete()));
connectLatch.awaitSuccess(10000);
subscriber.actualConnection().query("NOTIFY channel1, 'msg1'", ctx.asyncAssertSuccess());
subscriber.actualConnection().query("NOTIFY channel2, 'msg2'", ctx.asyncAssertSuccess());
notifiedLatch.awaitSuccess(10000);
}
示例3: test_fetchAllPagesData
import io.vertx.ext.unit.Async; //导入方法依赖的package包/类
@Test
public void test_fetchAllPagesData(TestContext context) {
Async async = context.async();
service.createPage("A", "abc", context.asyncAssertSuccess(p1 -> {
service.createPage("B", "123", context.asyncAssertSuccess(p2 -> {
service.fetchAllPagesData(context.asyncAssertSuccess(data -> {
context.assertEquals(2, data.size());
JsonObject a = data.get(0);
context.assertEquals("A", a.getString("NAME"));
context.assertEquals("abc", a.getString("CONTENT"));
JsonObject b = data.get(1);
context.assertEquals("B", b.getString("NAME"));
context.assertEquals("123", b.getString("CONTENT"));
async.complete();
}));
}));
}));
async.awaitSuccess(5000);
}
示例4: crud_operations
import io.vertx.ext.unit.Async; //导入方法依赖的package包/类
@Test
public void crud_operations(TestContext context) {
Async async = context.async();
service.createPage("Test", "Some content", context.asyncAssertSuccess(v1 -> {
service.fetchPage("Test", context.asyncAssertSuccess(json1 -> {
context.assertTrue(json1.getBoolean("found"));
context.assertTrue(json1.containsKey("id"));
context.assertEquals("Some content", json1.getString("rawContent"));
service.savePage(json1.getInteger("id"), "Yo!", context.asyncAssertSuccess(v2 -> {
service.fetchAllPages(context.asyncAssertSuccess(array1 -> {
context.assertEquals(1, array1.size());
service.fetchPage("Test", context.asyncAssertSuccess(json2 -> {
context.assertEquals("Yo!", json2.getString("rawContent"));
service.deletePage(json1.getInteger("id"), v3 -> {
service.fetchAllPages(context.asyncAssertSuccess(array2 -> {
context.assertTrue(array2.isEmpty());
async.complete(); // <1>
}));
});
}));
}));
}));
}));
}));
async.awaitSuccess(5000); // <2>
}
示例5: testCircuitBreakerLookupFail
import io.vertx.ext.unit.Async; //导入方法依赖的package包/类
@Test
public void testCircuitBreakerLookupFail(TestContext ctx) throws Exception {
Async async = ctx.async();
Router router = Router.router(vertx);
HttpServer server = vertx.createHttpServer().requestHandler(router::accept);
Flow flow = Flow.flow(vertx)
.withDiscovery(discovery)
.withBreaker(new CircuitBreakerOptions());
flow.route(router.get("/foo"), httpFlow -> {
httpFlow.httpRequest(new JsonObject().put("name", "hello-service"), HttpMethod.GET, "/", ctx.asyncAssertFailure(v1 -> {
publishBackend(ctx, v2 -> {
httpFlow.httpRequest(new JsonObject().put("name", "hello-service"), HttpMethod.GET, "/", ctx.asyncAssertSuccess(req -> {
req.send(ctx.asyncAssertSuccess(resp -> {
ctx.assertEquals(200, resp.statusCode());
httpFlow.response().end(resp.body());
async.complete();
}));
}));
});
}));
});
Async listenAsync = ctx.async();
server.listen(8080, ctx.asyncAssertSuccess(v -> listenAsync.complete()));
listenAsync.awaitSuccess(10000);
startBackendBlocking(ctx);
client
.get(8080, "localhost", "/foo")
.send(ctx.asyncAssertSuccess(resp -> {
ctx.assertEquals(200, resp.statusCode());
ctx.assertEquals("Hello World", resp.bodyAsString());
}));
}
示例6: crud_operations
import io.vertx.ext.unit.Async; //导入方法依赖的package包/类
@Test
public void crud_operations(TestContext context) {
Async async = context.async();
service.createPage("Test", "Some content", context.asyncAssertSuccess(v1 -> {
service.fetchPage("Test", context.asyncAssertSuccess(json1 -> {
context.assertTrue(json1.getBoolean("found"));
context.assertTrue(json1.containsKey("id"));
context.assertEquals("Some content", json1.getString("rawContent"));
service.savePage(json1.getInteger("id"), "Yo!", context.asyncAssertSuccess(v2 -> {
service.fetchAllPages(context.asyncAssertSuccess(array1 -> {
context.assertEquals(1, array1.size());
service.fetchPage("Test", context.asyncAssertSuccess(json2 -> {
context.assertEquals("Yo!", json2.getString("rawContent"));
service.deletePage(json1.getInteger("id"), v3 -> {
service.fetchAllPages(context.asyncAssertSuccess(array2 -> {
context.assertTrue(array2.isEmpty());
async.complete();
}));
});
}));
}));
}));
}));
}));
async.awaitSuccess(5000);
}
示例7: test400
import io.vertx.ext.unit.Async; //导入方法依赖的package包/类
@Test
public void test400(final TestContext testContext) throws Exception {
final HttpServerRequest serverRequest = mock(HttpServerRequest.class);
when(serverRequest.absoluteURI()).thenReturn("http://test.trajano.net/api/hello/400");
when(serverRequest.path()).thenReturn("/api/hello/400");
when(serverRequest.uri()).thenReturn("/api/hello/400");
when(serverRequest.isEnded()).thenReturn(true);
when(serverRequest.method()).thenReturn(HttpMethod.GET);
final HttpServerResponse response = mock(HttpServerResponse.class);
when(response.putHeader(anyString(), anyString())).thenReturn(response);
when(response.putHeader(any(AsciiString.class), anyString())).thenReturn(response);
when(response.headers()).thenReturn(new VertxHttpHeaders());
final Async async = testContext.async();
when(response.setStatusCode(Matchers.any(Integer.class))).then(invocation -> {
try {
return response;
} finally {
async.complete();
}
});
when(serverRequest.response()).thenReturn(response);
router.accept(serverRequest);
async.awaitSuccess();
verify(response, times(1)).setStatusCode(400);
}
示例8: testHttpToHttp
import io.vertx.ext.unit.Async; //导入方法依赖的package包/类
@Test
public void testHttpToHttp(TestContext ctx) throws Exception {
Async async = ctx.async();
Router router = Router.router(vertx);
HttpServer server = vertx.createHttpServer().requestHandler(router::accept);
Flow flow = Flow.flow(vertx)
.withDiscovery(discovery);
flow.route(router.get("/foo"), httpFlow -> {
httpFlow.httpRequest(new JsonObject().put("name", "hello-service"), HttpMethod.GET, "/", ctx.asyncAssertSuccess(req -> {
req.send(ctx.asyncAssertSuccess(resp -> {
ctx.assertEquals(200, resp.statusCode());
httpFlow.response().end(resp.body());
async.complete();
}));
}));
});
Async listenAsync = ctx.async();
server.listen(8080, ctx.asyncAssertSuccess(v -> listenAsync.complete()));
listenAsync.awaitSuccess(10000);
startBackendBlocking(ctx);
publishBackendBlocking(ctx);
client
.get(8080, "localhost", "/foo")
.send(ctx.asyncAssertSuccess(resp -> {
ctx.assertEquals(200, resp.statusCode());
ctx.assertEquals("Hello World", resp.bodyAsString());
}));
}
示例9: startServerBlocking
import io.vertx.ext.unit.Async; //导入方法依赖的package包/类
private HttpServer startServerBlocking(TestContext ctx, int port, Handler<HttpServerRequest> requestHandler) {
Async async = ctx.async();
HttpServer server = vertx.createHttpServer()
.requestHandler(requestHandler)
.listen(port, ctx.asyncAssertSuccess(v -> async.complete()));
async.awaitSuccess(10000);
return server;
}
示例10: testCircuitBreakerOpen
import io.vertx.ext.unit.Async; //导入方法依赖的package包/类
@Test
public void testCircuitBreakerOpen(TestContext ctx) throws Exception {
Async async = ctx.async();
Router router = Router.router(vertx);
HttpServer server = vertx.createHttpServer().requestHandler(router::accept);
Flow flow = Flow.flow(vertx)
.withDiscovery(discovery);
flow.route(router.get("/foo"), httpFlow -> {
AtomicInteger count = new AtomicInteger(6);
doRec(6, fut -> {
httpFlow.httpRequest(new JsonObject().put("name", "hello-service"), HttpMethod.GET, "/", ctx.asyncAssertFailure(v1 -> {
CircuitBreakerState state = flow.breaker("hello-service").state();
int val = count.decrementAndGet();
if (val == 0) {
ctx.assertEquals(CircuitBreakerState.OPEN, state);
httpFlow.response().end("failed");
async.complete();
} else if (val == 1) {
ctx.assertEquals(CircuitBreakerState.OPEN, state);
} else {
ctx.assertEquals(CircuitBreakerState.CLOSED, state);
}
fut.complete();
}));
});
});
Async listenAsync = ctx.async();
server.listen(8080, ctx.asyncAssertSuccess(v -> listenAsync.complete()));
listenAsync.awaitSuccess(10000);
client
.get(8080, "localhost", "/foo")
.send(ctx.asyncAssertSuccess(resp -> {
ctx.assertEquals(200, resp.statusCode());
ctx.assertEquals("failed", resp.bodyAsString());
}));
}
示例11: testNegotiation
import io.vertx.ext.unit.Async; //导入方法依赖的package包/类
private void testNegotiation(int amount, TestContext context) {
PrimaryVertex pv = new PrimaryVertex();
GDHVertex[] verticles = new GDHVertex[amount];
Configuration[] confs = new Configuration[amount];
Writer writer = new StringWriter();
for (int i = 0; i < amount; i++) {
verticles[i] = new GDHVertex();
confs[i] = new Configuration();
WriterAppender app = new WriterAppender(new PatternLayout(), writer);
app.setThreshold(Level.DEBUG);
app.activateOptions();
confs[i].setAppender(app);
String port = amount + "08" + i;
confs[i].setIP("localhost").setPort(port).setLogLevel(Level.DEBUG);
verticles[i].setConfiguration(confs[i]);
}
List<GDHVertex> list = new ArrayList<>(Arrays.asList(verticles));
Group g = new Group(confs[0], list.stream().map(y -> y.getNode()).collect(Collectors.toList()));
verticles[0].addGroup(g);
Async async1 = context.async(amount);
for (int i = 0; i < amount; i++)
pv.run(verticles[i], res -> {
if (res.succeeded()) {
async1.countDown();
} else {
res.cause().printStackTrace();
return;
}
});
async1.awaitSuccess();
BigInteger[] keys = new BigInteger[2];
try {
keys[0] = verticles[0].exchange(g.getGroupId()).get();
Assert.assertFalse(!writer.toString().isEmpty() && writer.toString().contains(keys[0].toString()));
} catch (InterruptedException | ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Async async2 = context.async(amount);
for (int i = 0; i < amount; i++)
pv.kill(verticles[i], res -> {
if (res.succeeded()) {
async2.countDown();
} else {
res.cause().printStackTrace();
}
});
async2.awaitSuccess();
}
示例12: testNegotiation
import io.vertx.ext.unit.Async; //导入方法依赖的package包/类
private void testNegotiation(int amount, TestContext context) {
// Vertx vertx = Vertx.vertx();
PrimaryVertex pv = new PrimaryVertex();
GDHVertex[] verticles = new GDHVertex[amount];
Configuration[] confs = new Configuration[amount];
for (int i = 0; i < amount; i++) {
verticles[i] = new GDHVertex();
confs[i] = new Configuration();
String port = amount + "07" + i;
confs[i].setIP("localhost").setPort(port).setLogLevel(Level.DEBUG);
verticles[i].setConfiguration(confs[i]);
}
List<GDHVertex> list = new ArrayList<>(Arrays.asList(verticles));
Group g = new Group(confs[0], list.stream().map(y -> y.getNode()).collect(Collectors.toList()));
verticles[0].addGroup(g);
Async async1 = context.async(amount);
for (int i = 0; i < amount; i++)
pv.run(verticles[i], res -> {
if (res.succeeded()) {
async1.countDown();
} else {
res.cause().printStackTrace();
return;
}
});
async1.awaitSuccess();
BigInteger key = null;
try {
CompletableFuture<BigInteger> bigint = verticles[0].exchange(g.getGroupId());
// double messages check
Method method1 = verticles[0].getClass().getDeclaredMethod("broadcast", Group.class);
method1.setAccessible(true);
method1.invoke(verticles[0],g);
// sending message of unknown group
Method method2 = verticles[0].getClass().getDeclaredMethod("sendMessage", Node.class, JsonObject.class);
method2.setAccessible(true);
method2.invoke(verticles[0],verticles[1].getNode(), MessageConstructor.roundInfo(new ExchangeState(45622, BigInteger.TEN)));
key = bigint.get();
for (int j = 0; j < verticles.length; j++) {
Assert.assertEquals(verticles[j].getKey(g.getGroupId()).get(), key);
}
} catch (InterruptedException | ExecutionException | SecurityException |
IllegalArgumentException | NoSuchMethodException | IllegalAccessException |
InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Async async2 = context.async(amount);
for (int i = 0; i < amount; i++)
pv.kill(verticles[i], res -> {
if (res.succeeded()) {
async2.countDown();
} else {
res.cause().printStackTrace();
}
});
async2.awaitSuccess();
}
示例13: testNegotiation
import io.vertx.ext.unit.Async; //导入方法依赖的package包/类
private void testNegotiation(int amount, TestContext context) {
// Vertx vertx = Vertx.vertx();
PrimaryVertex pv = new PrimaryVertex();
GDHVertex[] verticles = new GDHVertex[amount];
Configuration[] confs = new Configuration[amount];
for (int i = 0; i < amount; i++) {
verticles[i] = new GDHVertex();
confs[i] = new Configuration();
String port = amount + "07" + i;
confs[i].setIP("localhost").setPort(port).setLogLevel(Level.DEBUG);
verticles[i].setConfiguration(confs[i]);
}
List<GDHVertex> list = new ArrayList<>(Arrays.asList(verticles));
Group g = new Group(confs[0], list.stream().map(y -> y.getNode()).collect(Collectors.toList()));
verticles[0].addGroup(g);
Async async1 = context.async(amount);
for (int i = 0; i < amount; i++)
pv.run(verticles[i], res -> {
if (res.succeeded()) {
async1.countDown();
} else {
res.cause().printStackTrace();
return;
}
});
async1.awaitSuccess();
BigInteger key = null;
try {
key = verticles[0].exchange(g.getGroupId()).get();
for (int j = 0; j < verticles.length; j++) {
Assert.assertEquals(verticles[j].getKey(g.getGroupId()).get(), key);
}
} catch (InterruptedException | ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Async async2 = context.async(amount);
for (int i = 0; i < amount; i++)
pv.kill(verticles[i], res -> {
if (res.succeeded()) {
async2.countDown();
} else {
res.cause().printStackTrace();
}
});
async2.awaitSuccess();
}
示例14: testNegotiation
import io.vertx.ext.unit.Async; //导入方法依赖的package包/类
private void testNegotiation(int amount, TestContext context) {
PrimaryVertex pv = new PrimaryVertex();
GDHVertex[] verticles = new GDHVertex[amount];
Configuration[] confs = new Configuration[amount];
for (int i = 0; i < amount; i++) {
verticles[i] = new GDHVertex();
confs[i] = new Configuration();
String port = amount + "09" + i;
confs[i].setIP("localhost").setPort(port).setLogLevel(Level.DEBUG);
verticles[i].setConfiguration(confs[i]);
}
Group[] groups = new Group[amount - 1];
BigInteger[] keys = new BigInteger[amount - 1];
for (int i = 0; i < amount - 1; i++) {
groups[i] = new Group(confs[0], verticles[0].getNode(), verticles[i + 1].getNode());
verticles[0].addGroup(groups[i]);
}
Async async1 = context.async(amount);
for (int i = 0; i < amount; i++)
pv.run(verticles[i], res -> {
if (res.succeeded()) {
async1.countDown();
} else {
res.cause().printStackTrace();
return;
}
});
async1.awaitSuccess();
try {
for (int i = 0; i < amount - 1; i++)
keys[i] = verticles[0].exchange(groups[i].getGroupId()).get();
for (int i = 0; i < amount - 1; i++)
Assert.assertEquals(verticles[i + 1].getKey(groups[i].getGroupId()).get(),
verticles[0].getKey(groups[i].getGroupId()).get());
Map<BigInteger, Integer> mapOfKeys = new HashMap<>();
for (int i = 0; i < amount - 1; i++) {
BigInteger key = verticles[i + 1].getKey(groups[i].getGroupId()).get();
if (mapOfKeys.containsKey(key))
mapOfKeys.put(key, mapOfKeys.get(key) + 1);
else
mapOfKeys.put(key, 1);
}
for (Integer count : mapOfKeys.values())
Assert.assertTrue(count == 1);
} catch (InterruptedException | ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Async async2 = context.async(amount);
for (int i = 0; i < amount; i++)
pv.kill(verticles[i], res -> {
if (res.succeeded()) {
async2.countDown();
} else {
res.cause().printStackTrace();
}
});
async2.awaitSuccess();
}
示例15: testNegotiation
import io.vertx.ext.unit.Async; //导入方法依赖的package包/类
private void testNegotiation(int amount, TestContext context) {
PrimaryVertex pv = new PrimaryVertex();
GDHVertex[] verticles = new GDHVertex[amount];
Configuration[] confs = new Configuration[amount];
Writer writer = new StringWriter();
for (int i = 0; i < amount; i++) {
verticles[i] = new GDHVertex();
confs[i] = new Configuration();
WriterAppender app = new WriterAppender(new PatternLayout(), writer);
app.setThreshold(Level.DEBUG);
app.activateOptions();
confs[i].setAppender(app);
String port = amount + "08" + i;
confs[i].setIP("localhost").setPort(port).setLogLevel(Level.DEBUG);
verticles[i].setConfiguration(confs[i]);
}
List<GDHVertex> list = new ArrayList<>(Arrays.asList(verticles));
Group g = new Group(confs[0], list.stream().map(y -> y.getNode()).collect(Collectors.toList()));
verticles[0].addGroup(g);
Async async1 = context.async(amount);
for (int i = 0; i < amount; i++)
pv.run(verticles[i], res -> {
if (res.succeeded()) {
async1.countDown();
} else {
res.cause().printStackTrace();
return;
}
});
async1.awaitSuccess();
BigInteger[] keys = new BigInteger[1];
try {
keys[0] = verticles[0].exchange(g.getGroupId()).get();
for (int j = 0; j < verticles.length; j++) {
Assert.assertEquals(verticles[j].getKey(g.getGroupId()).get(), keys[0]);
}
//System.out.println(StringUtils.countMatches(writer.toString(), Constants.LOG_IN));
//System.out.println(StringUtils.countMatches(writer.toString(), Constants.LOG_OUT));
Assert.assertTrue(StringUtils.countMatches(writer.toString(), Constants.LOG_IN) >= amount*amount-1);
Assert.assertTrue(StringUtils.countMatches(writer.toString(), Constants.LOG_OUT) >= amount*amount-1);
} catch (InterruptedException | ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Async async2 = context.async(amount);
for (int i = 0; i < amount; i++)
pv.kill(verticles[i], res -> {
if (res.succeeded()) {
async2.countDown();
} else {
res.cause().printStackTrace();
}
});
async2.awaitSuccess();
}