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


Java TestContext.async方法代码示例

本文整理汇总了Java中io.vertx.ext.unit.TestContext.async方法的典型用法代码示例。如果您正苦于以下问题:Java TestContext.async方法的具体用法?Java TestContext.async怎么用?Java TestContext.async使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.vertx.ext.unit.TestContext的用法示例。


在下文中一共展示了TestContext.async方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testDisconnectAbruptly

import io.vertx.ext.unit.TestContext; //导入方法依赖的package包/类
@Test
public void testDisconnectAbruptly(TestContext ctx) {
  Async async = ctx.async();
  ProxyServer proxy = ProxyServer.create(vertx, options.getPort(), options.getHost());
  proxy.proxyHandler(conn -> {
    vertx.setTimer(200, id -> {
      conn.close();
    });
    conn.connect();
  });
  proxy.listen(8080, "localhost", ctx.asyncAssertSuccess(v1 -> {
    options.setPort(8080).setHost("localhost");
    connector.accept(ctx.asyncAssertSuccess(conn -> {
      conn.closeHandler(v2 -> {
        async.complete();
      });
    }));
  }));
}
 
开发者ID:vietj,项目名称:reactive-pg-client,代码行数:20,代码来源:PgConnectionTestBase.java

示例2: testSimpleRegEx

import io.vertx.ext.unit.TestContext; //导入方法依赖的package包/类
@Test
public void testSimpleRegEx(TestContext context) {

	// call and check response
	final Async async = context.async();

	client.getNow("/regEx/123", response -> {

		context.assertEquals(200, response.statusCode());

		response.handler(body -> {
			context.assertEquals("123", body.toString());
			async.complete();
		});
	});
}
 
开发者ID:zandero,项目名称:rest.vertx,代码行数:17,代码来源:RouteWithRegExTest.java

示例3: testCallback

import io.vertx.ext.unit.TestContext; //导入方法依赖的package包/类
@Test
public void testCallback(final TestContext testContext) throws Exception {
    final TestProfile expectedProfile = TestProfile.from(TEST_CREDENTIALS);
    when(webContext.getRequestParameter(Clients.DEFAULT_CLIENT_NAME_PARAMETER)).thenReturn(NAME);
    final Clients<AsyncClient<? extends Credentials, ? extends TestProfile>, AsyncAuthorizationGenerator<TestProfile>> clients = clientsWithOneIndirectClient();
    when(config.getClients()).thenReturn(clients);
    asyncCallbackLogic = new DefaultAsyncCallbackLogic<>(false, false, config, httpActionAdapter);
    final Async async = testContext.async();
    final CompletableFuture<Object> future = asyncCallbackLogic.perform(webContext, null);
    final CompletableFuture<Map<String, TestProfile>> profilesFuture = future.thenAccept(o -> {
        assertThat(o, is(nullValue()));
        assertThat(status.get(), is(302));
        assertThat(responseHeaders.get(LOCATION_HEADER), is(Pac4jConstants.DEFAULT_URL_VALUE));
        verify(sessionStore, never()).renewSession(any(AsyncWebContext.class));
    }).thenCompose((Void v) ->  webContext.getSessionStore().get(webContext, Pac4jConstants.USER_PROFILES));

    assertSuccessfulEvaluation(profilesFuture, profiles -> {
        assertThat(profiles.containsValue(expectedProfile), is(true));
        assertThat(profiles.size(), is(1));
    }, async);

}
 
开发者ID:millross,项目名称:pac4j-async,代码行数:23,代码来源:DefaultAsyncCallbackLogicTest.java

示例4: guiceCallInjectedRestTest2

import io.vertx.ext.unit.TestContext; //导入方法依赖的package包/类
@Test
public void guiceCallInjectedRestTest2(TestContext context) {

	startWith(new GuiceInjectionProvider(), context);

	final Async async = context.async();

	client.getNow("/injected/other", response -> {

		context.assertEquals(200, response.statusCode());

		response.handler(body -> {
			context.assertEquals("Oh yes I'm so dummy!", body.toString());
			async.complete();
		});
	});
}
 
开发者ID:zandero,项目名称:rest.vertx,代码行数:18,代码来源:InjectionProviderTest.java

示例5: testTransactionRollback

import io.vertx.ext.unit.TestContext; //导入方法依赖的package包/类
@Test
public void testTransactionRollback(TestContext ctx) {
  Async done = ctx.async();
  connector.accept(ctx.asyncAssertSuccess(conn -> {
    PgTransaction tx = conn.begin();
    AtomicInteger u1 = new AtomicInteger();
    AtomicInteger u2 = new AtomicInteger();
    conn.query("INSERT INTO TxTest (id) VALUES (3)", ctx.asyncAssertSuccess(res -> u1.addAndGet(res.updatedCount())));
    conn.query("INSERT INTO TxTest (id) VALUES (4)", ctx.asyncAssertSuccess(res -> u2.addAndGet(res.updatedCount())));
    tx.rollback(ctx.asyncAssertSuccess(v -> {
      ctx.assertEquals(1, u1.get());
      ctx.assertEquals(1, u2.get());
      conn.query("SELECT id FROM TxTest WHERE id=3 OR id=4", ctx.asyncAssertSuccess(result -> {
        ctx.assertEquals(0, result.size());
        done.complete();
      }));
    }));
  }));
}
 
开发者ID:vietj,项目名称:reactive-pg-client,代码行数:20,代码来源:PgConnectionTestBase.java

示例6: testPost

import io.vertx.ext.unit.TestContext; //导入方法依赖的package包/类
@Test
public void testPost(TestContext context) {
	Async async = context.async();
	getClient().post(port, "localhost", "/post").exceptionHandler(t -> context.fail(t)).handler(res -> {
		context.assertEquals(new BadRequest().getStatusCode(), res.statusCode(), "Incorrect response status");
		res.exceptionHandler(t -> context.fail(t)).bodyHandler(body -> {
			try {
				JsonObject o = body.toJsonObject();
				context.assertEquals(new BadRequest().getMessage(), o.getValue("message"));
			} catch (Exception e) {
				context.fail(e);
			}
			async.complete();
		});
	}).end("{}");
}
 
开发者ID:GreenfieldTech,项目名称:irked,代码行数:17,代码来源:TestMethodController.java

示例7: executeAsyncGetAllTest

import io.vertx.ext.unit.TestContext; //导入方法依赖的package包/类
private void executeAsyncGetAllTest(final TestContext testContext, final boolean fromSession,
                                    final BiConsumer<CompletableFuture<List<CommonProfile>>, Async> asyncAssertions) {
    final Async async = testContext.async();

    final CompletableFuture<List<CommonProfile>> future = profileManager.getAll(fromSession);

    asyncAssertions.accept(future, async);
}
 
开发者ID:millross,项目名称:pac4j-async,代码行数:9,代码来源:AsyncProfileManagerTest.java

示例8: testTx

import io.vertx.ext.unit.TestContext; //导入方法依赖的package包/类
@Test
public void testTx(TestContext ctx) {
  Async async = ctx.async();
  connector.accept(ctx.asyncAssertSuccess(conn -> {
    conn.query("BEGIN", ctx.asyncAssertSuccess(result1 -> {
      ctx.assertEquals(0, result1.size());
      ctx.assertNotNull(result1.iterator());
      conn.query("COMMIT", ctx.asyncAssertSuccess(result2 -> {
        ctx.assertEquals(0, result2.size());
        async.complete();
      }));
    }));
  }));
}
 
开发者ID:vietj,项目名称:reactive-pg-client,代码行数:15,代码来源:PgConnectionTestBase.java

示例9: testHttpActionExceptionBehaviour

import io.vertx.ext.unit.TestContext; //导入方法依赖的package包/类
@Test(timeout=1000, expected=HttpAction.class)
public void testHttpActionExceptionBehaviour(final TestContext testContext) throws Exception {
    final HttpAction action = HttpAction.status("Intentional http action", 200, webContext);
    when(extractor.extract(any(WebContext.class))).thenThrow(action);
    final Async async = testContext.async();
    final CompletableFuture<TestCredentials> credsFuture = AsyncCredentialsExtractor.fromNonBlocking(extractor).extract(null);
    assertSuccessfulEvaluation(credsFuture, creds -> {}, async);
}
 
开发者ID:millross,项目名称:pac4j-async,代码行数:9,代码来源:AsyncCredentialsExtractorTest.java

示例10: testParamChild

import io.vertx.ext.unit.TestContext; //导入方法依赖的package包/类
@Test
public void testParamChild(TestContext context) {
	Async async = context.async();
	getClient().get(port, "localhost", "/value/paramChild")
		.exceptionHandler(context::fail)
		.handler(compareBodyHandler("param child index", context, async)).end();
}
 
开发者ID:GreenfieldTech,项目名称:irked,代码行数:8,代码来源:TestMountController.java

示例11: testProfileInSessionAfter

import io.vertx.ext.unit.TestContext; //导入方法依赖的package包/类
private <T> void testProfileInSessionAfter(final CompletableFuture<T> initialSetupFuture,
                                           final Function<T, CompletableFuture<Void>> operation,
                                           final BiConsumer<CompletableFuture<Optional<CommonProfile>>, Async> assertions,
                                           final TestContext testContext) {
    final Async async = testContext.async();
    final CompletableFuture<Optional<CommonProfile>> profilesInSessionFuture = initialSetupFuture
            .thenCompose(operation)
            .thenCompose(v -> profileManager.get(true));
    assertions.accept(profilesInSessionFuture, async);

}
 
开发者ID:millross,项目名称:pac4j-async,代码行数:12,代码来源:AsyncProfileManagerTest.java

示例12: testMyApplication

import io.vertx.ext.unit.TestContext; //导入方法依赖的package包/类
@Test
public void testMyApplication(TestContext context) {
    final Async async = context.async();

    vertx.createHttpClient().getNow(8080, "localhost", "/",
        response ->
            response.handler(body -> {
                context.assertTrue(body.toString().contains("Hello"));
                async.complete();
            }));
}
 
开发者ID:cescoffier,项目名称:introduction-to-vert.x,代码行数:12,代码来源:MyFirstVerticleTest.java

示例13: testFromBlockingCredentialsExceptionBehaviour

import io.vertx.ext.unit.TestContext; //导入方法依赖的package包/类
@Test(timeout=1000, expected=CredentialsException.class)
public void testFromBlockingCredentialsExceptionBehaviour(final TestContext testContext) throws Exception {
    when(extractor.extract(any(WebContext.class))).thenThrow(new CredentialsException("Intentional credentials exception"));
    final Async async = testContext.async();
    final CompletableFuture<TestCredentials> credsFuture = AsyncCredentialsExtractor.fromBlocking(extractor).extract(webContext);
    assertSuccessfulEvaluation(credsFuture, creds -> {}, async);
}
 
开发者ID:millross,项目名称:pac4j-async,代码行数:8,代码来源:AsyncCredentialsExtractorTest.java

示例14: crud_operations

import io.vertx.ext.unit.TestContext; //导入方法依赖的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);
}
 
开发者ID:vert-x3,项目名称:vertx-guide-for-java-devs,代码行数:34,代码来源:WikiDatabaseVerticleTest.java

示例15: testStreamQueryPauseInBatch

import io.vertx.ext.unit.TestContext; //导入方法依赖的package包/类
@Test
public void testStreamQueryPauseInBatch(TestContext ctx) {
  Async async = ctx.async();
  PgClient.connect(vertx, options(), ctx.asyncAssertSuccess(conn -> {
    conn.query("BEGIN", ctx.asyncAssertSuccess(begin -> {
      conn.prepare("SELECT * FROM Fortune", ctx.asyncAssertSuccess(ps -> {
        PgStream<Row> stream = ps.createStream(4, Tuple.tuple());
        List<Tuple> rows = new ArrayList<>();
        AtomicInteger ended = new AtomicInteger();
        stream.endHandler(v -> {
          ctx.assertEquals(0, ended.getAndIncrement());
          ctx.assertEquals(12, rows.size());
          async.complete();
        });
        stream.handler(tuple -> {
          rows.add(tuple);
          if (rows.size() == 2) {
            stream.pause();
            vertx.setTimer(100, v -> {
              stream.resume();
            });
          }
        });
      }));
    }));
  }));
}
 
开发者ID:vietj,项目名称:reactive-pg-client,代码行数:28,代码来源:PreparedStatementTestBase.java


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