Run tests with Pooled and Unpooled allocator

This commit is contained in:
Norman Maurer 2013-10-16 11:51:16 +02:00
parent 9b625d611f
commit 9600318dc1
8 changed files with 142 additions and 82 deletions

View File

@ -17,6 +17,8 @@ package io.netty.testsuite.transport.sctp;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelOption;
import io.netty.testsuite.transport.sctp.SctpTestPermutation.Factory; import io.netty.testsuite.transport.sctp.SctpTestPermutation.Factory;
import io.netty.testsuite.util.TestUtils; import io.netty.testsuite.util.TestUtils;
import io.netty.util.NetUtil; import io.netty.util.NetUtil;
@ -35,6 +37,7 @@ public abstract class AbstractSctpTest {
private static final List<Entry<Factory<ServerBootstrap>, Factory<Bootstrap>>> COMBO = private static final List<Entry<Factory<ServerBootstrap>, Factory<Bootstrap>>> COMBO =
SctpTestPermutation.sctpChannel(); SctpTestPermutation.sctpChannel();
private static List<ByteBufAllocator> ALLOCATORS = SctpTestPermutation.allocator();
@Rule @Rule
public final TestName testName = new TestName(); public final TestName testName = new TestName();
@ -47,24 +50,29 @@ public abstract class AbstractSctpTest {
protected volatile Factory<Bootstrap> currentBootstrap; protected volatile Factory<Bootstrap> currentBootstrap;
protected void run() throws Throwable { protected void run() throws Throwable {
int i = 0; for (ByteBufAllocator allocator: ALLOCATORS) {
for (Entry<Factory<ServerBootstrap>, Factory<Bootstrap>> e: COMBO) { int i = 0;
currentBootstrap = e.getValue(); for (Entry<Factory<ServerBootstrap>, Factory<Bootstrap>> e: COMBO) {
sb = e.getKey().newInstance(); currentBootstrap = e.getValue();
cb = e.getValue().newInstance(); sb = e.getKey().newInstance();
addr = new InetSocketAddress( cb = e.getValue().newInstance();
NetUtil.LOCALHOST, TestUtils.getFreePort()); addr = new InetSocketAddress(
sb.localAddress(addr); NetUtil.LOCALHOST, TestUtils.getFreePort());
cb.remoteAddress(addr); sb.localAddress(addr);
sb.option(ChannelOption.ALLOCATOR, allocator);
logger.info(String.format( sb.childOption(ChannelOption.ALLOCATOR, allocator);
"Running: %s %d of %d (%s + %s)", testName.getMethodName(), ++ i, COMBO.size(), sb, cb)); cb.remoteAddress(addr);
try { cb.option(ChannelOption.ALLOCATOR, allocator);
Method m = getClass().getDeclaredMethod( logger.info(String.format(
testName.getMethodName(), ServerBootstrap.class, Bootstrap.class); "Running: %s %d of %d (%s + %s) with %s",
m.invoke(this, sb, cb); testName.getMethodName(), ++ i, COMBO.size(), sb, cb, allocator.getClass().getSimpleName()));
} catch (InvocationTargetException ex) { try {
throw ex.getCause(); Method m = getClass().getDeclaredMethod(
testName.getMethodName(), ServerBootstrap.class, Bootstrap.class);
m.invoke(this, sb, cb);
} catch (InvocationTargetException ex) {
throw ex.getCause();
}
} }
} }
} }

View File

@ -17,6 +17,9 @@ package io.netty.testsuite.transport.sctp;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.buffer.UnpooledByteBufAllocator;
import io.netty.channel.EventLoopGroup; import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.oio.OioEventLoopGroup; import io.netty.channel.oio.OioEventLoopGroup;
@ -130,6 +133,13 @@ public final class SctpTestPermutation {
return list; return list;
} }
static List<ByteBufAllocator> allocator() {
List<ByteBufAllocator> allocators = new ArrayList<ByteBufAllocator>();
allocators.add(UnpooledByteBufAllocator.DEFAULT);
allocators.add(PooledByteBufAllocator.DEFAULT);
return allocators;
}
private SctpTestPermutation() { } private SctpTestPermutation() { }
interface Factory<T> { interface Factory<T> {

View File

@ -16,6 +16,8 @@
package io.netty.testsuite.transport.socket; package io.netty.testsuite.transport.socket;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelOption;
import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory; import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory;
import io.netty.testsuite.util.TestUtils; import io.netty.testsuite.util.TestUtils;
import io.netty.util.NetUtil; import io.netty.util.NetUtil;
@ -32,6 +34,7 @@ import java.util.List;
public abstract class AbstractClientSocketTest { public abstract class AbstractClientSocketTest {
private static final List<Factory<Bootstrap>> COMBO = SocketTestPermutation.clientSocket(); private static final List<Factory<Bootstrap>> COMBO = SocketTestPermutation.clientSocket();
private static final List<ByteBufAllocator> ALLOCATORS = SocketTestPermutation.allocator();
@Rule @Rule
public final TestName testName = new TestName(); public final TestName testName = new TestName();
@ -42,20 +45,23 @@ public abstract class AbstractClientSocketTest {
protected volatile InetSocketAddress addr; protected volatile InetSocketAddress addr;
protected void run() throws Throwable { protected void run() throws Throwable {
int i = 0; for (ByteBufAllocator allocator: ALLOCATORS) {
for (Factory<Bootstrap> e: COMBO) { int i = 0;
cb = e.newInstance(); for (Factory<Bootstrap> e: COMBO) {
addr = new InetSocketAddress(NetUtil.LOCALHOST, TestUtils.getFreePort()); cb = e.newInstance();
cb.remoteAddress(addr); addr = new InetSocketAddress(NetUtil.LOCALHOST, TestUtils.getFreePort());
cb.remoteAddress(addr);
logger.info(String.format( cb.option(ChannelOption.ALLOCATOR, allocator);
"Running: %s %d of %d", testName.getMethodName(), ++ i, COMBO.size())); logger.info(String.format(
try { "Running: %s %d of %d with %s",
Method m = getClass().getDeclaredMethod( testName.getMethodName(), ++ i, COMBO.size(), allocator.getClass().getSimpleName()));
testName.getMethodName(), Bootstrap.class); try {
m.invoke(this, cb); Method m = getClass().getDeclaredMethod(
} catch (InvocationTargetException ex) { testName.getMethodName(), Bootstrap.class);
throw ex.getCause(); m.invoke(this, cb);
} catch (InvocationTargetException ex) {
throw ex.getCause();
}
} }
} }
} }

View File

@ -16,6 +16,8 @@
package io.netty.testsuite.transport.socket; package io.netty.testsuite.transport.socket;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelOption;
import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory; import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory;
import io.netty.testsuite.util.TestUtils; import io.netty.testsuite.util.TestUtils;
import io.netty.util.NetUtil; import io.netty.util.NetUtil;
@ -33,6 +35,7 @@ import java.util.Map.Entry;
public abstract class AbstractDatagramTest { public abstract class AbstractDatagramTest {
private static final List<Entry<Factory<Bootstrap>, Factory<Bootstrap>>> COMBO = SocketTestPermutation.datagram(); private static final List<Entry<Factory<Bootstrap>, Factory<Bootstrap>>> COMBO = SocketTestPermutation.datagram();
private static final List<ByteBufAllocator> ALLOCATORS = SocketTestPermutation.allocator();
@Rule @Rule
public final TestName testName = new TestName(); public final TestName testName = new TestName();
@ -44,23 +47,27 @@ public abstract class AbstractDatagramTest {
protected volatile InetSocketAddress addr; protected volatile InetSocketAddress addr;
protected void run() throws Throwable { protected void run() throws Throwable {
int i = 0; for (ByteBufAllocator allocator: ALLOCATORS) {
for (Entry<Factory<Bootstrap>, Factory<Bootstrap>> e: COMBO) { int i = 0;
sb = e.getKey().newInstance(); for (Entry<Factory<Bootstrap>, Factory<Bootstrap>> e: COMBO) {
cb = e.getValue().newInstance(); sb = e.getKey().newInstance();
addr = new InetSocketAddress( cb = e.getValue().newInstance();
NetUtil.LOCALHOST4, TestUtils.getFreePort()); addr = new InetSocketAddress(
sb.localAddress(addr); NetUtil.LOCALHOST4, TestUtils.getFreePort());
cb.localAddress(0).remoteAddress(addr); sb.localAddress(addr);
sb.option(ChannelOption.ALLOCATOR, allocator);
logger.info(String.format( cb.localAddress(0).remoteAddress(addr);
"Running: %s %d of %d (%s + %s)", testName.getMethodName(), ++ i, COMBO.size(), sb, cb)); cb.option(ChannelOption.ALLOCATOR, allocator);
try { logger.info(String.format(
Method m = getClass().getDeclaredMethod( "Running: %s %d of %d (%s + %s) with %s",
testName.getMethodName(), Bootstrap.class, Bootstrap.class); testName.getMethodName(), ++ i, COMBO.size(), sb, cb, allocator.getClass().getSimpleName()));
m.invoke(this, sb, cb); try {
} catch (InvocationTargetException ex) { Method m = getClass().getDeclaredMethod(
throw ex.getCause(); testName.getMethodName(), Bootstrap.class, Bootstrap.class);
m.invoke(this, sb, cb);
} catch (InvocationTargetException ex) {
throw ex.getCause();
}
} }
} }
} }

View File

@ -16,6 +16,8 @@
package io.netty.testsuite.transport.socket; package io.netty.testsuite.transport.socket;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelOption;
import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory; import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory;
import io.netty.testsuite.util.TestUtils; import io.netty.testsuite.util.TestUtils;
import io.netty.util.NetUtil; import io.netty.util.NetUtil;
@ -32,6 +34,7 @@ import java.util.List;
public abstract class AbstractServerSocketTest { public abstract class AbstractServerSocketTest {
private static final List<Factory<ServerBootstrap>> COMBO = SocketTestPermutation.serverSocket(); private static final List<Factory<ServerBootstrap>> COMBO = SocketTestPermutation.serverSocket();
private static final List<ByteBufAllocator> ALLOCATORS = SocketTestPermutation.allocator();
@Rule @Rule
public final TestName testName = new TestName(); public final TestName testName = new TestName();
@ -42,21 +45,26 @@ public abstract class AbstractServerSocketTest {
protected volatile InetSocketAddress addr; protected volatile InetSocketAddress addr;
protected void run() throws Throwable { protected void run() throws Throwable {
int i = 0; for (ByteBufAllocator allocator: ALLOCATORS) {
for (Factory<ServerBootstrap> e: COMBO) { int i = 0;
sb = e.newInstance(); for (Factory<ServerBootstrap> e: COMBO) {
addr = new InetSocketAddress( sb = e.newInstance();
NetUtil.LOCALHOST, TestUtils.getFreePort()); addr = new InetSocketAddress(
sb.localAddress(addr); NetUtil.LOCALHOST, TestUtils.getFreePort());
sb.localAddress(addr);
sb.option(ChannelOption.ALLOCATOR, allocator);
sb.childOption(ChannelOption.ALLOCATOR, allocator);
logger.info(String.format( logger.info(String.format(
"Running: %s %d of %d (%s)", testName.getMethodName(), ++ i, COMBO.size(), sb)); "Running: %s %d of %d (%s) with %s",
try { testName.getMethodName(), ++ i, COMBO.size(), sb, allocator.getClass().getSimpleName()));
Method m = getClass().getDeclaredMethod( try {
testName.getMethodName(), ServerBootstrap.class); Method m = getClass().getDeclaredMethod(
m.invoke(this, sb); testName.getMethodName(), ServerBootstrap.class);
} catch (InvocationTargetException ex) { m.invoke(this, sb);
throw ex.getCause(); } catch (InvocationTargetException ex) {
throw ex.getCause();
}
} }
} }
} }

View File

@ -17,6 +17,8 @@ package io.netty.testsuite.transport.socket;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelOption;
import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory; import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory;
import io.netty.testsuite.util.TestUtils; import io.netty.testsuite.util.TestUtils;
import io.netty.util.NetUtil; import io.netty.util.NetUtil;
@ -36,6 +38,8 @@ public abstract class AbstractSocketTest {
private static final List<Entry<Factory<ServerBootstrap>, Factory<Bootstrap>>> COMBO = private static final List<Entry<Factory<ServerBootstrap>, Factory<Bootstrap>>> COMBO =
SocketTestPermutation.socket(); SocketTestPermutation.socket();
private static final List<ByteBufAllocator> ALLOCATORS = SocketTestPermutation.allocator();
@Rule @Rule
public final TestName testName = new TestName(); public final TestName testName = new TestName();
@ -47,24 +51,30 @@ public abstract class AbstractSocketTest {
protected volatile Factory<Bootstrap> currentBootstrap; protected volatile Factory<Bootstrap> currentBootstrap;
protected void run() throws Throwable { protected void run() throws Throwable {
int i = 0; for (ByteBufAllocator allocator: ALLOCATORS) {
for (Entry<Factory<ServerBootstrap>, Factory<Bootstrap>> e: COMBO) { int i = 0;
currentBootstrap = e.getValue(); for (Entry<Factory<ServerBootstrap>, Factory<Bootstrap>> e: COMBO) {
sb = e.getKey().newInstance(); currentBootstrap = e.getValue();
cb = e.getValue().newInstance(); sb = e.getKey().newInstance();
addr = new InetSocketAddress( cb = e.getValue().newInstance();
NetUtil.LOCALHOST, TestUtils.getFreePort()); addr = new InetSocketAddress(
sb.localAddress(addr); NetUtil.LOCALHOST, TestUtils.getFreePort());
cb.remoteAddress(addr); sb.localAddress(addr);
sb.option(ChannelOption.ALLOCATOR, allocator);
sb.childOption(ChannelOption.ALLOCATOR, allocator);
cb.remoteAddress(addr);
cb.option(ChannelOption.ALLOCATOR, allocator);
logger.info(String.format( logger.info(String.format(
"Running: %s %d of %d (%s + %s)", testName.getMethodName(), ++ i, COMBO.size(), sb, cb)); "Running: %s %d of %d (%s + %s) with %s",
try { testName.getMethodName(), ++ i, COMBO.size(), sb, cb, allocator.getClass().getSimpleName()));
Method m = getClass().getDeclaredMethod( try {
testName.getMethodName(), ServerBootstrap.class, Bootstrap.class); Method m = getClass().getDeclaredMethod(
m.invoke(this, sb, cb); testName.getMethodName(), ServerBootstrap.class, Bootstrap.class);
} catch (InvocationTargetException ex) { m.invoke(this, sb, cb);
throw ex.getCause(); } catch (InvocationTargetException ex) {
throw ex.getCause();
}
} }
} }
} }

View File

@ -84,7 +84,8 @@ public class SocketBufReleaseTest extends AbstractSocketTest {
random.nextBytes(data); random.nextBytes(data);
buf = ctx.alloc().buffer(); buf = ctx.alloc().buffer();
buf.writeBytes(data); // call retain on it so it can't be put back on the pool
buf.writeBytes(data).retain();
ctx.channel().writeAndFlush(buf).addListener(new ChannelFutureListener() { ctx.channel().writeAndFlush(buf).addListener(new ChannelFutureListener() {
@Override @Override
@ -101,7 +102,7 @@ public class SocketBufReleaseTest extends AbstractSocketTest {
public void check() throws InterruptedException { public void check() throws InterruptedException {
latch.await(); latch.await();
assertEquals(0, buf.refCnt()); assertEquals(1, buf.refCnt());
} }
} }
} }

View File

@ -18,6 +18,9 @@ package io.netty.testsuite.transport.socket;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ChannelFactory; import io.netty.bootstrap.ChannelFactory;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.buffer.UnpooledByteBufAllocator;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.EventLoop; import io.netty.channel.EventLoop;
import io.netty.channel.EventLoopGroup; import io.netty.channel.EventLoopGroup;
@ -183,6 +186,13 @@ final class SocketTestPermutation {
return list; return list;
} }
static List<ByteBufAllocator> allocator() {
List<ByteBufAllocator> allocators = new ArrayList<ByteBufAllocator>();
allocators.add(UnpooledByteBufAllocator.DEFAULT);
allocators.add(PooledByteBufAllocator.DEFAULT);
return allocators;
}
private SocketTestPermutation() { } private SocketTestPermutation() { }
interface Factory<T> { interface Factory<T> {