當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。