Testing Actor without timers - scala

First of all, I am a beginner in Akka. I have an Actor (in Scala), which after receiving a message:
may not send anything
may send a message
may send multiple messages
I would like to test it, without the need for timers.
As far as I managed to dig, I can use the ? function of a TestActorRef, then wait for the Future. I don't know if this will time out if nothing is sent (I suspect it will, because it has an implicit timeout parameter), but it can't wait for multiple messages.
I can also use the recieve functions in the TestKit, however that will time out when it ensures that no message is received, which will make my tests slow and less robust.
What I need (or I think I need), is something that can send in messages, then run receive on the Actor until there are messages in its message queue, then check what it has sent out.
Can you tell me a way to achieve this, or point out what should I do in a different way?

You should use http://doc.akka.io/docs/akka/snapshot/scala/testing.html#Synchronous_Unit_Testing_with_TestActorRef
Documentation there is pretty good.

Related

Trigger something only after Resend Request is satisfied if exists with QuickFIX/J

Our system generates some messages (unsolicited cancel for example) it needs to send to the other party after a disconnect/connection lost, as soon as the connection recovers.
The problem is that we trigger sending those in onLogon(), but if there's a Resend Request that's too early and we had problems (maybe just because of how is implemented on the other end) when we had too many messages to send (hundreds).
I'm aware that ResendRequest may not come and it is impossible to figure that out without simply waiting, but what would be the best approach for us using QuickFIX/J to send our messages as soon as possible but after sequence numbers are synchronized?
EDIT: I'm trying to solve this using FIX 4.2. FIX 4.4 actually introduced http://www.onixs.biz/fix-dictionary/4.4/tagNum_789.html which would solve my problem (as long as the other party sends this optional tag too).
Thanks
My 10 cents is it sounds like you're trying to treat 2 scenarios in 1 go, and that's difficult. Do 1 thing at a time. For example, if it's your network that causes you to disconnect, before your client knows you've disconnected, your clients will send resend requests, right? Meanwhile, if a client disconnects but you don't then when they reconnect you gap fill. You've got to look carefully at the scenarios. Yes, a resend request may not come at all, it all depends how the client configures things their side. Maybe, per this question you want to send sequence resets because actually, the messages you're trying to send are quotes, right? I mean, what kind of messages are you trying to resend after a disco?

Is it possible to get POE::Component::IRC to receive events for its own PRIVMSGs?

I'm currently developing a bot with POE::Component::IRC whose job, amongst other things, is to post a notice to a list of channels on a schedule, for one week.
I can't seem to find a way to check that the message has been successfully sent to a channel though. The old Net::IRC package would fire a message received event for every message sent to a channel, including ones it itself had sent. POE seems not to do this - at least, the irc_public event is not firing when the bot's own message is published on the channel.
Is there a flag I can pass to the event handler to say "I'd really like to receive all messages please, even my own"? Or is there a way to do this with some sort of RAW event handler?
The IRC protocol does not echo your PRIVMSGs back to you, so you just have to trust that the server received your message and handled it the way it should.
If you just want to receive POE events for messages you send, there's a plug-in for that: POE::Component::IRC::Plugin::BotTraffic. It doesn't actually do anything to verify that the messages ever reach the server, though.
Fortunately, IRC runs on top of TCP, which provides guaranteed in-order delivery. Thus, as long as the connection doesn't drop or hang indefinitely, you can pretty safely assume that your commands will reach the server.
If you wanted to be absolutely sure, you could always follow your PRIVMSG with some command, such as TIME or PING, that you know the server will reply to; if it does, you'll know that it received your PRIVMSG too. Of course, even then there's still no guarantee that the server actually passed the message on to the intended recipient(s); things like netsplits do occur from time to time, and can cause messages to be dropped.

How is the behaviour of this Actor?

I am trying to understand the IO provided by akka. I started another question for this issue.
I found a simple example on how to use akka IO. I reimplemented it and started it. Now I am wondering why only the first message of the session is printed.
Can somebody please explain what state(socket)(Chunk(bytes)) is doing and how I could sent a message to another Actor of the ActorSystem instead?
Edit
I figured out, that the actor just takes a single input and process it by just printing it to the console. That leads me to another question: How can I make the actor take multiple inputs and process them? I connected to the server via putty and if I hit enter one time it processes the input as expected, but if I send another line of input it only stores the input. Where do I have to run flatMap, so it processes the next line of input? I tried it inside of the Read(socket, bytes) case, but it didn't work.
The example you are trying to understand is a bit more advanced, mainly because it is dealing with socket based communication. If you are actually interested in that kind of stuff, I suggest you read the documentation where the example from the blog seems to originate from.
In any case, before you do that, a good read would be Getting Started Tutorial which explains the fundamentals of Akka actors and gives you some actors to play with.

How does Play recognize a particular websocket message?

I am looking at the websocket-chat example. It unveils much, but I still cannot get something. I understand how messages are received, processed and sent on the web page side.
However, Play captures websocket messages by means of the receive method of an Akka actor. In the websocket-chat, there are several cases in this method, but I don't get, how does it know which websocket message should be mapped to which case. In fact, I don't understand the path that a websocket message follows upon entering Play's domain, how is it processed and how can different message types/kinds be sent from the webpage.
I have not find any info or sources related to this. Could please someone explain this or point to some kind of a good reference?
UPDATE:
The link to the original example.
The receive method from the sample doesn't have any link to the Play Websocket API. This receive method comes from the Akka library.
The Websockets events are managed through an Iteratee, which create and send a Talk message to the Actor system.
Simply put, it allows to have a highly scalable system (non-blocking), by sending messages between "workers".
So I suggest that you take a look at the Actor model in the Akka library.

Distributed Computing: Asynchronous Receive

If I have a receive primitive where I simply receive a message from a specified sender and I have a receive-all primitive where I receive from any sender, how can this be extended for real-time applications?
This is a question in some course notes I have that I never noticed before :). Any ideas?
An asynchronous receive is a non-blocking receive.
My idea is that we can somehow poll the sender every now and again to check that no messages are getting lost??... I'm not sure. Any ideas welcomed :).
Solution is to use timeouts: Messages can be lost in asynchronous communication so if we are left waiting on a message for too long then we should request to have it resent; a timeout can be used to achieve this.