ExecutionApiResource { @POST @Timed @Consumes(MediaType.APPLICATION_JSON) public Response receiveTaskAndExecutionData(TaskExecutionMessage taskExecutionMessage) { TaskAndEvents msg = taskExecutionMessage.getAkkaMessage(); String routerName = taskExecutionMessage.getRouterName(); logger.info("Received taskExecutionMessage for stateMachine {} taskId {} taskName {}", msg.getStateMachineId(), msg.getTaskId(), msg.getTaskName()); try { ActorRef router = routerRegistry.getRouter(routerName); if (router != null) { logger.info("Sending msg to router: {} to execute state machine: {} task: {}", router.path(), msg.getStateMachineId(), msg.getTaskId()); router.tell(msg, ActorRef.noSender()); metricsClient.incCounter(new StringBuilder(). append("stateMachine."). append(msg.getStateMachineName()). append(".task."). append(msg.getTaskName()). append(".queueSize").toString()); } else { logger.error("Corresponding router {} for the execution message not found", taskExecutionMessage.getRouterName()); return Response.status(Response.Status.NOT_FOUND).entity("Akka router for this executionMessage not found").build(); } } catch (Exception ex) { logger.error("Unable to append the task to the Actor Queue {}", ex); return Response.serverError().entity(ex.getCause() != null ? ex.getCause().getMessage() : null).build(); } return Response.accepted().build(); } @Inject  ExecutionApiResource(RouterRegistry routerRegistry, MetricsClient metricsClient); @POST @Timed @Consumes(MediaType.APPLICATION_JSON) Response receiveTaskAndExecutionData(TaskExecutionMessage taskExecutionMessage);  }
@Test public void receiveExecutionMessage_shouldLookupRouterAndSendMessage() throws Exception { TaskExecutionMessage msg = TestUtils.getStandardTaskExecutionMessage(); when(routerRegistry.getRouter(msg.getRouterName())).thenReturn(mockActor); executionApiResource.receiveTaskAndExecutionData(msg); verify(routerRegistry, times(1)).getRouter(msg.getRouterName()); mockActor.underlyingActor().assertMessageReceived(msg.getAkkaMessage(), 1); verifyNoMoreInteractions(routerRegistry); }