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");
}
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);
}
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()));
}
Aggregations