本文整理汇总了Java中io.vertx.ext.unit.Async.await方法的典型用法代码示例。如果您正苦于以下问题:Java Async.await方法的具体用法?Java Async.await怎么用?Java Async.await使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.ext.unit.Async
的用法示例。
在下文中一共展示了Async.await方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test404
import io.vertx.ext.unit.Async; //导入方法依赖的package包/类
@Test
public void test404(final TestContext testContext) throws Exception {
final Router router = Router.router(rule.vertx());
final JaxRsRouter jaxRsRouter = new JaxRsRouter();
final SpringJaxRsHandler handler = new SpringJaxRsHandler(MyApp.class);
jaxRsRouter.register(MyApp.class, router, handler, handler);
final HttpServerRequest serverRequest = mock(HttpServerRequest.class);
when(serverRequest.absoluteURI()).thenReturn("http://test.trajano.net/api/nothello");
when(serverRequest.path()).thenReturn("/api/nothello");
when(serverRequest.uri()).thenReturn("/api/nothello");
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();
Mockito.doAnswer(invocation -> {
async.complete();
return null;
}).when(response).end(anyString());
when(serverRequest.response()).thenReturn(response);
router.accept(serverRequest);
async.await();
verify(response, times(1)).setStatusCode(404);
verify(response, times(1)).end(anyString());
}
示例2: test404Internal
import io.vertx.ext.unit.Async; //导入方法依赖的package包/类
@Test
public void test404Internal(final TestContext testContext) throws Exception {
final Router router = Router.router(rule.vertx());
final JaxRsRouter jaxRsRouter = new JaxRsRouter();
final SpringJaxRsHandler handler = new SpringJaxRsHandler(MyApp.class);
jaxRsRouter.register(MyApp.class, router, handler, handler);
final HttpServerRequest serverRequest = mock(HttpServerRequest.class);
when(serverRequest.absoluteURI()).thenReturn("http://test.trajano.net/api/hello/404");
when(serverRequest.path()).thenReturn("/api/hello/404");
when(serverRequest.uri()).thenReturn("/api/hello/404");
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.await();
verify(response, times(1)).setStatusCode(404);
}
示例3: testFailure
import io.vertx.ext.unit.Async; //导入方法依赖的package包/类
@Test
public void testFailure(final TestContext testContext) throws Exception {
final HttpServerRequest serverRequest = mock(HttpServerRequest.class);
when(serverRequest.absoluteURI()).thenThrow(new RuntimeException("boom"));
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.await();
verify(response, times(1)).setStatusCode(500);
}
示例4: testHandler
import io.vertx.ext.unit.Async; //导入方法依赖的package包/类
@Test
public void testHandler(final TestContext testContext) throws Exception {
final Router router = Router.router(rule.vertx());
final JaxRsRouter jaxRsRouter = new JaxRsRouter();
final SpringJaxRsHandler handler = new SpringJaxRsHandler(MyApp.class);
jaxRsRouter.register(MyApp.class, router, handler, handler);
final HttpServerRequest serverRequest = mock(HttpServerRequest.class);
when(serverRequest.absoluteURI()).thenReturn("http://test.trajano.net/api/hello");
when(serverRequest.path()).thenReturn("/api/hello");
when(serverRequest.uri()).thenReturn("/api/hello");
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.write(Matchers.any(Buffer.class))).then(invocation -> {
try {
return response;
} finally {
async.complete();
}
});
when(serverRequest.response()).thenReturn(response);
router.accept(serverRequest);
async.await();
final ArgumentCaptor<Buffer> captor = ArgumentCaptor.forClass(Buffer.class);
verify(response, times(1)).setStatusCode(200);
verify(response, times(1)).setChunked(true);
verify(response, times(1)).write(captor.capture());
assertTrue(captor.getValue().toString().startsWith("Hello"));
}
示例5: annotate
import io.vertx.ext.unit.Async; //导入方法依赖的package包/类
@Test
public void annotate(TestContext ctx) throws Exception {
Async async = ctx.async();
client.annotate(new RequestParameters()
.setAnnotators(Arrays.asList("tokenize,ssplit,pos,ner,depparse,openie".split(",")))
.setText("Vert.x created by Tim Fox, maintain by Julien Viet"),
event -> {
if (event.succeeded()) {
ctx.assertFalse(event.result().isEmpty());
}
async.complete();
});
async.await();
}
示例6: tokensregex
import io.vertx.ext.unit.Async; //导入方法依赖的package包/类
@Test
public void tokensregex(TestContext ctx) throws Exception {
Async async = ctx.async();
client.tokensregex(new RequestParameters()
.setAnnotators(Arrays.asList("tokenize,ssplit,pos,ner,depparse,openie".split(",")))
.setPattern("[ner: PERSON]")
.setText("Vert.x created by Tim Fox, maintain by Julien Viet"),
event -> {
if (event.succeeded()) {
ctx.assertFalse(event.result().isEmpty());
}
async.complete();
});
async.await();
}
示例7: semgrex
import io.vertx.ext.unit.Async; //导入方法依赖的package包/类
@Test
public void semgrex(TestContext ctx) throws Exception {
Async async = ctx.async();
client.semgrex(new RequestParameters()
.setAnnotators(Arrays.asList("tokenize,ssplit,pos,ner,depparse,openie".split(",")))
.setPattern("{}=A <<nsubj {}=B")
.setText("Vert.x created by Tim Fox, maintain by Julien Viet"),
event -> {
if (event.succeeded()) {
ctx.assertFalse(event.result().isEmpty());
}
async.complete();
});
async.await();
}
示例8: testRunStandalone
import io.vertx.ext.unit.Async; //导入方法依赖的package包/类
@Test
public void testRunStandalone(TestContext ctx) {
Async async = ctx.async();
PgPool pool = PgClient.pool(new PgPoolOptions(options));
try {
pool.query("SELECT id, randomnumber from WORLD", ctx.asyncAssertSuccess(v -> {
async.complete();
}));
async.await(4000);
} finally {
pool.close();
}
}
示例9: await
import io.vertx.ext.unit.Async; //导入方法依赖的package包/类
protected final void await(@NotNull Consumer<Async> task) {
final Async latch = context.async();
task.accept(latch);
latch.await(TIMEOUT);
}