blob: e61f6e2dc393360e0039194151509c1c5a613c22 [file] [log] [blame]
toma7083182014-09-25 21:38:03 -07001package org.onlab.nio;
2
3import org.junit.Before;
toma7083182014-09-25 21:38:03 -07004import org.junit.Test;
5
6import java.net.InetAddress;
toma7083182014-09-25 21:38:03 -07007import java.util.Random;
tom74d49652014-09-25 23:48:46 -07008import java.util.logging.Level;
9import java.util.logging.Logger;
toma7083182014-09-25 21:38:03 -070010
11import static org.onlab.junit.TestTools.delay;
12
13/**
14 * Integration test for the select, accept and IO loops.
15 */
16public class IOLoopIntegrationTest {
17
toma7083182014-09-25 21:38:03 -070018 private static final int THREADS = 6;
tom74d49652014-09-25 23:48:46 -070019 private static final int TIMEOUT = 60;
20 private static final int MESSAGE_LENGTH = 128;
toma7083182014-09-25 21:38:03 -070021
tom74d49652014-09-25 23:48:46 -070022 private static final int MILLION = 1000000;
23 private static final int MSG_COUNT = 40 * MILLION;
toma7083182014-09-25 21:38:03 -070024
25 @Before
26 public void warmUp() throws Exception {
tom74d49652014-09-25 23:48:46 -070027 Logger.getLogger("").setLevel(Level.SEVERE);
toma7083182014-09-25 21:38:03 -070028 try {
tom74d49652014-09-25 23:48:46 -070029 runTest(MILLION, MESSAGE_LENGTH, 15);
toma7083182014-09-25 21:38:03 -070030 } catch (Throwable e) {
31 System.err.println("Failed warmup but moving on.");
32 e.printStackTrace();
33 }
34 }
35
tom74d49652014-09-25 23:48:46 -070036
toma7083182014-09-25 21:38:03 -070037 @Test
38 public void basic() throws Exception {
tom74d49652014-09-25 23:48:46 -070039 runTest(MILLION, MESSAGE_LENGTH, TIMEOUT);
toma7083182014-09-25 21:38:03 -070040 }
41
tom74d49652014-09-25 23:48:46 -070042 public void longHaul() throws Exception {
43 runTest(MSG_COUNT, MESSAGE_LENGTH, TIMEOUT);
44 }
toma7083182014-09-25 21:38:03 -070045
tom74d49652014-09-25 23:48:46 -070046 private void runTest(int count, int size, int timeout) throws Exception {
47 // Use a random port to prevent conflicts.
48 int port = IOLoopTestServer.PORT + new Random().nextInt(100);
toma7083182014-09-25 21:38:03 -070049
50 InetAddress ip = InetAddress.getLoopbackAddress();
tom74d49652014-09-25 23:48:46 -070051 IOLoopTestServer server = new IOLoopTestServer(ip, THREADS, size, port);
52 IOLoopTestClient client = new IOLoopTestClient(ip, THREADS, count, size, port);
toma7083182014-09-25 21:38:03 -070053
tom74d49652014-09-25 23:48:46 -070054 server.start();
55 client.start();
56 delay(100); // Pause to allow loops to get going
toma7083182014-09-25 21:38:03 -070057
tom74d49652014-09-25 23:48:46 -070058 client.await(timeout);
59 client.report();
toma7083182014-09-25 21:38:03 -070060
tom74d49652014-09-25 23:48:46 -070061 server.stop();
62 server.report();
toma7083182014-09-25 21:38:03 -070063 }
64
65}