blob: b7f706ef80af3939dc08241f88bae2d1cb331410 [file] [log] [blame]
toma7083182014-09-25 21:38:03 -07001package org.onlab.nio;
2
3import org.junit.Before;
4import org.junit.Ignore;
5import org.junit.Test;
6
7import java.net.InetAddress;
8import java.text.DecimalFormat;
9import java.util.Random;
10
11import static org.onlab.junit.TestTools.delay;
12
13/**
14 * Integration test for the select, accept and IO loops.
15 */
16public class IOLoopIntegrationTest {
17
18 private static final int MILLION = 1000000;
19 private static final int TIMEOUT = 60;
20
21 private static final int THREADS = 6;
22 private static final int MSG_COUNT = 20 * MILLION;
23 private static final int MSG_SIZE = 128;
24
25 private static final long MIN_MPS = 10 * MILLION;
26
27 @Before
28 public void warmUp() throws Exception {
29 try {
30 run(MILLION, MSG_SIZE, 15, 0);
31 } catch (Throwable e) {
32 System.err.println("Failed warmup but moving on.");
33 e.printStackTrace();
34 }
35 }
36
37 @Ignore
38 @Test
39 public void basic() throws Exception {
40 run(MSG_COUNT, MSG_SIZE, TIMEOUT, MIN_MPS);
41 }
42
43
44 private void run(int count, int size, int timeout, double mps) throws Exception {
45 DecimalFormat f = new DecimalFormat("#,##0");
46 System.out.print(f.format(count * THREADS) +
47 (mps > 0.0 ? " messages: " : " message warm-up: "));
48
49 // Setup the test on a random port to avoid intermittent test failures
50 // due to the port being already bound.
tom2d6d3972014-09-25 22:38:57 -070051 int port = IOLoopServer.PORT + new Random().nextInt(100);
toma7083182014-09-25 21:38:03 -070052
53 InetAddress ip = InetAddress.getLoopbackAddress();
tom2d6d3972014-09-25 22:38:57 -070054 IOLoopServer sss = new IOLoopServer(ip, THREADS, size, port);
55 IOLoopClient ssc = new IOLoopClient(ip, THREADS, count, size, port);
toma7083182014-09-25 21:38:03 -070056
57 sss.start();
58 ssc.start();
59 delay(250); // give the server and client a chance to go
60
61 ssc.await(timeout);
62 ssc.report();
63
64 delay(1000);
65 sss.stop();
66 sss.report();
toma7083182014-09-25 21:38:03 -070067 }
68
69}