Run tests with Pooled and Unpooled allocator
This commit is contained in:
parent
9b625d611f
commit
9600318dc1
@ -17,6 +17,8 @@ package io.netty.testsuite.transport.sctp;
|
||||
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
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.util.TestUtils;
|
||||
import io.netty.util.NetUtil;
|
||||
@ -35,6 +37,7 @@ public abstract class AbstractSctpTest {
|
||||
|
||||
private static final List<Entry<Factory<ServerBootstrap>, Factory<Bootstrap>>> COMBO =
|
||||
SctpTestPermutation.sctpChannel();
|
||||
private static List<ByteBufAllocator> ALLOCATORS = SctpTestPermutation.allocator();
|
||||
|
||||
@Rule
|
||||
public final TestName testName = new TestName();
|
||||
@ -47,24 +50,29 @@ public abstract class AbstractSctpTest {
|
||||
protected volatile Factory<Bootstrap> currentBootstrap;
|
||||
|
||||
protected void run() throws Throwable {
|
||||
int i = 0;
|
||||
for (Entry<Factory<ServerBootstrap>, Factory<Bootstrap>> e: COMBO) {
|
||||
currentBootstrap = e.getValue();
|
||||
sb = e.getKey().newInstance();
|
||||
cb = e.getValue().newInstance();
|
||||
addr = new InetSocketAddress(
|
||||
NetUtil.LOCALHOST, TestUtils.getFreePort());
|
||||
sb.localAddress(addr);
|
||||
cb.remoteAddress(addr);
|
||||
|
||||
logger.info(String.format(
|
||||
"Running: %s %d of %d (%s + %s)", testName.getMethodName(), ++ i, COMBO.size(), sb, cb));
|
||||
try {
|
||||
Method m = getClass().getDeclaredMethod(
|
||||
testName.getMethodName(), ServerBootstrap.class, Bootstrap.class);
|
||||
m.invoke(this, sb, cb);
|
||||
} catch (InvocationTargetException ex) {
|
||||
throw ex.getCause();
|
||||
for (ByteBufAllocator allocator: ALLOCATORS) {
|
||||
int i = 0;
|
||||
for (Entry<Factory<ServerBootstrap>, Factory<Bootstrap>> e: COMBO) {
|
||||
currentBootstrap = e.getValue();
|
||||
sb = e.getKey().newInstance();
|
||||
cb = e.getValue().newInstance();
|
||||
addr = new InetSocketAddress(
|
||||
NetUtil.LOCALHOST, TestUtils.getFreePort());
|
||||
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(
|
||||
"Running: %s %d of %d (%s + %s) with %s",
|
||||
testName.getMethodName(), ++ i, COMBO.size(), sb, cb, allocator.getClass().getSimpleName()));
|
||||
try {
|
||||
Method m = getClass().getDeclaredMethod(
|
||||
testName.getMethodName(), ServerBootstrap.class, Bootstrap.class);
|
||||
m.invoke(this, sb, cb);
|
||||
} catch (InvocationTargetException ex) {
|
||||
throw ex.getCause();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,9 @@ package io.netty.testsuite.transport.sctp;
|
||||
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
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.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.oio.OioEventLoopGroup;
|
||||
@ -130,6 +133,13 @@ public final class SctpTestPermutation {
|
||||
return list;
|
||||
}
|
||||
|
||||
static List<ByteBufAllocator> allocator() {
|
||||
List<ByteBufAllocator> allocators = new ArrayList<ByteBufAllocator>();
|
||||
allocators.add(UnpooledByteBufAllocator.DEFAULT);
|
||||
allocators.add(PooledByteBufAllocator.DEFAULT);
|
||||
return allocators;
|
||||
}
|
||||
|
||||
private SctpTestPermutation() { }
|
||||
|
||||
interface Factory<T> {
|
||||
|
@ -16,6 +16,8 @@
|
||||
package io.netty.testsuite.transport.socket;
|
||||
|
||||
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.util.TestUtils;
|
||||
import io.netty.util.NetUtil;
|
||||
@ -32,6 +34,7 @@ import java.util.List;
|
||||
public abstract class AbstractClientSocketTest {
|
||||
|
||||
private static final List<Factory<Bootstrap>> COMBO = SocketTestPermutation.clientSocket();
|
||||
private static final List<ByteBufAllocator> ALLOCATORS = SocketTestPermutation.allocator();
|
||||
|
||||
@Rule
|
||||
public final TestName testName = new TestName();
|
||||
@ -42,20 +45,23 @@ public abstract class AbstractClientSocketTest {
|
||||
protected volatile InetSocketAddress addr;
|
||||
|
||||
protected void run() throws Throwable {
|
||||
int i = 0;
|
||||
for (Factory<Bootstrap> e: COMBO) {
|
||||
cb = e.newInstance();
|
||||
addr = new InetSocketAddress(NetUtil.LOCALHOST, TestUtils.getFreePort());
|
||||
cb.remoteAddress(addr);
|
||||
|
||||
logger.info(String.format(
|
||||
"Running: %s %d of %d", testName.getMethodName(), ++ i, COMBO.size()));
|
||||
try {
|
||||
Method m = getClass().getDeclaredMethod(
|
||||
testName.getMethodName(), Bootstrap.class);
|
||||
m.invoke(this, cb);
|
||||
} catch (InvocationTargetException ex) {
|
||||
throw ex.getCause();
|
||||
for (ByteBufAllocator allocator: ALLOCATORS) {
|
||||
int i = 0;
|
||||
for (Factory<Bootstrap> e: COMBO) {
|
||||
cb = e.newInstance();
|
||||
addr = new InetSocketAddress(NetUtil.LOCALHOST, TestUtils.getFreePort());
|
||||
cb.remoteAddress(addr);
|
||||
cb.option(ChannelOption.ALLOCATOR, allocator);
|
||||
logger.info(String.format(
|
||||
"Running: %s %d of %d with %s",
|
||||
testName.getMethodName(), ++ i, COMBO.size(), allocator.getClass().getSimpleName()));
|
||||
try {
|
||||
Method m = getClass().getDeclaredMethod(
|
||||
testName.getMethodName(), Bootstrap.class);
|
||||
m.invoke(this, cb);
|
||||
} catch (InvocationTargetException ex) {
|
||||
throw ex.getCause();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,8 @@
|
||||
package io.netty.testsuite.transport.socket;
|
||||
|
||||
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.util.TestUtils;
|
||||
import io.netty.util.NetUtil;
|
||||
@ -33,6 +35,7 @@ import java.util.Map.Entry;
|
||||
public abstract class AbstractDatagramTest {
|
||||
|
||||
private static final List<Entry<Factory<Bootstrap>, Factory<Bootstrap>>> COMBO = SocketTestPermutation.datagram();
|
||||
private static final List<ByteBufAllocator> ALLOCATORS = SocketTestPermutation.allocator();
|
||||
|
||||
@Rule
|
||||
public final TestName testName = new TestName();
|
||||
@ -44,23 +47,27 @@ public abstract class AbstractDatagramTest {
|
||||
protected volatile InetSocketAddress addr;
|
||||
|
||||
protected void run() throws Throwable {
|
||||
int i = 0;
|
||||
for (Entry<Factory<Bootstrap>, Factory<Bootstrap>> e: COMBO) {
|
||||
sb = e.getKey().newInstance();
|
||||
cb = e.getValue().newInstance();
|
||||
addr = new InetSocketAddress(
|
||||
NetUtil.LOCALHOST4, TestUtils.getFreePort());
|
||||
sb.localAddress(addr);
|
||||
cb.localAddress(0).remoteAddress(addr);
|
||||
|
||||
logger.info(String.format(
|
||||
"Running: %s %d of %d (%s + %s)", testName.getMethodName(), ++ i, COMBO.size(), sb, cb));
|
||||
try {
|
||||
Method m = getClass().getDeclaredMethod(
|
||||
testName.getMethodName(), Bootstrap.class, Bootstrap.class);
|
||||
m.invoke(this, sb, cb);
|
||||
} catch (InvocationTargetException ex) {
|
||||
throw ex.getCause();
|
||||
for (ByteBufAllocator allocator: ALLOCATORS) {
|
||||
int i = 0;
|
||||
for (Entry<Factory<Bootstrap>, Factory<Bootstrap>> e: COMBO) {
|
||||
sb = e.getKey().newInstance();
|
||||
cb = e.getValue().newInstance();
|
||||
addr = new InetSocketAddress(
|
||||
NetUtil.LOCALHOST4, TestUtils.getFreePort());
|
||||
sb.localAddress(addr);
|
||||
sb.option(ChannelOption.ALLOCATOR, allocator);
|
||||
cb.localAddress(0).remoteAddress(addr);
|
||||
cb.option(ChannelOption.ALLOCATOR, allocator);
|
||||
logger.info(String.format(
|
||||
"Running: %s %d of %d (%s + %s) with %s",
|
||||
testName.getMethodName(), ++ i, COMBO.size(), sb, cb, allocator.getClass().getSimpleName()));
|
||||
try {
|
||||
Method m = getClass().getDeclaredMethod(
|
||||
testName.getMethodName(), Bootstrap.class, Bootstrap.class);
|
||||
m.invoke(this, sb, cb);
|
||||
} catch (InvocationTargetException ex) {
|
||||
throw ex.getCause();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,8 @@
|
||||
package io.netty.testsuite.transport.socket;
|
||||
|
||||
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.util.TestUtils;
|
||||
import io.netty.util.NetUtil;
|
||||
@ -32,6 +34,7 @@ import java.util.List;
|
||||
public abstract class AbstractServerSocketTest {
|
||||
|
||||
private static final List<Factory<ServerBootstrap>> COMBO = SocketTestPermutation.serverSocket();
|
||||
private static final List<ByteBufAllocator> ALLOCATORS = SocketTestPermutation.allocator();
|
||||
|
||||
@Rule
|
||||
public final TestName testName = new TestName();
|
||||
@ -42,21 +45,26 @@ public abstract class AbstractServerSocketTest {
|
||||
protected volatile InetSocketAddress addr;
|
||||
|
||||
protected void run() throws Throwable {
|
||||
int i = 0;
|
||||
for (Factory<ServerBootstrap> e: COMBO) {
|
||||
sb = e.newInstance();
|
||||
addr = new InetSocketAddress(
|
||||
NetUtil.LOCALHOST, TestUtils.getFreePort());
|
||||
sb.localAddress(addr);
|
||||
for (ByteBufAllocator allocator: ALLOCATORS) {
|
||||
int i = 0;
|
||||
for (Factory<ServerBootstrap> e: COMBO) {
|
||||
sb = e.newInstance();
|
||||
addr = new InetSocketAddress(
|
||||
NetUtil.LOCALHOST, TestUtils.getFreePort());
|
||||
sb.localAddress(addr);
|
||||
sb.option(ChannelOption.ALLOCATOR, allocator);
|
||||
sb.childOption(ChannelOption.ALLOCATOR, allocator);
|
||||
|
||||
logger.info(String.format(
|
||||
"Running: %s %d of %d (%s)", testName.getMethodName(), ++ i, COMBO.size(), sb));
|
||||
try {
|
||||
Method m = getClass().getDeclaredMethod(
|
||||
testName.getMethodName(), ServerBootstrap.class);
|
||||
m.invoke(this, sb);
|
||||
} catch (InvocationTargetException ex) {
|
||||
throw ex.getCause();
|
||||
logger.info(String.format(
|
||||
"Running: %s %d of %d (%s) with %s",
|
||||
testName.getMethodName(), ++ i, COMBO.size(), sb, allocator.getClass().getSimpleName()));
|
||||
try {
|
||||
Method m = getClass().getDeclaredMethod(
|
||||
testName.getMethodName(), ServerBootstrap.class);
|
||||
m.invoke(this, sb);
|
||||
} catch (InvocationTargetException ex) {
|
||||
throw ex.getCause();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,8 @@ package io.netty.testsuite.transport.socket;
|
||||
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
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.util.TestUtils;
|
||||
import io.netty.util.NetUtil;
|
||||
@ -36,6 +38,8 @@ public abstract class AbstractSocketTest {
|
||||
private static final List<Entry<Factory<ServerBootstrap>, Factory<Bootstrap>>> COMBO =
|
||||
SocketTestPermutation.socket();
|
||||
|
||||
private static final List<ByteBufAllocator> ALLOCATORS = SocketTestPermutation.allocator();
|
||||
|
||||
@Rule
|
||||
public final TestName testName = new TestName();
|
||||
|
||||
@ -47,24 +51,30 @@ public abstract class AbstractSocketTest {
|
||||
protected volatile Factory<Bootstrap> currentBootstrap;
|
||||
|
||||
protected void run() throws Throwable {
|
||||
int i = 0;
|
||||
for (Entry<Factory<ServerBootstrap>, Factory<Bootstrap>> e: COMBO) {
|
||||
currentBootstrap = e.getValue();
|
||||
sb = e.getKey().newInstance();
|
||||
cb = e.getValue().newInstance();
|
||||
addr = new InetSocketAddress(
|
||||
NetUtil.LOCALHOST, TestUtils.getFreePort());
|
||||
sb.localAddress(addr);
|
||||
cb.remoteAddress(addr);
|
||||
for (ByteBufAllocator allocator: ALLOCATORS) {
|
||||
int i = 0;
|
||||
for (Entry<Factory<ServerBootstrap>, Factory<Bootstrap>> e: COMBO) {
|
||||
currentBootstrap = e.getValue();
|
||||
sb = e.getKey().newInstance();
|
||||
cb = e.getValue().newInstance();
|
||||
addr = new InetSocketAddress(
|
||||
NetUtil.LOCALHOST, TestUtils.getFreePort());
|
||||
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(
|
||||
"Running: %s %d of %d (%s + %s)", testName.getMethodName(), ++ i, COMBO.size(), sb, cb));
|
||||
try {
|
||||
Method m = getClass().getDeclaredMethod(
|
||||
testName.getMethodName(), ServerBootstrap.class, Bootstrap.class);
|
||||
m.invoke(this, sb, cb);
|
||||
} catch (InvocationTargetException ex) {
|
||||
throw ex.getCause();
|
||||
logger.info(String.format(
|
||||
"Running: %s %d of %d (%s + %s) with %s",
|
||||
testName.getMethodName(), ++ i, COMBO.size(), sb, cb, allocator.getClass().getSimpleName()));
|
||||
try {
|
||||
Method m = getClass().getDeclaredMethod(
|
||||
testName.getMethodName(), ServerBootstrap.class, Bootstrap.class);
|
||||
m.invoke(this, sb, cb);
|
||||
} catch (InvocationTargetException ex) {
|
||||
throw ex.getCause();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -84,7 +84,8 @@ public class SocketBufReleaseTest extends AbstractSocketTest {
|
||||
random.nextBytes(data);
|
||||
|
||||
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() {
|
||||
@Override
|
||||
@ -101,7 +102,7 @@ public class SocketBufReleaseTest extends AbstractSocketTest {
|
||||
|
||||
public void check() throws InterruptedException {
|
||||
latch.await();
|
||||
assertEquals(0, buf.refCnt());
|
||||
assertEquals(1, buf.refCnt());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,9 @@ package io.netty.testsuite.transport.socket;
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.bootstrap.ChannelFactory;
|
||||
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.EventLoop;
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
@ -183,6 +186,13 @@ final class SocketTestPermutation {
|
||||
return list;
|
||||
}
|
||||
|
||||
static List<ByteBufAllocator> allocator() {
|
||||
List<ByteBufAllocator> allocators = new ArrayList<ByteBufAllocator>();
|
||||
allocators.add(UnpooledByteBufAllocator.DEFAULT);
|
||||
allocators.add(PooledByteBufAllocator.DEFAULT);
|
||||
return allocators;
|
||||
}
|
||||
|
||||
private SocketTestPermutation() { }
|
||||
|
||||
interface Factory<T> {
|
||||
|
Loading…
Reference in New Issue
Block a user