Question

I have a Spring MVC application which internally uses Akka. One of the actors is invoking a REST service which has been mocked using MockRestServiceServer. When I run the test which calls the controller and then the interesting actor, the test passes even though an exception is internally thrown.

I see the following exception stack trace in the logs. Within the test case, I also have put in a Thread.sleep(5000) before verifying the mock server (mockRestServiceServer.verify()). I am wondering about why this exception is not being thrown to the TestNG framework and failing the test.

Any pointers or on how to fix this issue would be most appreciated! Thanks!

java.lang.AssertionError: Request content expected:<"{\"GET\":{\"user\":[\"some user id\"]}}\""> but was:<{"GET":{"user":["some user id"]}}">
at org.springframework.test.util.AssertionErrors.fail(AssertionErrors.java:60) ~[spring-test-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.test.util.AssertionErrors.assertEquals(AssertionErrors.java:89) ~[spring-test-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.test.web.client.match.ContentRequestMatchers$3.match(ContentRequestMatchers.java:94) ~[spring-test-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.test.web.client.RequestMatcherClientHttpRequest.executeInternal(RequestMatcherClientHttpRequest.java:71) ~[spring-test-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.mock.http.client.MockClientHttpRequest.execute(MockClientHttpRequest.java:90) ~[spring-test-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:484) ~[spring-web-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:461) ~[spring-web-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:410) ~[spring-web-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at com.some.company.akka.actor.adr.service.AdvDataRepoService.generateAndExecuteHttpRequest(AdvDataRepoService.java:118) ~[classes/:na]
at com.some.company.akka.actor.adr.service.AdvDataRepoService.updatePermissions(AdvDataRepoService.java:57) ~[classes/:na]
at com.some.company.akka.actor.adr.AdvDataRepoServiceActor.onReceive(AdvDataRepoServiceActor.java:35) ~[classes/:na]
at akka.actor.UntypedActor$$anonfun$receive$1.applyOrElse(UntypedActor.scala:167) ~[akka-actor_2.10-2.3-M2.jar:2.3-M2]
at akka.actor.Actor$class.aroundReceive(Actor.scala:467) ~[akka-actor_2.10-2.3-M2.jar:2.3-M2]
at akka.actor.UntypedActor.aroundReceive(UntypedActor.scala:97) ~[akka-actor_2.10-2.3-M2.jar:2.3-M2]
at akka.actor.ActorCell.receiveMessage(ActorCell.scala:491) [akka-actor_2.10-2.3-M2.jar:2.3-M2]
at akka.actor.ActorCell.invoke(ActorCell.scala:462) [akka-actor_2.10-2.3-M2.jar:2.3-M2]
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:237) [akka-actor_2.10-2.3-M2.jar:2.3-M2]
at akka.dispatch.Mailbox.run(Mailbox.scala:219) [akka-actor_2.10-2.3-M2.jar:2.3-M2]
at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:385) [akka-actor_2.10-2.3-M2.jar:2.3-M2]
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) [scala-library-2.10.3.jar:na]
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) [scala-library-2.10.3.jar:na]
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) [scala-library-2.10.3.jar:na]
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) [scala-library-2.10.3.jar:na]
Was it helpful?

Solution

Actors are executed asynchronously, on a different thread then from where you send messages to them. Therefore you cannot catch these exceptions in the sending code. This is by design: the only one who gets the exceptions is the actor’s supervisor.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top