Search in sources :

Example 6 with XFuture

use of org.webpieces.util.futures.XFuture in project webpieces by deanhiller.

the class BeansController method pageParamAsync.

public XFuture<Action> pageParamAsync() {
    XFuture<Action> future = new XFuture<>();
    RequestContext ctx = Current.getContext();
    executor.execute(new Runnable() {

        @Override
        public void run() {
            ctx.getFlash().put("testkey", "testflashvalue");
            future.complete(Actions.renderThis("user", "Dean Hiller"));
        }
    });
    return future;
}
Also used : Action(org.webpieces.router.api.controller.actions.Action) XFuture(org.webpieces.util.futures.XFuture) RequestContext(org.webpieces.ctx.api.RequestContext)

Example 7 with XFuture

use of org.webpieces.util.futures.XFuture in project webpieces by deanhiller.

the class TestAsynchronousErrors method testNotFoundHandlerThrowsNotFound.

@Test
public void testNotFoundHandlerThrowsNotFound() {
    XFuture<Integer> future = new XFuture<Integer>();
    mockNotFoundLib.queueFuture(future);
    HttpFullRequest req = Requests.createRequest(KnownHttpMethod.GET, "/route/that/does/not/exist");
    XFuture<HttpFullResponse> respFuture = http11Socket.send(req);
    Assert.assertFalse(respFuture.isDone());
    future.completeExceptionally(new NotFoundException("testing notfound from notfound route"));
    ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
    response.assertStatusCode(KnownStatusCode.HTTP_500_INTERNAL_SVR_ERROR);
    response.assertContains("There was a bug in our software...sorry about that");
}
Also used : HttpFullResponse(org.webpieces.httpclient11.api.HttpFullResponse) HttpFullRequest(org.webpieces.httpclient11.api.HttpFullRequest) XFuture(org.webpieces.util.futures.XFuture) NotFoundException(org.webpieces.http.exception.NotFoundException) ResponseWrapper(org.webpieces.webserver.test.ResponseWrapper) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) PrivateWebserverForTest(org.webpieces.webserver.PrivateWebserverForTest) Test(org.junit.Test)

Example 8 with XFuture

use of org.webpieces.util.futures.XFuture in project webpieces by deanhiller.

the class TestAsynchronousErrors method testWebappThrowsNotFound.

@Test
public void testWebappThrowsNotFound() {
    XFuture<Integer> future = new XFuture<Integer>();
    mockNotFoundLib.queueFuture(future);
    XFuture<Integer> future2 = new XFuture<Integer>();
    mockNotFoundLib.queueFuture(future2);
    HttpFullRequest req = Requests.createRequest(KnownHttpMethod.GET, "/throwNotFound");
    XFuture<HttpFullResponse> respFuture = http11Socket.send(req);
    Assert.assertFalse(respFuture.isDone());
    future.completeExceptionally(new NotFoundException("some async NotFound"));
    Assert.assertFalse(respFuture.isDone());
    future2.complete(55);
    ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
    response.assertStatusCode(KnownStatusCode.HTTP_404_NOTFOUND);
    response.assertContains("Your page was not found");
}
Also used : HttpFullResponse(org.webpieces.httpclient11.api.HttpFullResponse) HttpFullRequest(org.webpieces.httpclient11.api.HttpFullRequest) XFuture(org.webpieces.util.futures.XFuture) NotFoundException(org.webpieces.http.exception.NotFoundException) ResponseWrapper(org.webpieces.webserver.test.ResponseWrapper) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) PrivateWebserverForTest(org.webpieces.webserver.PrivateWebserverForTest) Test(org.junit.Test)

Example 9 with XFuture

use of org.webpieces.util.futures.XFuture in project webpieces by deanhiller.

the class TestAsynchronousErrors method testNotFoundRoute.

@Test
public void testNotFoundRoute() {
    // NOTE: This is adding future to the notFound route
    XFuture<Integer> future = new XFuture<Integer>();
    mockNotFoundLib.queueFuture(future);
    HttpFullRequest req = Requests.createRequest(KnownHttpMethod.GET, "/route/that/does/not/exist");
    XFuture<HttpFullResponse> respFuture = http11Socket.send(req);
    Assert.assertFalse(respFuture.isDone());
    // now resolve the future (which would be done on another thread)
    future.complete(22);
    ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
    response.assertStatusCode(KnownStatusCode.HTTP_404_NOTFOUND);
    response.assertContains("Your page was not found");
}
Also used : HttpFullResponse(org.webpieces.httpclient11.api.HttpFullResponse) HttpFullRequest(org.webpieces.httpclient11.api.HttpFullRequest) XFuture(org.webpieces.util.futures.XFuture) ResponseWrapper(org.webpieces.webserver.test.ResponseWrapper) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) PrivateWebserverForTest(org.webpieces.webserver.PrivateWebserverForTest) Test(org.junit.Test)

Example 10 with XFuture

use of org.webpieces.util.futures.XFuture in project webpieces by deanhiller.

the class TestAsynchronousErrors method testNotFoundThrowsException.

@Test
public void testNotFoundThrowsException() {
    XFuture<Integer> future = new XFuture<Integer>();
    mockNotFoundLib.queueFuture(future);
    HttpFullRequest req = Requests.createRequest(KnownHttpMethod.GET, "/route/that/does/not/exist");
    XFuture<HttpFullResponse> respFuture = http11Socket.send(req);
    Assert.assertFalse(respFuture.isDone());
    future.completeExceptionally(new RuntimeException("testing notfound from notfound route"));
    ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
    response.assertStatusCode(KnownStatusCode.HTTP_500_INTERNAL_SVR_ERROR);
    response.assertContains("There was a bug in our software...sorry about that");
}
Also used : HttpFullResponse(org.webpieces.httpclient11.api.HttpFullResponse) HttpFullRequest(org.webpieces.httpclient11.api.HttpFullRequest) XFuture(org.webpieces.util.futures.XFuture) ResponseWrapper(org.webpieces.webserver.test.ResponseWrapper) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) PrivateWebserverForTest(org.webpieces.webserver.PrivateWebserverForTest) Test(org.junit.Test)

Aggregations

XFuture (org.webpieces.util.futures.XFuture)71 Test (org.junit.Test)21 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)20 ByteBuffer (java.nio.ByteBuffer)16 Logger (org.slf4j.Logger)15 LoggerFactory (org.slf4j.LoggerFactory)15 ArrayList (java.util.ArrayList)14 List (java.util.List)13 Map (java.util.Map)12 DataWrapper (org.webpieces.data.api.DataWrapper)12 HttpFullRequest (org.webpieces.httpclient11.api.HttpFullRequest)12 HttpFullResponse (org.webpieces.httpclient11.api.HttpFullResponse)12 NotFoundException (org.webpieces.http.exception.NotFoundException)11 AbstractWebpiecesTest (org.webpieces.webserver.test.AbstractWebpiecesTest)11 ResponseWrapper (org.webpieces.webserver.test.ResponseWrapper)11 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)10 PrivateWebserverForTest (org.webpieces.webserver.PrivateWebserverForTest)10 StreamRef (com.webpieces.http2.api.streaming.StreamRef)9 RequestContext (org.webpieces.ctx.api.RequestContext)9 Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)8