[akka-user] Re: Usage of EventFilters in akka.testkit

2016-03-23 Thread Sven Hodapp
I've found a solution:

  EventFilter.info(pattern="log content", occurrences=1) intercept {
ac ! Consume(...)
  }


Regards,
Sven 

Am Dienstag, 22. März 2016 09:13:13 UTC+1 schrieb Sven Hodapp:
>
> Dear reader,
>
> I've seen in the documentation that it is possible to do assertions on 
> Akka log messages.
>
>
> http://doc.akka.io/docs/akka/current/scala/testing.html#Expecting_Log_Messages
>
>
> But the documentation is here a bit sparsely and doesn't explain how to do 
> "non-exception" assertions.
> You can give me an hint how to do it?
>
> My current code looks similar to this:
>
> class TheActorSpec(_system: ActorSystem)
>   extends TestKit(_system)
>   with ImplicitSender
>   with Matchers
>   with FlatSpecLike
>   with BeforeAndAfterAll {
>
>   def this() = this(ActorSystem("testsystem", ConfigFactory.parseString("""
>   akka.loggers = ["akka.testkit.TestEventListener"]
>   """)))
>
>   override def afterAll: Unit = {
> system.shutdown()
> system.awaitTermination(10.seconds)
>   }
>
>   "An Actor" should "be able to assert log messages" in {
> val ac = TestActorRef(Props[TheActor])
>
> ac ! Consume(...)
>
>  
>
> // Or with pattern="..."?
>
> EventFilter.info(message="the log content", 
> source=classOf[TheActor].getName, 
> occurrences=1).assertDone(1.second)  
>
>
>   }
>
> }
>
>
> But I get Stacktraces like "[...] java.lang.AssertionError: assertion 
> failed: 1 messages outstanding on InfoFilter [...]".
> Within TheActor Consume is log.info("the log content") called.
>
> Anybody an idea what's wrong or how to use EventFilter correctly?
>
> Thanks!
>
> Regards,
> Sven
>
>

-- 
>>>>>>>>>>  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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


[akka-user] Usage of EventFilters in akka.testkit

2016-03-22 Thread Sven Hodapp
Dear reader,

I've seen in the documentation that it is possible to do assertions on Akka 
log messages.

http://doc.akka.io/docs/akka/current/scala/testing.html#Expecting_Log_Messages


But the documentation is here a bit sparsely and doesn't explain how to do 
"non-exception" assertions.
You can give me an hint how to do it?

My current code looks similar to this:

class TheActorSpec(_system: ActorSystem)
  extends TestKit(_system)
  with ImplicitSender
  with Matchers
  with FlatSpecLike
  with BeforeAndAfterAll {

  def this() = this(ActorSystem("testsystem", ConfigFactory.parseString("""
  akka.loggers = ["akka.testkit.TestEventListener"]
  """)))

  override def afterAll: Unit = {
system.shutdown()
system.awaitTermination(10.seconds)
  }

  "An Actor" should "be able to assert log messages" in {
val ac = TestActorRef(Props[TheActor])

ac ! Consume(...)

 

// Or with pattern="..."?

EventFilter.info(message="the log content", 
source=classOf[TheActor].getName, 
occurrences=1).assertDone(1.second)  


  }

}


But I get Stacktraces like "[...] java.lang.AssertionError: assertion 
failed: 1 messages outstanding on InfoFilter [...]".
Within TheActor Consume is log.info("the log content") called.

Anybody an idea what's wrong or how to use EventFilter correctly?

Thanks!

Regards,
Sven

-- 
>>  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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.