blob: 79e5f71858d0553ba9e69e90a590173e13a448de [file] [log] [blame]
Thomas Vachuska24c849c2014-10-27 09:53:05 -07001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
toma7083182014-09-25 21:38:03 -070019package org.onlab.nio;
20
21import org.junit.Before;
Pingping3855f312014-10-22 12:50:37 -070022import org.junit.Ignore;
toma7083182014-09-25 21:38:03 -070023import org.junit.Test;
24
25import java.net.InetAddress;
toma7083182014-09-25 21:38:03 -070026import java.util.Random;
tom74d49652014-09-25 23:48:46 -070027import java.util.logging.Level;
28import java.util.logging.Logger;
toma7083182014-09-25 21:38:03 -070029
30import static org.onlab.junit.TestTools.delay;
31
32/**
33 * Integration test for the select, accept and IO loops.
34 */
35public class IOLoopIntegrationTest {
36
toma7083182014-09-25 21:38:03 -070037 private static final int THREADS = 6;
tom74d49652014-09-25 23:48:46 -070038 private static final int TIMEOUT = 60;
39 private static final int MESSAGE_LENGTH = 128;
toma7083182014-09-25 21:38:03 -070040
tom74d49652014-09-25 23:48:46 -070041 private static final int MILLION = 1000000;
42 private static final int MSG_COUNT = 40 * MILLION;
toma7083182014-09-25 21:38:03 -070043
44 @Before
45 public void warmUp() throws Exception {
tom74d49652014-09-25 23:48:46 -070046 Logger.getLogger("").setLevel(Level.SEVERE);
toma7083182014-09-25 21:38:03 -070047 try {
tom74d49652014-09-25 23:48:46 -070048 runTest(MILLION, MESSAGE_LENGTH, 15);
toma7083182014-09-25 21:38:03 -070049 } catch (Throwable e) {
50 System.err.println("Failed warmup but moving on.");
51 e.printStackTrace();
52 }
53 }
54
Pingping3855f312014-10-22 12:50:37 -070055 // TODO: this test can not pass in some environments, need to be improved
56 @Ignore
toma7083182014-09-25 21:38:03 -070057 @Test
58 public void basic() throws Exception {
tom74d49652014-09-25 23:48:46 -070059 runTest(MILLION, MESSAGE_LENGTH, TIMEOUT);
toma7083182014-09-25 21:38:03 -070060 }
61
tom74d49652014-09-25 23:48:46 -070062 public void longHaul() throws Exception {
63 runTest(MSG_COUNT, MESSAGE_LENGTH, TIMEOUT);
64 }
toma7083182014-09-25 21:38:03 -070065
tom74d49652014-09-25 23:48:46 -070066 private void runTest(int count, int size, int timeout) throws Exception {
67 // Use a random port to prevent conflicts.
68 int port = IOLoopTestServer.PORT + new Random().nextInt(100);
toma7083182014-09-25 21:38:03 -070069
70 InetAddress ip = InetAddress.getLoopbackAddress();
tom74d49652014-09-25 23:48:46 -070071 IOLoopTestServer server = new IOLoopTestServer(ip, THREADS, size, port);
72 IOLoopTestClient client = new IOLoopTestClient(ip, THREADS, count, size, port);
toma7083182014-09-25 21:38:03 -070073
tom74d49652014-09-25 23:48:46 -070074 server.start();
75 client.start();
76 delay(100); // Pause to allow loops to get going
toma7083182014-09-25 21:38:03 -070077
tom74d49652014-09-25 23:48:46 -070078 client.await(timeout);
79 client.report();
toma7083182014-09-25 21:38:03 -070080
tom74d49652014-09-25 23:48:46 -070081 server.stop();
82 server.report();
toma7083182014-09-25 21:38:03 -070083 }
84
85}