blob: 21843f0d735b3cbc3f260cba8ea2760702cad9bf [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.
51 int port = StandaloneSpeedServer.PORT + new Random().nextInt(100);
52
53 InetAddress ip = InetAddress.getLoopbackAddress();
54 StandaloneSpeedServer sss = new StandaloneSpeedServer(ip, THREADS, size, port);
55 StandaloneSpeedClient ssc = new StandaloneSpeedClient(ip, THREADS, count, size, port);
56
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();
67
68 // Note that the client and server will have potentially significantly
69 // differing rates. This is due to the wide variance in how tightly
70 // the throughput tracking starts & stops relative to to the short
71 // test duration.
72// System.out.println(f.format(ssc.messages.throughput()) + " mps");
73
74// // Make sure client sent everything.
75// assertEquals("incorrect client message count sent",
76// (long) count * THREADS, ssc.messages.total());
77// assertEquals("incorrect client bytes count sent",
78// (long) size * count * THREADS, ssc.bytes.total());
79//
80// // Make sure server received everything.
81// assertEquals("incorrect server message count received",
82// (long) count * THREADS, sss.messages.total());
83// assertEquals("incorrect server bytes count received",
84// (long) size * count * THREADS, sss.bytes.total());
85//
86// // Make sure speeds were reasonable.
87// if (mps > 0.0) {
88// assertAboveThreshold("insufficient client speed", mps,
89// ssc.messages.throughput());
90// assertAboveThreshold("insufficient server speed", mps / 2,
91// sss.messages.throughput());
92// }
93 }
94
95}