Search in sources :

Example 1 with FetchValueResponse

use of webpiecesxxxxxpackage.service.FetchValueResponse in project webpieces by deanhiller.

the class TestLesson3Errors method testRemoteSystemDown.

/**
 * Tests a remote asynchronous system fails and a 500 error page is rendered
 */
@Test
public void testRemoteSystemDown() {
    XFuture<FetchValueResponse> future = new XFuture<FetchValueResponse>();
    mockRemote.addValueToReturn(future);
    HttpFullRequest req = TestLesson2Html.createRequest("/async");
    XFuture<HttpFullResponse> respFuture = http11Socket.send(req);
    Assert.assertFalse(respFuture.isDone());
    // notice that the thread returned but there is no response back to browser yet such that thread can do more work.
    // next, simulate remote system returning a value..
    future.completeExceptionally(new RuntimeException("complete future with exception"));
    ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
    response.assertStatusCode(KnownStatusCode.HTTP_500_INTERNAL_SVR_ERROR);
    response.assertContains("You encountered a Bug in our web 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) FetchValueResponse(webpiecesxxxxxpackage.service.FetchValueResponse) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) Test(org.junit.Test)

Example 2 with FetchValueResponse

use of webpiecesxxxxxpackage.service.FetchValueResponse in project webpieces by deanhiller.

the class TestLesson2Html method testAsyncControllerAndRemoteSystem.

/**
 * It is highly suggested you step through this test in debug mode to understand the description below...
 *
 * This is a single threaded test that actually allows the webserver thread to return back to the test before
 * the response comes.  (in production the thread would process other requests while waiting for remote system response).
 * Then the test simulates the response coming in from remote system and makes sure we send a response back
 * to the ResponseSender.  In implementations like this with a remote system, one can avoid holding threads up
 * and allow them to keep working while waiting for a response from the remote system.
 */
@Test
public void testAsyncControllerAndRemoteSystem() {
    XFuture<FetchValueResponse> future = new XFuture<FetchValueResponse>();
    mockRemote.addValueToReturn(future);
    HttpFullRequest req = createRequest("/async");
    XFuture<HttpFullResponse> respFuture = http11Socket.send(req);
    Assert.assertFalse(respFuture.isDone());
    // notice that the thread returned but there is no response back to browser yet such that thread can do more work.
    // next, simulate remote system returning a value..
    int value = 85;
    future.complete(new FetchValueResponse(85));
    ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
    response.assertStatusCode(KnownStatusCode.HTTP_200_OK);
    response.assertContains("This is a page with value=" + value);
}
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) FetchValueResponse(webpiecesxxxxxpackage.service.FetchValueResponse) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) Test(org.junit.Test)

Example 3 with FetchValueResponse

use of webpiecesxxxxxpackage.service.FetchValueResponse in project webpieces by deanhiller.

the class MainController method myAsyncMethod.

public XFuture<Action> myAsyncMethod() {
    FetchValueRequest request = new FetchValueRequest("dean", 21);
    XFuture<FetchValueResponse> remoteValue = service.fetchValue(request);
    // fetchRemoteValue("dean", 21);
    return remoteValue.thenApply(s -> convertToAction(s.getNum()));
}
Also used : FetchValueRequest(webpiecesxxxxxpackage.service.FetchValueRequest) FetchValueResponse(webpiecesxxxxxpackage.service.FetchValueResponse)

Aggregations

FetchValueResponse (webpiecesxxxxxpackage.service.FetchValueResponse)3 Test (org.junit.Test)2 HttpFullRequest (org.webpieces.httpclient11.api.HttpFullRequest)2 HttpFullResponse (org.webpieces.httpclient11.api.HttpFullResponse)2 XFuture (org.webpieces.util.futures.XFuture)2 AbstractWebpiecesTest (org.webpieces.webserver.test.AbstractWebpiecesTest)2 ResponseWrapper (org.webpieces.webserver.test.ResponseWrapper)2 FetchValueRequest (webpiecesxxxxxpackage.service.FetchValueRequest)1