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


Java Async类代码示例

本文整理汇总了Java中io.vertx.ext.unit.Async的典型用法代码示例。如果您正苦于以下问题:Java Async类的具体用法?Java Async怎么用?Java Async使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: testVXML

import io.vertx.ext.unit.Async; //导入依赖的package包/类
@Test
public void testVXML(TestContext context) throws Exception{
    final Async async = context.async();
    client.getAbs("http://39.108.96.23/static/test.xmlv")
            .send(ar ->{
                if(ar.succeeded()){
                    System.out.println(ar.result().getHeader("Content-Type"));
                    System.out.println(ar.result().bodyAsString());

                    ObjectMapper xmlMapper = new XmlMapper();
                    try {
                        XmlV xmlV = xmlMapper.readValue(ar.result().bodyAsString(), XmlV.class);
                    }catch (Exception e){
                        e.printStackTrace();
                    }
                }else{

                }
                async.complete();
            });
}
 
开发者ID:whitewoodcity,项目名称:xbrowser,代码行数:22,代码来源:MyTest.java

示例2: testLogoutNotPerformedBecauseLocalLogoutIsFalse

import io.vertx.ext.unit.Async; //导入依赖的package包/类
@Test
public void testLogoutNotPerformedBecauseLocalLogoutIsFalse(final TestContext testContext) {
    final Map<String, TestProfile> profiles = new HashMap<>();
    profiles.put(NAME, TestProfile.from(TEST_CREDENTIALS));
    final Clients<AsyncClient<? extends Credentials, ? extends TestProfile>, AsyncAuthorizationGenerator<TestProfile>> clients = new Clients<>();
    when(config.getClients()).thenReturn(clients);
    final Async async = testContext.async();
    asyncLogoutLogic = new DefaultAsyncLogoutLogic<>(config, httpActionAdapter, null, null, false, false, false);
    final CompletableFuture<Object> resultFuture = addProfilesToContext(profiles)
            .thenCompose(v -> asyncLogoutLogic.perform(webContext));

    assertSuccessfulEvaluation(assertProfilesCount(resultFuture, 1), o -> {
        assertThat(buffer.toString(), is(""));
        assertThat(status.get(), is(200));
    }, async);
}
 
开发者ID:millross,项目名称:pac4j-async,代码行数:17,代码来源:DefaultAsyncLogoutLogicTest.java

示例3: echoDummyJsonTest

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

	final Async async = context.async();
	Dummy dummy = new Dummy("one", "dude");
	String json = JsonUtils.toJson(dummy);

	client.get("/header/dummy", response -> {

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

		response.handler(body -> {
			context.assertEquals("one=dude", body.toString());
			async.complete();
		});
	}).putHeader("dummy", json).end();
}
 
开发者ID:zandero,项目名称:rest.vertx,代码行数:18,代码来源:RouteWithHeaderTest.java

示例4: testFromNonBlockingSynchronousFailureCheckedException

import io.vertx.ext.unit.Async; //导入依赖的package包/类
/**
 * Test for failing non-blocking synchronous computation with checked exception
 * @param testContext
 */
@Test(timeout = 1000, expected=CheckedIntentionalException.class)
public void testFromNonBlockingSynchronousFailureCheckedException(final TestContext testContext) {

    final Context context = rule.vertx().getOrCreateContext();
    final Async async = testContext.async();
    final int input = 1;

    AsynchronousComputationAdapter.fromNonBlocking(ExceptionSoftener.softenSupplier(() -> CheckedIntentionalException.throwException()))
            .thenAccept(i -> {
                context.runOnContext(x -> {
                    assertThat(i, is(input + 1));
                    async.complete();
                });
            });

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

示例5: executeTest

import io.vertx.ext.unit.Async; //导入依赖的package包/类
private void executeTest(TestContext context) {
	Async asyncRed = context.async();
	Async asyncBlue = context.async();
	
	getClient().get(port, "localhost", "/red").exceptionHandler(t -> context.fail(t)).handler(r -> {
		context.assertEquals(200, r.statusCode(), "Failed to call red");
		r.exceptionHandler(t -> context.fail(t)).bodyHandler(body -> {
			context.assertTrue(body.toString().contains("red"));
			asyncRed.complete();
		});
	}).end();
	
	getClient().get(port, "localhost", "/blue").exceptionHandler(t -> context.fail(t)).handler(r -> {
		context.assertEquals(200, r.statusCode(), "Failed to call blue");
		r.exceptionHandler(t -> context.fail(t)).bodyHandler(body -> {
			context.assertTrue(body.toString().contains("blue"));
			asyncBlue.complete();
		});
	}).end();
}
 
开发者ID:GreenfieldTech,项目名称:irked,代码行数:21,代码来源:TestMultipleEndpoints.java

示例6: testConsumesOne

import io.vertx.ext.unit.Async; //导入依赖的package包/类
@Test
public void testConsumesOne(TestContext context) {
	deployController(new TestConsumesOne(), context.asyncAssertSuccess(s -> {
		Async f1 = context.async();
		getClient().post(port, "localhost", "/one")
		.putHeader("Content-Type", "text/plain")
		.exceptionHandler(context::fail)
		.handler(compareBodyHandler(TestConsumesOne.message, context, f1)).end();
		
		Async f2 = context.async();
		f1.handler(r -> {
			getClient().post(port, "localhost", "/one")
			.putHeader("Content-Type", "text/xml")
			.exceptionHandler(context::fail)
			.handler(verifyMissHandler(context, f2)).end();
		});
	}));
}
 
开发者ID:GreenfieldTech,项目名称:irked,代码行数:19,代码来源:TestConsumes.java

示例7: testGetUserAuthorized

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

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

	client.get("/private/user", response -> {

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

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

示例8: executeTest

import io.vertx.ext.unit.Async; //导入依赖的package包/类
private void executeTest(TestContext context) {
	Async asyncRed = context.async();
	Async asyncBlue = context.async();
	
	getClient().post(port, "localhost", "/red").exceptionHandler(t -> context.fail(t)).handler(r -> {
		context.assertEquals(200, r.statusCode(), "Failed to call red");
		r.exceptionHandler(t -> context.fail(t)).bodyHandler(body -> {
			context.assertTrue(body.toString().contains("red"));
			asyncRed.complete();
		});
	}).end();
	
	getClient().post(port, "localhost", "/blue").exceptionHandler(t -> context.fail(t)).handler(r -> {
		context.assertEquals(200, r.statusCode(), "Failed to call blue");
		r.exceptionHandler(t -> context.fail(t)).bodyHandler(body -> {
			context.assertTrue(body.toString().contains("blue"));
			asyncBlue.complete();
		});
	}).end();
}
 
开发者ID:GreenfieldTech,项目名称:irked,代码行数:21,代码来源:TestRepeatables.java

示例9: singleProfileSaveNullProfileToNonEmptySession

import io.vertx.ext.unit.Async; //导入依赖的package包/类
@Test(timeout = 2000)
public void singleProfileSaveNullProfileToNonEmptySession(final TestContext testContext) {

    final TestProfile originalProfile = profile(GOOD_USERNAME2);
    final AsyncProfileManager<TestProfile, AsyncWebContext> profileManager = asyncProfileManager();

    final Async async = testContext.async();
    // Save the original profile to pre-setup the session
    profileManager.save(true, originalProfile, false)
            // Then save a null profile
            .thenCompose(v -> SINGLE_PROFILE_SAVE.saveProfile(profileManager, p -> true, null))
            // Check result of second save is false
            .thenCompose(checkSaveResultIs(false, profileManager))
            // And check that only original profile was stored
            .thenAccept(validateProfiles(equalTo(Arrays.asList(originalProfile)), async));
}
 
开发者ID:millross,项目名称:pac4j-async,代码行数:17,代码来源:AsyncSingleProfileSaveTest.java

示例10: throwDifferentExceptionTestOne

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

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

	client.getNow("/throw/multi/one", response -> { // throws NotAllowedException

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

		response.handler(body -> {
			context.assertEquals("Exception: HTTP 405 Method Not Allowed", body.toString()); // ExceptionWriter kicked in
			async.complete();
		});
	});
}
 
开发者ID:zandero,项目名称:rest.vertx,代码行数:17,代码来源:GlobalErrorHandlerTest.java

示例11: callMissingContext

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

	Router router = RestRouter.register(vertx, TestDefaultValueRest.class);
	vertx.createHttpServer()
	     .requestHandler(router::accept)
	     .listen(PORT);

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

	client.getNow("/default/context", response -> {

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

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

示例12: testAdd

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

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

	client.getNow("/query/add?one=1&two=2", response -> {

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

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

示例13: extendedContentTypeByMediaType

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

	TestReaderRest testRest = new TestReaderRest();

	Router router = RestRouter.register(vertx, testRest);

	vertx.createHttpServer()
	     .requestHandler(router::accept)
	     .listen(PORT);

	// register reader afterwards - should still work
	RestRouter.getReaders().register("application/json", DummyBodyReader.class);

	final Async async = context.async();
	client.post("/read/normal/dummy", response -> {

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

		response.handler(body -> {
			context.assertEquals("one=dummy", body.toString()); // returns sorted list of unique words
			async.complete();
		});
	}).putHeader("Content-Type", "application/json;charset=UTF-8")
	      .end(JsonUtils.toJson(new Dummy("one", "dummy")));
}
 
开发者ID:zandero,项目名称:rest.vertx,代码行数:27,代码来源:CustomReaderTest.java

示例14: testGetOtherUnAuthorized

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

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

	client.get("/private/other", response -> {

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

		response.handler(body -> {
			context.assertEquals("HTTP 401 Unauthorized", body.toString());
			async.complete();
		});
	}).putHeader("X-Token", "user").end();
}
 
开发者ID:zandero,项目名称:rest.vertx,代码行数:17,代码来源:RouteAuthorizationTest.java

示例15: pushContextTest

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

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

	client.getNow("/context/custom", response -> {

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

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


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