本文整理汇总了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();
});
}));
}));
}
示例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();
});
});
}
示例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);
}
示例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();
});
});
}
示例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();
}));
}));
}));
}
示例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("{}");
}
示例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);
}
示例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();
}));
}));
}));
}
示例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);
}
示例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();
}
示例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);
}
示例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();
}));
}
示例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);
}
示例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);
}
示例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();
});
}
});
}));
}));
}));
}