Frage

I have about 100 JUnit tests that simulate a client's socket connection with a server. They look something like this:

@Test
public void testProtocolInACertainWay() throws Exception {
    Socket socket = _socketFactory.createSocket(_host, _port);  // SSLSocketFactory

    // Send payload
    DataOutputStream outputStream = new DataOutputStream(socket.getOutputStream());
    outputStream.write(/* test-specific payload */);
    outputStream.flush();

    // Receive response
    DataInputStream inputStream = new DataInputStream(socket.getInputStream());        
    socket.setSoTimeout(5000);
    byte[] buffer = new byte[512];
    int numBytesRead = inputStream.read(buffer);
    buffer = ArrayUtils.subarray(buffer, 0, numBytesRead);

    // Assert test-specific stuff on response
    Assert.assertTrue(buffer[0] == (byte)1);  // for example

    /* At this point, depending on the test, we either repeat similar steps with different payloads or end the test */
}

Now, I want to be able to run these tests (or a subset) from a server, 1.5 million at a time. That means that I want to send out 1.5M socket writes concurrently, read them all, and assert on their responses.

Is there a way I can do this without having to rewrite all 100 JUnit tests? (Please say yes, SO :))

Thanks!

War es hilfreich?

Lösung

After much research, turns out what I really wanted to do was use Netty or vert.x. I would have had to rewrite all the tests to use an event queue instead of blocking I/O.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top