Unit Testing

Post here all your questions related with SmartFoxServer Java API

Moderators: Lapo, Bax

Post Reply
mugambs
Posts: 32
Joined: 11 Dec 2008, 12:05
Location: United Kingdom

Unit Testing

Post by mugambs »

Hi,

We are trying to integrate some Smartfox statistics into our website e.g. things like # of users online, busiest rooms, buddies online etc.

The webapp is running in a seperate Tomcat container (in production it will run on a different server, so dont want to use embedded server)

So my approach so far is to create a service class in my webapp, which wraps all of the Smartfox client communication and event handling. I am using the Java Client API, and have created a simple ConnectionManager class that connects to SFS and listens for events.

Thats all fine, but i'm wondering if anyone has some best practice ideas for unit testing it. At the moment, say I am testing connection, this is what I do.

- Register test case class as an event listener for onConnection
- Initiate connection
- Sleep for X millisecs
- Check that an onConnection event was received, and success = true

That also works, but I dont like the sleep. It needs to be somewhere around 300 millisecs to allow time for event to be received. As the number of tests grow and become more complex, this could be a serious hit on the unit test time.

I suppose one option would be to create a mock XML socket server - wondering what your thoughts are?

Regards,

Mo
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

Hi,
you mentioned a 300ms delay... it's not clear... is that the amount of time necessary to connect? Is the Server running locally?
In a LAN a connection should take place in just a few milliseconds, and the same should go for all other calls which in turn would allow you to run your tests without much added time overhead.
Lapo
--
gotoAndPlay()
...addicted to flash games
mugambs
Posts: 32
Joined: 11 Dec 2008, 12:05
Location: United Kingdom

Post by mugambs »

Hi Lapo,

Thanks for your reply.

Yes, the 300 ms is a safe time taken to connect, login and get the room list. If i reduce it, the test intermittently fails.

However, I've been thinking about the best way of integrating an SFS client into a web application. Please correct me if I'm wrong, but I think the client needs to run in its own dedicated thread, initialised on application startup.

That should take care of the issues between synchronous HTTP requests and asynchronous SFS client?

Regards,

Mo
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

I don't think this is necessary because the Client API already spawn the necessary networking threads. So your event handlers will be called by those threads.
Lapo
--
gotoAndPlay()
...addicted to flash games
Post Reply