blob: f42c8dc503bb46b961b977d429af7eb8d263c0d9 [file] [log] [blame]
Thomas Vachuska24c849c2014-10-27 09:53:05 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska24c849c2014-10-27 09:53:05 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
Thomas Vachuska24c849c2014-10-27 09:53:05 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
Thomas Vachuska24c849c2014-10-27 09:53:05 -070015 */
toma7083182014-09-25 21:38:03 -070016package org.onlab.nio;
17
18import org.junit.Before;
Pingping3855f312014-10-22 12:50:37 -070019import org.junit.Ignore;
toma7083182014-09-25 21:38:03 -070020import org.junit.Test;
21
22import java.net.InetAddress;
toma7083182014-09-25 21:38:03 -070023import java.util.Random;
tom74d49652014-09-25 23:48:46 -070024import java.util.logging.Level;
25import java.util.logging.Logger;
toma7083182014-09-25 21:38:03 -070026
27import static org.onlab.junit.TestTools.delay;
28
29/**
30 * Integration test for the select, accept and IO loops.
31 */
32public class IOLoopIntegrationTest {
33
toma7083182014-09-25 21:38:03 -070034 private static final int THREADS = 6;
tom74d49652014-09-25 23:48:46 -070035 private static final int TIMEOUT = 60;
36 private static final int MESSAGE_LENGTH = 128;
toma7083182014-09-25 21:38:03 -070037
tom74d49652014-09-25 23:48:46 -070038 private static final int MILLION = 1000000;
39 private static final int MSG_COUNT = 40 * MILLION;
toma7083182014-09-25 21:38:03 -070040
41 @Before
42 public void warmUp() throws Exception {
tom74d49652014-09-25 23:48:46 -070043 Logger.getLogger("").setLevel(Level.SEVERE);
toma7083182014-09-25 21:38:03 -070044 try {
tom74d49652014-09-25 23:48:46 -070045 runTest(MILLION, MESSAGE_LENGTH, 15);
toma7083182014-09-25 21:38:03 -070046 } catch (Throwable e) {
47 System.err.println("Failed warmup but moving on.");
48 e.printStackTrace();
49 }
50 }
51
Pingping3855f312014-10-22 12:50:37 -070052 // TODO: this test can not pass in some environments, need to be improved
53 @Ignore
toma7083182014-09-25 21:38:03 -070054 @Test
55 public void basic() throws Exception {
tom74d49652014-09-25 23:48:46 -070056 runTest(MILLION, MESSAGE_LENGTH, TIMEOUT);
toma7083182014-09-25 21:38:03 -070057 }
58
tom74d49652014-09-25 23:48:46 -070059 public void longHaul() throws Exception {
60 runTest(MSG_COUNT, MESSAGE_LENGTH, TIMEOUT);
61 }
toma7083182014-09-25 21:38:03 -070062
tom74d49652014-09-25 23:48:46 -070063 private void runTest(int count, int size, int timeout) throws Exception {
64 // Use a random port to prevent conflicts.
65 int port = IOLoopTestServer.PORT + new Random().nextInt(100);
toma7083182014-09-25 21:38:03 -070066
67 InetAddress ip = InetAddress.getLoopbackAddress();
tom74d49652014-09-25 23:48:46 -070068 IOLoopTestServer server = new IOLoopTestServer(ip, THREADS, size, port);
69 IOLoopTestClient client = new IOLoopTestClient(ip, THREADS, count, size, port);
toma7083182014-09-25 21:38:03 -070070
tom74d49652014-09-25 23:48:46 -070071 server.start();
72 client.start();
73 delay(100); // Pause to allow loops to get going
toma7083182014-09-25 21:38:03 -070074
tom74d49652014-09-25 23:48:46 -070075 client.await(timeout);
76 client.report();
toma7083182014-09-25 21:38:03 -070077
tom74d49652014-09-25 23:48:46 -070078 server.stop();
79 server.report();
toma7083182014-09-25 21:38:03 -070080 }
81
82}