This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hello Cedric and Hani, Welcome to Javaranch. I am using google web toolkit with RPC calls to database. Your book index has Asynchronous Testing topic. Do you think it will help me testing RPC calls to database?
Yes, it's actually very easy to do this sort of test via dependencies, we cover this quite extensively in the book (both in terms of async testing in general, and illustrating the same techniques later on with JMS).
The basic idea is to have test pairs, one for sending and one for receiving. The receiver depends on the sender, and has a timeout value so you dont end up blocking forever. In code, the test's annotation looks like @Test(dependsOnMethod="sendRequest", timeout=1000)
TestNG will run the first test (or configuration method, if its not an actual test) which will send the request. Then the second test is run, which will read the response (well, wait for it first), and verify the results. TestNG allows you to guarantee that the tests are run in that order, so you dont end up waiting for a response before you've sent the request out.
Originally posted by Daniel Trebbien: This is interesting. Is there also a way to run two test methods simultaneously? For example, if one wishes to test the server-side and client-side code of a protocol implementation.
Yes: you can ask TestNG to run all your test methods in different threads (you configure the thread pool size in testng.xml). Here is the relevant documentation link:
However, I'm not sure I would do that in the situation you are describing, since both sides should be part of the same test method. You would probably be better off spawning the back-end part in a separate thread and wait for it in the main thread. You can also ask TestNG to abort you after a little while to make sure you won't block: