I have a java server on a server socket. Clients connect to this server socket, and exchange over input/output object streams. Now I need to test the app for scalability. Which means I need to run the same test making requests, and test if the server is able to handle requests from random clients.
Is the below junit based test case the right way to test random connections/requests. I get a feeling that the below code is testing clients sequencially.
Some links I read, and did not work for me
Creating a JUnit testsuite with multiple instances of a Parameterized test
public class ScalePostiveTestCases {
SendQueue sendQueue;
Socket clientSocket = null;
public static void main(String[] args) throws Throwable {
testSearching() ;
}
@SuppressWarnings("unchecked")
private static void testSearching() throws ClassNotFoundException, InstantiationException, IllegalAccessException {
TestSuite tests = new TestSuite();
for (int i = 0; i < 99; i++) {
Class<SingleSearchTest> singleSearchTest = (Class<SingleSearchTest>) ClassLoader
.getSystemClassLoader().loadClass(
"SingleSearchTest");
SingleSearchTest singleSearch = singleSearchTest.newInstance();
tests.addTest(singleSearch);
}
TestRunner.run(tests);
}
public class SingleSearchTest extends TestCase {
static SingleSearchTest singleSearch = null;
private String device, connection, user;
private ClientSession clientSession;
private SendQueue sendQueue;
public static SingleSearchTest main(String args[]) {
singleSearch = new SingleSearchTest();
return singleSearch;
}
public SingleSearchTest() {
super("testSingleSearch");
Random rand = new Random();
}
}
You are creating many test which have one client each.
What you need to do is have one plain test which creates many clients which are executed concurrently.
In my unit tests;