Search in sources :

Example 61 with XFuture

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

the class TestAsyncWebServer method testCompletePromiseOnAnotherThread.

@Test
public void testCompletePromiseOnAnotherThread() {
    XFuture<Integer> future = new XFuture<Integer>();
    mockNotFoundLib.queueFuture(future);
    HttpFullRequest req = Requests.createRequest(KnownHttpMethod.GET, "/asyncSuccessRoute");
    XFuture<HttpFullResponse> respFuture = http11Socket.send(req);
    // no response yet...
    Assert.assertFalse(respFuture.isDone());
    // now have the server complete processing
    future.complete(5);
    ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
    response.assertStatusCode(KnownStatusCode.HTTP_200_OK);
    response.assertContains("Hi Dean Hiller, This is a page");
}
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) PrivateWebserverForTest(org.webpieces.webserver.PrivateWebserverForTest) Test(org.junit.Test) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest)

Example 62 with XFuture

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

the class TestAsynchronousErrors method testWebAppHasBugRenders500Route.

/**
 * This tests bug in your webapp "/another" route, you could also test you have a bug in that route AND a bug in your internal
 * server route as well!!!
 */
@Test
public void testWebAppHasBugRenders500Route() {
    XFuture<Integer> future = new XFuture<Integer>();
    mockNotFoundLib.queueFuture(future);
    HttpFullRequest req = Requests.createRequest(KnownHttpMethod.GET, "/");
    XFuture<HttpFullResponse> respFuture = http11Socket.send(req);
    Assert.assertFalse(respFuture.isDone());
    future.completeExceptionally(new RuntimeException("test async exception"));
    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)

Example 63 with XFuture

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

the class TestAsynchronousErrors method testWebAppHasBugAndRender500HasBug.

@Test
public void testWebAppHasBugAndRender500HasBug() {
    XFuture<Integer> future = new XFuture<Integer>();
    mockNotFoundLib.queueFuture(future);
    XFuture<Integer> future2 = new XFuture<Integer>();
    mockInternalSvrErrorLib.queueFuture(future2);
    HttpFullRequest req = Requests.createRequest(KnownHttpMethod.GET, "/");
    XFuture<HttpFullResponse> respFuture = http11Socket.send(req);
    Assert.assertFalse(respFuture.isDone());
    future.completeExceptionally(new RuntimeException("fail notfound route"));
    Assert.assertFalse(respFuture.isDone());
    future2.completeExceptionally(new RuntimeException("fail internal server error route"));
    ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
    response.assertStatusCode(KnownStatusCode.HTTP_500_INTERNAL_SVR_ERROR);
    response.assertContains("There was a bug in the developers application or webpieces server");
}
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 64 with XFuture

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

the class TestAsynchronousErrors method testCompletePromiseAnotherThreadAndPageParamMissing.

@Test
public void testCompletePromiseAnotherThreadAndPageParamMissing() {
    XFuture<Integer> future = new XFuture<Integer>();
    mockNotFoundLib.queueFuture(future);
    HttpFullRequest req = Requests.createRequest(KnownHttpMethod.GET, "/asyncFailRoute");
    XFuture<HttpFullResponse> respFuture = http11Socket.send(req);
    // now have the server complete processing
    future.complete(5);
    ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
    response.assertStatusCode(KnownStatusCode.HTTP_500_INTERNAL_SVR_ERROR);
    response.assertContains("There was a bug in our software");
}
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 65 with XFuture

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

the class TestAsynchronousErrors method testNotFoundThrowsThenInternalSvrErrorHandlerThrows.

@Test
public void testNotFoundThrowsThenInternalSvrErrorHandlerThrows() {
    XFuture<Integer> future = new XFuture<Integer>();
    mockNotFoundLib.queueFuture(future);
    XFuture<Integer> future2 = new XFuture<Integer>();
    mockInternalSvrErrorLib.queueFuture(future2);
    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("fail notfound route"));
    Assert.assertFalse(respFuture.isDone());
    future2.completeExceptionally(new RuntimeException("fail internal server error route"));
    ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
    response.assertStatusCode(KnownStatusCode.HTTP_500_INTERNAL_SVR_ERROR);
    response.assertContains("There was a bug in the developers application or webpieces server");
}
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