当前位置: 首页>>代码示例>>Java>>正文


Java Async.await方法代码示例

本文整理汇总了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());
}
 
开发者ID:trajano,项目名称:app-ms,代码行数:35,代码来源:SpringJaxRsHandlerTest.java

示例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);
}
 
开发者ID:trajano,项目名称:app-ms,代码行数:37,代码来源:SpringJaxRsHandlerTest.java

示例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);
}
 
开发者ID:trajano,项目名称:app-ms,代码行数:32,代码来源:SpringJaxRsHandlerTest.java

示例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"));
}
 
开发者ID:trajano,项目名称:app-ms,代码行数:41,代码来源:SpringJaxRsHandlerTest.java

示例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();
}
 
开发者ID:shikeio,项目名称:vertx-corenlp-client,代码行数:15,代码来源:CoreNLPClientTest.java

示例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();
}
 
开发者ID:shikeio,项目名称:vertx-corenlp-client,代码行数:16,代码来源:CoreNLPClientTest.java

示例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();
}
 
开发者ID:shikeio,项目名称:vertx-corenlp-client,代码行数:16,代码来源:CoreNLPClientTest.java

示例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();
  }
}
 
开发者ID:vietj,项目名称:reactive-pg-client,代码行数:14,代码来源:PgPoolTest.java

示例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);
}
 
开发者ID:nolequen,项目名称:vertx-prometheus-metrics,代码行数:6,代码来源:PrometheusMetricsTestCase.java


注:本文中的io.vertx.ext.unit.Async.await方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。