Move SPDY echo tests to testsuite to use AbstractSocketTest
- Moved MIN_VERSION and MAX_VERSION to SpdyConstants to allow public access - Removed the tests that are not necessary anymore.
This commit is contained in:
parent
d48973b0ff
commit
361cb417e0
@ -19,9 +19,6 @@ import io.netty.buffer.ChannelBuffer;
|
||||
|
||||
final class SpdyCodecUtil {
|
||||
|
||||
static final int SPDY_MIN_VERSION = 2;
|
||||
static final int SPDY_MAX_VERSION = 3;
|
||||
|
||||
static final int SPDY_HEADER_TYPE_OFFSET = 2;
|
||||
static final int SPDY_HEADER_FLAGS_OFFSET = 4;
|
||||
static final int SPDY_HEADER_LENGTH_OFFSET = 5;
|
||||
|
@ -0,0 +1,9 @@
|
||||
package io.netty.handler.codec.spdy;
|
||||
|
||||
public final class SpdyConstants {
|
||||
|
||||
public static final int SPDY_MIN_VERSION = 2;
|
||||
public static final int SPDY_MAX_VERSION = 3;
|
||||
|
||||
private SpdyConstants() {}
|
||||
}
|
@ -82,7 +82,7 @@ public class SpdyFrameDecoder extends StreamToMessageDecoder<Object> {
|
||||
* Creates a new instance with the specified parameters.
|
||||
*/
|
||||
public SpdyFrameDecoder(int version, int maxChunkSize, int maxHeaderSize) {
|
||||
if (version < SPDY_MIN_VERSION || version > SPDY_MAX_VERSION) {
|
||||
if (version < SpdyConstants.SPDY_MIN_VERSION || version > SpdyConstants.SPDY_MAX_VERSION) {
|
||||
throw new IllegalArgumentException(
|
||||
"unsupported version: " + version);
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ public class SpdyFrameEncoder extends MessageToStreamEncoder<Object> {
|
||||
*/
|
||||
public SpdyFrameEncoder(int version, int compressionLevel, int windowBits, int memLevel) {
|
||||
super();
|
||||
if (version < SPDY_MIN_VERSION || version > SPDY_MAX_VERSION) {
|
||||
if (version < SpdyConstants.SPDY_MIN_VERSION || version > SpdyConstants.SPDY_MAX_VERSION) {
|
||||
throw new IllegalArgumentException(
|
||||
"unknown version: " + version);
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ class SpdyHeaderBlockJZlibCompressor extends SpdyHeaderBlockCompressor {
|
||||
|
||||
public SpdyHeaderBlockJZlibCompressor(
|
||||
int version, int compressionLevel, int windowBits, int memLevel) {
|
||||
if (version < SPDY_MIN_VERSION || version > SPDY_MAX_VERSION) {
|
||||
if (version < SpdyConstants.SPDY_MIN_VERSION || version > SpdyConstants.SPDY_MAX_VERSION) {
|
||||
throw new IllegalArgumentException(
|
||||
"unsupported version: " + version);
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ class SpdyHeaderBlockZlibCompressor extends SpdyHeaderBlockCompressor {
|
||||
private final Deflater compressor;
|
||||
|
||||
public SpdyHeaderBlockZlibCompressor(int version, int compressionLevel) {
|
||||
if (version < SPDY_MIN_VERSION || version > SPDY_MAX_VERSION) {
|
||||
if (version < SpdyConstants.SPDY_MIN_VERSION || version > SpdyConstants.SPDY_MAX_VERSION) {
|
||||
throw new IllegalArgumentException(
|
||||
"unsupported version: " + version);
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ class SpdyHeaderBlockZlibDecompressor extends SpdyHeaderBlockDecompressor {
|
||||
private final Inflater decompressor = new Inflater();
|
||||
|
||||
public SpdyHeaderBlockZlibDecompressor(int version) {
|
||||
if (version < SPDY_MIN_VERSION || version > SPDY_MAX_VERSION) {
|
||||
if (version < SpdyConstants.SPDY_MIN_VERSION || version > SpdyConstants.SPDY_MAX_VERSION) {
|
||||
throw new IllegalArgumentException(
|
||||
"unsupported version: " + version);
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ public class SpdyHttpDecoder extends MessageToMessageDecoder<Object, HttpMessage
|
||||
*/
|
||||
public SpdyHttpDecoder(int version, int maxContentLength) {
|
||||
super();
|
||||
if (version < SPDY_MIN_VERSION || version > SPDY_MAX_VERSION) {
|
||||
if (version < SpdyConstants.SPDY_MIN_VERSION || version > SpdyConstants.SPDY_MAX_VERSION) {
|
||||
throw new IllegalArgumentException(
|
||||
"unsupported version: " + version);
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ public class SpdyHttpEncoder extends MessageToMessageEncoder<Object, Object> {
|
||||
* @param version the protocol version
|
||||
*/
|
||||
public SpdyHttpEncoder(int version) {
|
||||
if (version < SPDY_MIN_VERSION || version > SPDY_MAX_VERSION) {
|
||||
if (version < SpdyConstants.SPDY_MIN_VERSION || version > SpdyConstants.SPDY_MAX_VERSION) {
|
||||
throw new IllegalArgumentException(
|
||||
"unsupported version: " + version);
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ public class SpdySessionHandler extends ChannelHandlerAdapter<Object, Object> {
|
||||
*/
|
||||
public SpdySessionHandler(int version, boolean server) {
|
||||
super();
|
||||
if (version < SPDY_MIN_VERSION || version > SPDY_MAX_VERSION) {
|
||||
if (version < SpdyConstants.SPDY_MIN_VERSION || version > SpdyConstants.SPDY_MAX_VERSION) {
|
||||
throw new IllegalArgumentException(
|
||||
"unsupported version: " + version);
|
||||
}
|
||||
|
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012 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.handler.codec.spdy;
|
||||
|
||||
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.channel.socket.nio.NioEventLoop;
|
||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
|
||||
public class NioNioSocketSpdyEchoTest extends AbstractSocketSpdyEchoTest {
|
||||
|
||||
@Override
|
||||
protected Bootstrap newClientBootstrap() {
|
||||
return new Bootstrap().eventLoop(new NioEventLoop()).channel(new NioSocketChannel());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ServerBootstrap newServerBootstrap() {
|
||||
return new ServerBootstrap().eventLoop(new NioEventLoop(), new NioEventLoop()).channel(new NioServerSocketChannel());
|
||||
}
|
||||
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012 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.handler.codec.spdy;
|
||||
|
||||
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.channel.socket.nio.NioEventLoop;
|
||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
import io.netty.channel.socket.oio.OioEventLoop;
|
||||
import io.netty.channel.socket.oio.OioServerSocketChannel;
|
||||
|
||||
public class NioOioSocketSpdyEchoTest extends AbstractSocketSpdyEchoTest {
|
||||
|
||||
@Override
|
||||
protected Bootstrap newClientBootstrap() {
|
||||
return new Bootstrap().eventLoop(new NioEventLoop()).channel(new NioSocketChannel());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ServerBootstrap newServerBootstrap() {
|
||||
return new ServerBootstrap().eventLoop(new OioEventLoop(), new OioEventLoop()).channel(new OioServerSocketChannel());
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012 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.handler.codec.spdy;
|
||||
|
||||
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.channel.socket.nio.NioEventLoop;
|
||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
import io.netty.channel.socket.oio.OioEventLoop;
|
||||
import io.netty.channel.socket.oio.OioSocketChannel;
|
||||
|
||||
public class OioNioSocketSpdyEchoTest extends AbstractSocketSpdyEchoTest {
|
||||
|
||||
@Override
|
||||
protected Bootstrap newClientBootstrap() {
|
||||
return new Bootstrap().eventLoop(new OioEventLoop()).channel(new OioSocketChannel());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ServerBootstrap newServerBootstrap() {
|
||||
return new ServerBootstrap().eventLoop(new NioEventLoop(), new NioEventLoop()).channel(new NioServerSocketChannel());
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012 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.handler.codec.spdy;
|
||||
|
||||
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.channel.socket.oio.OioEventLoop;
|
||||
import io.netty.channel.socket.oio.OioServerSocketChannel;
|
||||
import io.netty.channel.socket.oio.OioSocketChannel;
|
||||
|
||||
public class OioOioSocketSpdyEchoTest extends AbstractSocketSpdyEchoTest {
|
||||
|
||||
@Override
|
||||
protected Bootstrap newClientBootstrap() {
|
||||
return new Bootstrap().eventLoop(new OioEventLoop()).channel(new OioSocketChannel());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ServerBootstrap newServerBootstrap() {
|
||||
return new ServerBootstrap().eventLoop(new OioEventLoop(), new OioEventLoop()).channel(new OioServerSocketChannel());
|
||||
}
|
||||
}
|
@ -256,7 +256,7 @@ public class SpdySessionHandlerTest {
|
||||
|
||||
@Test
|
||||
public void testSpdyClientSessionHandler() {
|
||||
for (int version = SPDY_MIN_VERSION; version <= SPDY_MAX_VERSION; version ++) {
|
||||
for (int version = SpdyConstants.SPDY_MIN_VERSION; version <= SpdyConstants.SPDY_MAX_VERSION; version ++) {
|
||||
logger.info("Running: testSpdyClientSessionHandler v" + version);
|
||||
testSpdySessionHandler(version, false);
|
||||
}
|
||||
@ -264,7 +264,7 @@ public class SpdySessionHandlerTest {
|
||||
|
||||
@Test
|
||||
public void testSpdyServerSessionHandler() {
|
||||
for (int version = SPDY_MIN_VERSION; version <= SPDY_MAX_VERSION; version ++) {
|
||||
for (int version = SpdyConstants.SPDY_MIN_VERSION; version <= SpdyConstants.SPDY_MAX_VERSION; version ++) {
|
||||
logger.info("Running: testSpdyServerSessionHandler v" + version);
|
||||
testSpdySessionHandler(version, true);
|
||||
}
|
||||
|
@ -34,6 +34,11 @@
|
||||
<artifactId>netty-handler</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>netty-codec-http</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
|
@ -46,7 +46,7 @@ public abstract class AbstractSocketTest {
|
||||
protected volatile Bootstrap cb;
|
||||
protected volatile InetSocketAddress addr;
|
||||
|
||||
protected void run() throws Exception {
|
||||
protected void run() throws Throwable {
|
||||
int i = 0;
|
||||
for (Entry<Factory<ServerBootstrap>, Factory<Bootstrap>> e: COMBO) {
|
||||
sb = e.getKey().newInstance();
|
||||
|
@ -40,7 +40,7 @@ public class SocketEchoTest extends AbstractSocketTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleEcho() throws Exception {
|
||||
public void testSimpleEcho() throws Throwable {
|
||||
run();
|
||||
}
|
||||
|
||||
|
@ -13,9 +13,8 @@
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package io.netty.handler.codec.spdy;
|
||||
package io.netty.testsuite.transport.socket;
|
||||
|
||||
import static io.netty.handler.codec.spdy.SpdyCodecUtil.*;
|
||||
import static org.junit.Assert.*;
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
@ -27,6 +26,9 @@ import io.netty.channel.ChannelInboundMessageHandlerAdapter;
|
||||
import io.netty.channel.ChannelInboundStreamHandlerAdapter;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import io.netty.handler.codec.spdy.SpdyConstants;
|
||||
import io.netty.handler.codec.spdy.SpdyFrameDecoder;
|
||||
import io.netty.handler.codec.spdy.SpdyFrameEncoder;
|
||||
import io.netty.util.SocketAddresses;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -36,7 +38,7 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public abstract class AbstractSocketSpdyEchoTest {
|
||||
public class SocketSpdyEchoTest extends AbstractSocketTest {
|
||||
|
||||
private static final Random random = new Random();
|
||||
static final int ignoredBytes = 20;
|
||||
@ -163,27 +165,17 @@ public abstract class AbstractSocketSpdyEchoTest {
|
||||
return frames;
|
||||
}
|
||||
|
||||
private ServerBootstrap sb;
|
||||
private Bootstrap cb;
|
||||
private int version;
|
||||
|
||||
protected abstract ServerBootstrap newServerBootstrap();
|
||||
protected abstract Bootstrap newClientBootstrap();
|
||||
|
||||
@Test(timeout = 10000)
|
||||
@Test(timeout = 15000)
|
||||
public void testSpdyEcho() throws Throwable {
|
||||
for (int version = SPDY_MIN_VERSION; version <= SPDY_MAX_VERSION; version ++) {
|
||||
sb = newServerBootstrap();
|
||||
cb = newClientBootstrap();
|
||||
try {
|
||||
testSpdyEcho(version);
|
||||
} finally {
|
||||
sb.shutdown();
|
||||
cb.shutdown();
|
||||
}
|
||||
for (version = SpdyConstants.SPDY_MIN_VERSION; version <= SpdyConstants.SPDY_MAX_VERSION; version ++) {
|
||||
logger.info("Testing against SPDY v" + version);
|
||||
run();
|
||||
}
|
||||
}
|
||||
|
||||
private void testSpdyEcho(final int version) throws Throwable {
|
||||
public void testSpdyEcho(ServerBootstrap sb, Bootstrap cb) throws Throwable {
|
||||
|
||||
ChannelBuffer frames = createFrames(version);
|
||||
|
Loading…
Reference in New Issue
Block a user