Move tests to the appropriate packages / Remove unnecessary tests

This commit is contained in:
Trustin Lee 2012-06-02 23:28:17 -07:00
parent cc4c98d7ba
commit e241b3d6a2
23 changed files with 32 additions and 447 deletions

View File

@ -1,80 +0,0 @@
/*
* Copyright 2011 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.testsuite.transport.socket.nio;
import static org.junit.Assert.*;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.ServerSocketChannel;
import java.util.concurrent.Executors;
import org.junit.Test;
import io.netty.bootstrap.ClientBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.socket.nio.NioClientSocketChannelFactory;
import io.netty.testsuite.util.DummyHandler;
import io.netty.util.SocketAddresses;
public class NioClientSocketShutdownTimeTest {
@Test
public void testShutdownTime() throws Throwable {
ServerSocketChannel serverSocket = ServerSocketChannel.open();
serverSocket.socket().bind(new InetSocketAddress(0));
ClientBootstrap b = new ClientBootstrap(
new NioClientSocketChannelFactory(Executors.newCachedThreadPool()));
b.pipeline().addLast("handler", new DummyHandler());
long startTime;
long stopTime;
try {
serverSocket.configureBlocking(false);
ChannelFuture f = b.connect(new InetSocketAddress(
SocketAddresses.LOCALHOST,
serverSocket.socket().getLocalPort()));
serverSocket.accept();
f.awaitUninterruptibly();
if (f.cause() != null) {
throw f.cause();
}
assertTrue(f.isSuccess());
startTime = System.currentTimeMillis();
f.channel().close().awaitUninterruptibly();
} finally {
b.getFactory().releaseExternalResources();
stopTime = System.currentTimeMillis();
try {
serverSocket.close();
} catch (IOException ex) {
// Ignore.
}
}
long shutdownTime = stopTime - startTime;
assertTrue("Shutdown takes too long: " + shutdownTime + " ms", shutdownTime < 500);
}
}

View File

@ -1,104 +0,0 @@
/*
* Copyright 2011 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.testsuite.transport.socket.nio;
import static org.junit.Assert.*;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.concurrent.Executors;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelStateEvent;
import io.netty.channel.SimpleChannelUpstreamHandler;
import io.netty.channel.socket.nio.NioServerSocketChannelFactory;
import io.netty.util.SocketAddresses;
import org.junit.Test;
public class NioServerSocketShutdownTimeTest {
@Test(timeout = 10000)
public void testSuccessfulBindAttempt() throws Exception {
ServerBootstrap bootstrap = new ServerBootstrap(
new NioServerSocketChannelFactory(Executors.newCachedThreadPool()));
bootstrap.setOption("localAddress", new InetSocketAddress(0));
bootstrap.setOption("child.receiveBufferSize", 9753);
bootstrap.setOption("child.sendBufferSize", 8642);
DummyHandler handler = new DummyHandler();
bootstrap.pipeline().addLast("dummy", handler);
Channel channel = bootstrap.bind();
final long startTime;
Socket socket = null;
try {
socket = new Socket(
SocketAddresses.LOCALHOST,
((InetSocketAddress) channel.getLocalAddress()).getPort());
while (!handler.connected) {
Thread.yield();
}
socket.close();
while (!handler.closed) {
Thread.yield();
}
} finally {
if (socket != null) {
try {
socket.close();
} catch (IOException e) {
// Ignore.
}
}
startTime = System.currentTimeMillis();
channel.close().awaitUninterruptibly();
bootstrap.getFactory().releaseExternalResources();
}
long shutdownTime = System.currentTimeMillis() - startTime;
assertTrue("Shutdown takes too long: " + shutdownTime + " ms", shutdownTime < 500);
}
private static class DummyHandler extends SimpleChannelUpstreamHandler {
volatile boolean connected;
volatile boolean closed;
DummyHandler() {
}
@Override
public void channelConnected(ChannelHandlerContext ctx,
ChannelStateEvent e) throws Exception {
connected = true;
}
@Override
public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e)
throws Exception {
closed = true;
}
}
}

View File

@ -1,39 +0,0 @@
/*
* Copyright 2011 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.testsuite.transport.socket.nio;
import java.util.concurrent.Executor;
import io.netty.channel.ChannelFactory;
import io.netty.channel.socket.nio.NioClientSocketChannelFactory;
import io.netty.testsuite.transport.socket.AbstractSocketClientBootstrapTest;
/**
* A test for New I/O socket client bootstraps
*/
public class NioSocketClientBootstrapTest extends
AbstractSocketClientBootstrapTest {
/**
* Creates a new New I/O client socket channel factory
*
* @param executor The executor to use
*/
@Override
protected ChannelFactory newClientSocketChannelFactory(Executor executor) {
return new NioClientSocketChannelFactory(executor);
}
}

View File

@ -1,39 +0,0 @@
/*
* Copyright 2011 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.testsuite.transport.socket.nio;
import java.util.concurrent.Executor;
import io.netty.channel.ChannelFactory;
import io.netty.channel.socket.nio.NioServerSocketChannelFactory;
import io.netty.testsuite.transport.socket.AbstractSocketServerBootstrapTest;
/**
* A test for New I/O socket server bootstraps
*/
public class NioSocketServerBootstrapTest extends
AbstractSocketServerBootstrapTest {
/**
* Creates a new New I/O server socket channel factory
*
* @param executor The executor to use
*/
@Override
protected ChannelFactory newServerSocketChannelFactory(Executor executor) {
return new NioServerSocketChannelFactory(executor);
}
}

View File

@ -1,91 +0,0 @@
/*
* Copyright 2011 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.testsuite.transport.socket.nio;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
/**
* A UDP (User Datagram Protocol) client for use in testing
*/
public class UdpClient {
/**
* The internet address which is the target of this client
*/
private final InetAddress address;
/**
* The datagram socket used by this client
*/
private final DatagramSocket clientSocket;
/**
* The destination port used by this client
*/
private final int port;
/**
* Creates a new UDP client
*
* @param address The target address to use
* @param port The target port to use
*/
public UdpClient(final InetAddress address, final int port)
throws SocketException {
//Set the address
this.address = address;
//Set the port
this.port = port;
//Set up a new datagram socket
clientSocket = new DatagramSocket();
//And allow addresses to be reused
clientSocket.setReuseAddress(true);
}
/**
* Sends a packet
*
* @param payload The payload of bytes to send
* @return The datagram packet sent
*/
public void send(final byte[] payload) throws IOException {
final DatagramPacket dp =
new DatagramPacket(payload, payload.length, address, port);
clientSocket.send(dp);
}
/**
* Receives data from a datagram packet
*
* @param dp The datagram packet to use
* @param timeout The timeout to use
*/
public void receive(final DatagramPacket dp, final int timeout) throws IOException {
clientSocket.setSoTimeout(timeout);
clientSocket.receive(dp);
}
/**
* Close this client and the socket it uses
*/
public void close() {
clientSocket.close();
}
}

View File

@ -13,13 +13,14 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.testsuite.transport.socket;
package io.netty.testsuite.transport.socket.nio.nio;
import java.util.concurrent.Executor;
import io.netty.channel.ChannelFactory;
import io.netty.channel.socket.nio.NioClientSocketChannelFactory;
import io.netty.channel.socket.nio.NioServerSocketChannelFactory;
import io.netty.testsuite.transport.socket.AbstractSocketCompatibleObjectStreamEchoTest;
public class NioNioSocketCompatibleObjectStreamEchoTest extends AbstractSocketCompatibleObjectStreamEchoTest {

View File

@ -13,13 +13,14 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.testsuite.transport.socket;
package io.netty.testsuite.transport.socket.nio.nio;
import java.util.concurrent.Executor;
import io.netty.channel.ChannelFactory;
import io.netty.channel.socket.nio.NioClientSocketChannelFactory;
import io.netty.channel.socket.nio.NioServerSocketChannelFactory;
import io.netty.testsuite.transport.socket.AbstractSocketFixedLengthEchoTest;
public class NioNioSocketFixedLengthEchoTest extends AbstractSocketFixedLengthEchoTest {

View File

@ -13,13 +13,14 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.testsuite.transport.socket;
package io.netty.testsuite.transport.socket.nio.nio;
import java.util.concurrent.Executor;
import io.netty.channel.ChannelFactory;
import io.netty.channel.socket.nio.NioClientSocketChannelFactory;
import io.netty.channel.socket.nio.NioServerSocketChannelFactory;
import io.netty.testsuite.transport.socket.AbstractSocketObjectStreamEchoTest;
public class NioNioSocketObjectStreamEchoTest extends AbstractSocketObjectStreamEchoTest {

View File

@ -13,13 +13,14 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.testsuite.transport.socket;
package io.netty.testsuite.transport.socket.nio.nio;
import java.util.concurrent.Executor;
import io.netty.channel.ChannelFactory;
import io.netty.channel.socket.nio.NioClientSocketChannelFactory;
import io.netty.channel.socket.nio.NioServerSocketChannelFactory;
import io.netty.testsuite.transport.socket.AbstractSocketStringEchoTest;
public class NioNioSocketStringEchoTest extends AbstractSocketStringEchoTest {

View File

@ -13,13 +13,14 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.testsuite.transport.socket;
package io.netty.testsuite.transport.socket.nio.oio;
import java.util.concurrent.Executor;
import io.netty.channel.ChannelFactory;
import io.netty.channel.socket.nio.NioClientSocketChannelFactory;
import io.netty.channel.socket.oio.OioServerSocketChannelFactory;
import io.netty.testsuite.transport.socket.AbstractSocketCompatibleObjectStreamEchoTest;
public class NioOioSocketCompatibleObjectStreamEchoTest extends AbstractSocketCompatibleObjectStreamEchoTest {

View File

@ -13,13 +13,14 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.testsuite.transport.socket;
package io.netty.testsuite.transport.socket.nio.oio;
import java.util.concurrent.Executor;
import io.netty.channel.ChannelFactory;
import io.netty.channel.socket.nio.NioClientSocketChannelFactory;
import io.netty.channel.socket.oio.OioServerSocketChannelFactory;
import io.netty.testsuite.transport.socket.AbstractSocketFixedLengthEchoTest;
public class NioOioSocketFixedLengthEchoTest extends AbstractSocketFixedLengthEchoTest {

View File

@ -13,13 +13,14 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.testsuite.transport.socket;
package io.netty.testsuite.transport.socket.nio.oio;
import java.util.concurrent.Executor;
import io.netty.channel.ChannelFactory;
import io.netty.channel.socket.nio.NioClientSocketChannelFactory;
import io.netty.channel.socket.oio.OioServerSocketChannelFactory;
import io.netty.testsuite.transport.socket.AbstractSocketObjectStreamEchoTest;
public class NioOioSocketObjectStreamEchoTest extends AbstractSocketObjectStreamEchoTest {

View File

@ -13,13 +13,14 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.testsuite.transport.socket;
package io.netty.testsuite.transport.socket.nio.oio;
import java.util.concurrent.Executor;
import io.netty.channel.ChannelFactory;
import io.netty.channel.socket.nio.NioClientSocketChannelFactory;
import io.netty.channel.socket.oio.OioServerSocketChannelFactory;
import io.netty.testsuite.transport.socket.AbstractSocketStringEchoTest;
public class NioOioSocketStringEchoTest extends AbstractSocketStringEchoTest {

View File

@ -1,39 +0,0 @@
/*
* Copyright 2011 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.testsuite.transport.socket.oio;
import java.util.concurrent.Executor;
import io.netty.channel.ChannelFactory;
import io.netty.channel.socket.oio.OioClientSocketChannelFactory;
import io.netty.testsuite.transport.socket.AbstractSocketClientBootstrapTest;
/**
* A test for "Old" I/O socket client bootstraps
*/
public class OioSocketClientBootstrapTest extends
AbstractSocketClientBootstrapTest {
/**
* Creates a new "Old" I/O client socket channel factory
*
* @param executor The executor to use
*/
@Override
protected ChannelFactory newClientSocketChannelFactory(Executor executor) {
return new OioClientSocketChannelFactory(executor);
}
}

View File

@ -1,39 +0,0 @@
/*
* Copyright 2011 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.testsuite.transport.socket.oio;
import java.util.concurrent.Executor;
import io.netty.channel.ChannelFactory;
import io.netty.channel.socket.oio.OioServerSocketChannelFactory;
import io.netty.testsuite.transport.socket.AbstractSocketServerBootstrapTest;
/**
* A socket server bootstrap test for "Old" I/O
*/
public class OioSocketServerBootstrapTest extends
AbstractSocketServerBootstrapTest {
/**
* Creates a new "Old" I/O server socket channel factory
*
* @param executor The executor to use
*/
@Override
protected ChannelFactory newServerSocketChannelFactory(Executor executor) {
return new OioServerSocketChannelFactory(executor, executor);
}
}

View File

@ -13,13 +13,14 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.testsuite.transport.socket;
package io.netty.testsuite.transport.socket.oio.nio;
import java.util.concurrent.Executor;
import io.netty.channel.ChannelFactory;
import io.netty.channel.socket.nio.NioServerSocketChannelFactory;
import io.netty.channel.socket.oio.OioClientSocketChannelFactory;
import io.netty.testsuite.transport.socket.AbstractSocketCompatibleObjectStreamEchoTest;
public class OioNioSocketCompatibleObjectStreamEchoTest extends AbstractSocketCompatibleObjectStreamEchoTest {

View File

@ -13,13 +13,14 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.testsuite.transport.socket;
package io.netty.testsuite.transport.socket.oio.nio;
import java.util.concurrent.Executor;
import io.netty.channel.ChannelFactory;
import io.netty.channel.socket.nio.NioServerSocketChannelFactory;
import io.netty.channel.socket.oio.OioClientSocketChannelFactory;
import io.netty.testsuite.transport.socket.AbstractSocketFixedLengthEchoTest;
public class OioNioSocketFixedLengthEchoTest extends AbstractSocketFixedLengthEchoTest {

View File

@ -13,13 +13,14 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.testsuite.transport.socket;
package io.netty.testsuite.transport.socket.oio.nio;
import java.util.concurrent.Executor;
import io.netty.channel.ChannelFactory;
import io.netty.channel.socket.nio.NioServerSocketChannelFactory;
import io.netty.channel.socket.oio.OioClientSocketChannelFactory;
import io.netty.testsuite.transport.socket.AbstractSocketObjectStreamEchoTest;
/**
*/

View File

@ -13,13 +13,14 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.testsuite.transport.socket;
package io.netty.testsuite.transport.socket.oio.nio;
import java.util.concurrent.Executor;
import io.netty.channel.ChannelFactory;
import io.netty.channel.socket.nio.NioServerSocketChannelFactory;
import io.netty.channel.socket.oio.OioClientSocketChannelFactory;
import io.netty.testsuite.transport.socket.AbstractSocketStringEchoTest;
public class OioNioSocketStringEchoTest extends AbstractSocketStringEchoTest {

View File

@ -13,13 +13,14 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.testsuite.transport.socket;
package io.netty.testsuite.transport.socket.oio.oio;
import java.util.concurrent.Executor;
import io.netty.channel.ChannelFactory;
import io.netty.channel.socket.oio.OioClientSocketChannelFactory;
import io.netty.channel.socket.oio.OioServerSocketChannelFactory;
import io.netty.testsuite.transport.socket.AbstractSocketCompatibleObjectStreamEchoTest;
public class OioOioSocketCompatibleObjectStreamEchoTest extends AbstractSocketCompatibleObjectStreamEchoTest {

View File

@ -13,13 +13,14 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.testsuite.transport.socket;
package io.netty.testsuite.transport.socket.oio.oio;
import java.util.concurrent.Executor;
import io.netty.channel.ChannelFactory;
import io.netty.channel.socket.oio.OioClientSocketChannelFactory;
import io.netty.channel.socket.oio.OioServerSocketChannelFactory;
import io.netty.testsuite.transport.socket.AbstractSocketFixedLengthEchoTest;
public class OioOioSocketFixedLengthEchoTest extends AbstractSocketFixedLengthEchoTest {

View File

@ -13,13 +13,14 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.testsuite.transport.socket;
package io.netty.testsuite.transport.socket.oio.oio;
import java.util.concurrent.Executor;
import io.netty.channel.ChannelFactory;
import io.netty.channel.socket.oio.OioClientSocketChannelFactory;
import io.netty.channel.socket.oio.OioServerSocketChannelFactory;
import io.netty.testsuite.transport.socket.AbstractSocketObjectStreamEchoTest;
public class OioOioSocketObjectStreamEchoTest extends AbstractSocketObjectStreamEchoTest {

View File

@ -13,13 +13,14 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.testsuite.transport.socket;
package io.netty.testsuite.transport.socket.oio.oio;
import java.util.concurrent.Executor;
import io.netty.channel.ChannelFactory;
import io.netty.channel.socket.oio.OioClientSocketChannelFactory;
import io.netty.channel.socket.oio.OioServerSocketChannelFactory;
import io.netty.testsuite.transport.socket.AbstractSocketStringEchoTest;
public class OioOioSocketStringEchoTest extends AbstractSocketStringEchoTest {