Hi
In light of the the route testkit module not having the JUnitTestRoute
class. I thought I would try to test using with JavaTestKit.
Test setup:
system = ActorSystem.create();
probe = new JavaTestKit(system);
webAPI = new WebAPI(actorRef);
webAPI.bindRoute("localhost", 8080, this.system);
materializer = ActorMaterializer.create(system);
The route:
public Future<Object> sendToActor(RechargeRequest request, ExecutionContext
ec) {
return Patterns.ask(apiActor, request, 3000);
}
public Future<RouteResult> asyncSendToActor(final RequestContext ctx,
RechargeRequest recharge) {
Mapper<Object, RouteResult> func = new Mapper<Object, RouteResult>() {
@Override
public RouteResult apply(Object parameter) {
return ctx.complete("Test");
}
};
return sendToActor(recharge, ctx.executionContext()).map(func, ctx.
executionContext());
}
@Override
public Route createRoute() {
RequestVal<RechargeRequest> requestRequestVal = RequestVals.entityAs(
Jackson.jsonAs(RechargeRequest.class));
return route(pathPrefix("recharge").route(
path("single").route(post(handleWithAsync1(requestRequestVal,
this::asyncSendToActor)
))));
}
The test case is as follows:
ObjectMapper mapper = new ObjectMapper();
String json = mapper.writeValueAsString(request);
HttpRequest httpRequest = HttpRequest.create()
.withUri("http://localhost:8080/recharge/single")
.withMethod(HttpMethods.POST)
.withEntity(MediaTypes.APPLICATION_JSON.toContentType(), json);
Http.get(system).singleRequest(httpRequest, materializer);
probe.expectMsgClass(RechargeRequest.class);
The probe never receives the message class sent to it. What is the
recommended way of sending a message from an http route to an actor ?
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ:
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.