Re: [akka-user] Java : How should Futures be handled when Unit testing?
Does this help? http://christopher-batey.blogspot.se/2014/02/testing-scala-futures-with-scalatest-20.html On Thu, Apr 9, 2015 at 1:27 PM, Adam Daines dainesa...@gmail.com wrote: Hi all, I've got a question in relation to the unit testing of a piece of non actor code that produces a FutureActorRef via performing an actorSelection().resolveOne on the ActorSystem. Within the Future.onFailure() a value is being set that I would like to test but the Future is making use of the ActorSystem.dispatcher() which is therefore causing asynchronicity issues when attempting to Assert that the value has been set as expected. I am currently performing a Thread.sleep() within the Unit test to provide enough time for the value to have been set but this is far from ideal! What is the best way to go about testing this type of code without having to sleep and wait? Is it possible to override the dispatcher that the ActorSystem returns with the CallingThreadDispatcher? Thanks. -- 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 akka-user+unsubscr...@googlegroups.com. To post to this group, send email to akka-user@googlegroups.com. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout. -- Cheers, √ -- 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 akka-user+unsubscr...@googlegroups.com. To post to this group, send email to akka-user@googlegroups.com. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.
Re: [akka-user] Java : How should Futures be handled when Unit testing?
On Thu, Apr 9, 2015 at 1:33 PM, Viktor Klang viktor.kl...@gmail.com wrote: Does this help? http://christopher-batey.blogspot.se/2014/02/testing-scala-futures-with-scalatest-20.html That is for scala though. We usually use scala.concurrent.Await which can be used like this assert(Await.result(myFuture, timeoutDuration) == xyz) This will block the test and wait until the future becomes ready. If the future completes then the assertion will run. If the future fails, then Await.result() will throw the exception. If the future does not complete during the time defined in timeoutDuration, then it will throw A TimeoutException. -Endre On Thu, Apr 9, 2015 at 1:27 PM, Adam Daines dainesa...@gmail.com wrote: Hi all, I've got a question in relation to the unit testing of a piece of non actor code that produces a FutureActorRef via performing an actorSelection().resolveOne on the ActorSystem. Within the Future.onFailure() a value is being set that I would like to test but the Future is making use of the ActorSystem.dispatcher() which is therefore causing asynchronicity issues when attempting to Assert that the value has been set as expected. I am currently performing a Thread.sleep() within the Unit test to provide enough time for the value to have been set but this is far from ideal! What is the best way to go about testing this type of code without having to sleep and wait? Is it possible to override the dispatcher that the ActorSystem returns with the CallingThreadDispatcher? Thanks. -- 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 akka-user+unsubscr...@googlegroups.com. To post to this group, send email to akka-user@googlegroups.com. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout. -- Cheers, √ -- 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 akka-user+unsubscr...@googlegroups.com. To post to this group, send email to akka-user@googlegroups.com. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout. -- Akka Team Typesafe - Reactive apps on the JVM Blog: letitcrash.com Twitter: @akkateam -- 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 akka-user+unsubscr...@googlegroups.com. To post to this group, send email to akka-user@googlegroups.com. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.
Re: [akka-user] Java : How should Futures be handled when Unit testing?
Thank you both for the quick and helpful responses! Our issue is now resolved :) Thanks. On Thursday, April 9, 2015 at 1:01:24 PM UTC+1, √ wrote: Ouch, nice catch, now we've covered both the question and the alternative (Scala) :) On Thu, Apr 9, 2015 at 1:59 PM, Akka Team akka.o...@gmail.com javascript: wrote: On Thu, Apr 9, 2015 at 1:33 PM, Viktor Klang viktor...@gmail.com javascript: wrote: Does this help? http://christopher-batey.blogspot.se/2014/02/testing-scala-futures-with-scalatest-20.html That is for scala though. We usually use scala.concurrent.Await which can be used like this assert(Await.result(myFuture, timeoutDuration) == xyz) This will block the test and wait until the future becomes ready. If the future completes then the assertion will run. If the future fails, then Await.result() will throw the exception. If the future does not complete during the time defined in timeoutDuration, then it will throw A TimeoutException. -Endre On Thu, Apr 9, 2015 at 1:27 PM, Adam Daines daine...@gmail.com javascript: wrote: Hi all, I've got a question in relation to the unit testing of a piece of non actor code that produces a FutureActorRef via performing an actorSelection().resolveOne on the ActorSystem. Within the Future.onFailure() a value is being set that I would like to test but the Future is making use of the ActorSystem.dispatcher() which is therefore causing asynchronicity issues when attempting to Assert that the value has been set as expected. I am currently performing a Thread.sleep() within the Unit test to provide enough time for the value to have been set but this is far from ideal! What is the best way to go about testing this type of code without having to sleep and wait? Is it possible to override the dispatcher that the ActorSystem returns with the CallingThreadDispatcher? Thanks. -- 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 akka-user+...@googlegroups.com javascript:. To post to this group, send email to akka...@googlegroups.com javascript:. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout. -- Cheers, √ -- 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 akka-user+...@googlegroups.com javascript:. To post to this group, send email to akka...@googlegroups.com javascript:. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout. -- Akka Team Typesafe - Reactive apps on the JVM Blog: letitcrash.com Twitter: @akkateam -- 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 akka-user+...@googlegroups.com javascript:. To post to this group, send email to akka...@googlegroups.com javascript:. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout. -- Cheers, √ -- 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 akka-user+unsubscr...@googlegroups.com. To post to this group, send email to akka-user@googlegroups.com. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.
Re: [akka-user] Java : How should Futures be handled when Unit testing?
Hi Adam, I generally recommend against using onComplete, onSuccess and onFailure for that reason, instead use map/flatMap/andThen/recover/recoverWith/transform On Thu, Apr 9, 2015 at 4:14 PM, Adam Daines dainesa...@gmail.com wrote: Hi again, At first it had appeared that the issue was fully resolved but the test I had written began to fail again intermittently. It appears that taking the approach Endre suggested does not quite work as I had expected. It appears that the Await triggers and unblocks at the moment that the Future gets completed which is before the .onSuccess .onFailure have actually run. In my use case the variable (which is a deferredResult) is actually set inside the .onFailure, therefore I cannot do an assertion on it until after the .onFailure has finished running. Any further assistance would be much appreciated. Thanks. On Thursday, April 9, 2015 at 1:46:22 PM UTC+1, Adam Daines wrote: Thank you both for the quick and helpful responses! Our issue is now resolved :) Thanks. On Thursday, April 9, 2015 at 1:01:24 PM UTC+1, √ wrote: Ouch, nice catch, now we've covered both the question and the alternative (Scala) :) On Thu, Apr 9, 2015 at 1:59 PM, Akka Team akka.o...@gmail.com wrote: On Thu, Apr 9, 2015 at 1:33 PM, Viktor Klang viktor...@gmail.com wrote: Does this help? http://christopher-batey.blogspot.se/2014/02/testing- scala-futures-with-scalatest-20.html That is for scala though. We usually use scala.concurrent.Await which can be used like this assert(Await.result(myFuture, timeoutDuration) == xyz) This will block the test and wait until the future becomes ready. If the future completes then the assertion will run. If the future fails, then Await.result() will throw the exception. If the future does not complete during the time defined in timeoutDuration, then it will throw A TimeoutException. -Endre On Thu, Apr 9, 2015 at 1:27 PM, Adam Daines daine...@gmail.com wrote: Hi all, I've got a question in relation to the unit testing of a piece of non actor code that produces a FutureActorRef via performing an actorSelection().resolveOne on the ActorSystem. Within the Future.onFailure() a value is being set that I would like to test but the Future is making use of the ActorSystem.dispatcher() which is therefore causing asynchronicity issues when attempting to Assert that the value has been set as expected. I am currently performing a Thread.sleep() within the Unit test to provide enough time for the value to have been set but this is far from ideal! What is the best way to go about testing this type of code without having to sleep and wait? Is it possible to override the dispatcher that the ActorSystem returns with the CallingThreadDispatcher? Thanks. -- 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 akka-user+...@googlegroups.com. To post to this group, send email to akka...@googlegroups.com. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout. -- Cheers, √ -- 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 akka-user+...@googlegroups.com. To post to this group, send email to akka...@googlegroups.com. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout. -- Akka Team Typesafe - Reactive apps on the JVM Blog: letitcrash.com Twitter: @akkateam -- 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 akka-user+...@googlegroups.com. To post to this group, send email to akka...@googlegroups.com. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout. -- Cheers, √ -- 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
[akka-user] Java : How should Futures be handled when Unit testing?
Hi all, I've got a question in relation to the unit testing of a piece of non actor code that produces a FutureActorRef via performing an actorSelection().resolveOne on the ActorSystem. Within the Future.onFailure() a value is being set that I would like to test but the Future is making use of the ActorSystem.dispatcher() which is therefore causing asynchronicity issues when attempting to Assert that the value has been set as expected. I am currently performing a Thread.sleep() within the Unit test to provide enough time for the value to have been set but this is far from ideal! What is the best way to go about testing this type of code without having to sleep and wait? Is it possible to override the dispatcher that the ActorSystem returns with the CallingThreadDispatcher? Thanks. -- 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 akka-user+unsubscr...@googlegroups.com. To post to this group, send email to akka-user@googlegroups.com. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.
Re: [akka-user] Java : How should Futures be handled when Unit testing?
Ouch, nice catch, now we've covered both the question and the alternative (Scala) :) On Thu, Apr 9, 2015 at 1:59 PM, Akka Team akka.offic...@gmail.com wrote: On Thu, Apr 9, 2015 at 1:33 PM, Viktor Klang viktor.kl...@gmail.com wrote: Does this help? http://christopher-batey.blogspot.se/2014/02/testing-scala-futures-with-scalatest-20.html That is for scala though. We usually use scala.concurrent.Await which can be used like this assert(Await.result(myFuture, timeoutDuration) == xyz) This will block the test and wait until the future becomes ready. If the future completes then the assertion will run. If the future fails, then Await.result() will throw the exception. If the future does not complete during the time defined in timeoutDuration, then it will throw A TimeoutException. -Endre On Thu, Apr 9, 2015 at 1:27 PM, Adam Daines dainesa...@gmail.com wrote: Hi all, I've got a question in relation to the unit testing of a piece of non actor code that produces a FutureActorRef via performing an actorSelection().resolveOne on the ActorSystem. Within the Future.onFailure() a value is being set that I would like to test but the Future is making use of the ActorSystem.dispatcher() which is therefore causing asynchronicity issues when attempting to Assert that the value has been set as expected. I am currently performing a Thread.sleep() within the Unit test to provide enough time for the value to have been set but this is far from ideal! What is the best way to go about testing this type of code without having to sleep and wait? Is it possible to override the dispatcher that the ActorSystem returns with the CallingThreadDispatcher? Thanks. -- 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 akka-user+unsubscr...@googlegroups.com. To post to this group, send email to akka-user@googlegroups.com. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout. -- Cheers, √ -- 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 akka-user+unsubscr...@googlegroups.com. To post to this group, send email to akka-user@googlegroups.com. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout. -- Akka Team Typesafe - Reactive apps on the JVM Blog: letitcrash.com Twitter: @akkateam -- 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 akka-user+unsubscr...@googlegroups.com. To post to this group, send email to akka-user@googlegroups.com. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout. -- Cheers, √ -- 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 akka-user+unsubscr...@googlegroups.com. To post to this group, send email to akka-user@googlegroups.com. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.
Re: [akka-user] Java : How should Futures be handled when Unit testing?
Hi again, At first it had appeared that the issue was fully resolved but the test I had written began to fail again intermittently. It appears that taking the approach Endre suggested does not quite work as I had expected. It appears that the Await triggers and unblocks at the moment that the Future gets completed which is before the .onSuccess .onFailure have actually run. In my use case the variable (which is a deferredResult) is actually set inside the .onFailure, therefore I cannot do an assertion on it until after the .onFailure has finished running. Any further assistance would be much appreciated. Thanks. On Thursday, April 9, 2015 at 1:46:22 PM UTC+1, Adam Daines wrote: Thank you both for the quick and helpful responses! Our issue is now resolved :) Thanks. On Thursday, April 9, 2015 at 1:01:24 PM UTC+1, √ wrote: Ouch, nice catch, now we've covered both the question and the alternative (Scala) :) On Thu, Apr 9, 2015 at 1:59 PM, Akka Team akka.o...@gmail.com wrote: On Thu, Apr 9, 2015 at 1:33 PM, Viktor Klang viktor...@gmail.com wrote: Does this help? http://christopher-batey.blogspot.se/2014/02/testing-scala-futures-with-scalatest-20.html That is for scala though. We usually use scala.concurrent.Await which can be used like this assert(Await.result(myFuture, timeoutDuration) == xyz) This will block the test and wait until the future becomes ready. If the future completes then the assertion will run. If the future fails, then Await.result() will throw the exception. If the future does not complete during the time defined in timeoutDuration, then it will throw A TimeoutException. -Endre On Thu, Apr 9, 2015 at 1:27 PM, Adam Daines daine...@gmail.com wrote: Hi all, I've got a question in relation to the unit testing of a piece of non actor code that produces a FutureActorRef via performing an actorSelection().resolveOne on the ActorSystem. Within the Future.onFailure() a value is being set that I would like to test but the Future is making use of the ActorSystem.dispatcher() which is therefore causing asynchronicity issues when attempting to Assert that the value has been set as expected. I am currently performing a Thread.sleep() within the Unit test to provide enough time for the value to have been set but this is far from ideal! What is the best way to go about testing this type of code without having to sleep and wait? Is it possible to override the dispatcher that the ActorSystem returns with the CallingThreadDispatcher? Thanks. -- 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 akka-user+...@googlegroups.com. To post to this group, send email to akka...@googlegroups.com. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout. -- Cheers, √ -- 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 akka-user+...@googlegroups.com. To post to this group, send email to akka...@googlegroups.com. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout. -- Akka Team Typesafe - Reactive apps on the JVM Blog: letitcrash.com Twitter: @akkateam -- 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 akka-user+...@googlegroups.com. To post to this group, send email to akka...@googlegroups.com. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout. -- Cheers, √ -- 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 akka-user+unsubscr...@googlegroups.com. To post to this group, send email to