Replace LocalEventLoopGroup with DefaultEventLoopGroup
Motivation: LocalEventLoopGroup and LocalEventLoop are not really special for LocalChannels. It can be used for other channel implementations as long as they don't require special handling. Modifications: - Add DefaultEventLoopGroup and DefaultEventLoop - Deprecate LocalEventLoopGroup and make it extend DefaultEventLoopGroup - Add DefaultEventLoop and remove LocalEventLoop - Fix inspector warnings Result: - Better class names.
This commit is contained in:
parent
924113ce8c
commit
1e3b7d8273
@ -20,10 +20,10 @@ import io.netty.bootstrap.ServerBootstrap;
|
|||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
|
import io.netty.channel.DefaultEventLoopGroup;
|
||||||
import io.netty.channel.EventLoopGroup;
|
import io.netty.channel.EventLoopGroup;
|
||||||
import io.netty.channel.local.LocalAddress;
|
import io.netty.channel.local.LocalAddress;
|
||||||
import io.netty.channel.local.LocalChannel;
|
import io.netty.channel.local.LocalChannel;
|
||||||
import io.netty.channel.local.LocalEventLoopGroup;
|
|
||||||
import io.netty.channel.local.LocalServerChannel;
|
import io.netty.channel.local.LocalServerChannel;
|
||||||
import io.netty.channel.nio.NioEventLoopGroup;
|
import io.netty.channel.nio.NioEventLoopGroup;
|
||||||
import io.netty.handler.logging.LogLevel;
|
import io.netty.handler.logging.LogLevel;
|
||||||
@ -44,7 +44,7 @@ public class LocalEcho {
|
|||||||
// Address to bind on / connect to.
|
// Address to bind on / connect to.
|
||||||
final LocalAddress addr = new LocalAddress(port);
|
final LocalAddress addr = new LocalAddress(port);
|
||||||
|
|
||||||
EventLoopGroup serverGroup = new LocalEventLoopGroup();
|
EventLoopGroup serverGroup = new DefaultEventLoopGroup();
|
||||||
EventLoopGroup clientGroup = new NioEventLoopGroup(); // NIO event loops are also OK
|
EventLoopGroup clientGroup = new NioEventLoopGroup(); // NIO event loops are also OK
|
||||||
try {
|
try {
|
||||||
// Note that we can use any event loop to ensure certain local channels
|
// Note that we can use any event loop to ensure certain local channels
|
||||||
|
@ -13,15 +13,36 @@
|
|||||||
* License for the specific language governing permissions and limitations
|
* License for the specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
package io.netty.channel.local;
|
package io.netty.channel;
|
||||||
|
|
||||||
import io.netty.channel.SingleThreadEventLoop;
|
import io.netty.util.concurrent.DefaultThreadFactory;
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.concurrent.ThreadFactory;
|
||||||
|
|
||||||
final class LocalEventLoop extends SingleThreadEventLoop {
|
public class DefaultEventLoop extends SingleThreadEventLoop {
|
||||||
|
|
||||||
LocalEventLoop(LocalEventLoopGroup parent, Executor executor) {
|
public DefaultEventLoop() {
|
||||||
|
this((EventLoopGroup) null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DefaultEventLoop(ThreadFactory threadFactory) {
|
||||||
|
this(null, threadFactory);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DefaultEventLoop(Executor executor) {
|
||||||
|
this(null, executor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DefaultEventLoop(EventLoopGroup parent) {
|
||||||
|
this(parent, new DefaultThreadFactory(DefaultEventLoop.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
public DefaultEventLoop(EventLoopGroup parent, ThreadFactory threadFactory) {
|
||||||
|
super(parent, threadFactory, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DefaultEventLoop(EventLoopGroup parent, Executor executor) {
|
||||||
super(parent, executor, true);
|
super(parent, executor, true);
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* 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.channel;
|
||||||
|
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.concurrent.ThreadFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link MultithreadEventLoopGroup} which must be used for the local transport.
|
||||||
|
*/
|
||||||
|
public class DefaultEventLoopGroup extends MultithreadEventLoopGroup {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance with the default number of threads.
|
||||||
|
*/
|
||||||
|
public DefaultEventLoopGroup() {
|
||||||
|
this(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance
|
||||||
|
*
|
||||||
|
* @param nThreads the number of threads to use
|
||||||
|
*/
|
||||||
|
public DefaultEventLoopGroup(int nThreads) {
|
||||||
|
this(nThreads, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance
|
||||||
|
*
|
||||||
|
* @param nThreads the number of threads to use
|
||||||
|
* @param threadFactory the {@link ThreadFactory} or {@code null} to use the default
|
||||||
|
*/
|
||||||
|
public DefaultEventLoopGroup(int nThreads, ThreadFactory threadFactory) {
|
||||||
|
super(nThreads, threadFactory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected EventLoop newChild(Executor executor, Object... args) throws Exception {
|
||||||
|
return new DefaultEventLoop(this, executor);
|
||||||
|
}
|
||||||
|
}
|
@ -15,23 +15,20 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.channel.local;
|
package io.netty.channel.local;
|
||||||
|
|
||||||
import io.netty.channel.MultithreadEventLoopGroup;
|
import io.netty.channel.DefaultEventLoopGroup;
|
||||||
import io.netty.util.concurrent.EventExecutor;
|
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
import java.util.concurrent.ThreadFactory;
|
import java.util.concurrent.ThreadFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link MultithreadEventLoopGroup} which must be used for the local transport.
|
* @deprecated Use {@link DefaultEventLoopGroup} instead.
|
||||||
*/
|
*/
|
||||||
public class LocalEventLoopGroup extends MultithreadEventLoopGroup {
|
@Deprecated
|
||||||
|
public class LocalEventLoopGroup extends DefaultEventLoopGroup {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance with the default number of threads.
|
* Create a new instance with the default number of threads.
|
||||||
*/
|
*/
|
||||||
public LocalEventLoopGroup() {
|
public LocalEventLoopGroup() { }
|
||||||
this(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance
|
* Create a new instance
|
||||||
@ -39,7 +36,7 @@ public class LocalEventLoopGroup extends MultithreadEventLoopGroup {
|
|||||||
* @param nThreads the number of threads to use
|
* @param nThreads the number of threads to use
|
||||||
*/
|
*/
|
||||||
public LocalEventLoopGroup(int nThreads) {
|
public LocalEventLoopGroup(int nThreads) {
|
||||||
this(nThreads, null);
|
super(nThreads);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -51,10 +48,4 @@ public class LocalEventLoopGroup extends MultithreadEventLoopGroup {
|
|||||||
public LocalEventLoopGroup(int nThreads, ThreadFactory threadFactory) {
|
public LocalEventLoopGroup(int nThreads, ThreadFactory threadFactory) {
|
||||||
super(nThreads, threadFactory);
|
super(nThreads, threadFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected EventExecutor newChild(
|
|
||||||
Executor executor, Object... args) throws Exception {
|
|
||||||
return new LocalEventLoop(this, executor);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -19,10 +19,10 @@ package io.netty.bootstrap;
|
|||||||
import io.netty.channel.ChannelHandler.Sharable;
|
import io.netty.channel.ChannelHandler.Sharable;
|
||||||
import io.netty.channel.ChannelInboundHandler;
|
import io.netty.channel.ChannelInboundHandler;
|
||||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||||
|
import io.netty.channel.DefaultEventLoopGroup;
|
||||||
import io.netty.channel.EventLoopGroup;
|
import io.netty.channel.EventLoopGroup;
|
||||||
import io.netty.channel.local.LocalAddress;
|
import io.netty.channel.local.LocalAddress;
|
||||||
import io.netty.channel.local.LocalChannel;
|
import io.netty.channel.local.LocalChannel;
|
||||||
import io.netty.channel.local.LocalEventLoopGroup;
|
|
||||||
import io.netty.util.concurrent.Future;
|
import io.netty.util.concurrent.Future;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@ -33,8 +33,8 @@ public class BootstrapTest {
|
|||||||
|
|
||||||
@Test(timeout = 10000)
|
@Test(timeout = 10000)
|
||||||
public void testBindDeadLock() throws Exception {
|
public void testBindDeadLock() throws Exception {
|
||||||
EventLoopGroup groupA = new LocalEventLoopGroup(1);
|
EventLoopGroup groupA = new DefaultEventLoopGroup(1);
|
||||||
EventLoopGroup groupB = new LocalEventLoopGroup(1);
|
EventLoopGroup groupB = new DefaultEventLoopGroup(1);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ChannelInboundHandler dummyHandler = new DummyHandler();
|
ChannelInboundHandler dummyHandler = new DummyHandler();
|
||||||
@ -81,8 +81,8 @@ public class BootstrapTest {
|
|||||||
|
|
||||||
@Test(timeout = 10000)
|
@Test(timeout = 10000)
|
||||||
public void testConnectDeadLock() throws Exception {
|
public void testConnectDeadLock() throws Exception {
|
||||||
EventLoopGroup groupA = new LocalEventLoopGroup(1);
|
EventLoopGroup groupA = new DefaultEventLoopGroup(1);
|
||||||
EventLoopGroup groupB = new LocalEventLoopGroup(1);
|
EventLoopGroup groupB = new DefaultEventLoopGroup(1);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ChannelInboundHandler dummyHandler = new DummyHandler();
|
ChannelInboundHandler dummyHandler = new DummyHandler();
|
||||||
|
@ -16,25 +16,25 @@
|
|||||||
package io.netty.channel;
|
package io.netty.channel;
|
||||||
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import io.netty.bootstrap.Bootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.bootstrap.ServerBootstrap;
|
import io.netty.bootstrap.ServerBootstrap;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import io.netty.channel.local.LocalChannel;
|
import io.netty.channel.local.LocalChannel;
|
||||||
import io.netty.channel.local.LocalEventLoopGroup;
|
|
||||||
import io.netty.channel.local.LocalServerChannel;
|
import io.netty.channel.local.LocalServerChannel;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
class BaseChannelTest {
|
class BaseChannelTest {
|
||||||
|
|
||||||
private final LoggingHandler loggingHandler;
|
private final LoggingHandler loggingHandler;
|
||||||
|
|
||||||
BaseChannelTest() {
|
BaseChannelTest() {
|
||||||
this.loggingHandler = new LoggingHandler();
|
loggingHandler = new LoggingHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerBootstrap getLocalServerBootstrap() {
|
ServerBootstrap getLocalServerBootstrap() {
|
||||||
EventLoopGroup serverGroup = new LocalEventLoopGroup();
|
EventLoopGroup serverGroup = new DefaultEventLoopGroup();
|
||||||
ServerBootstrap sb = new ServerBootstrap();
|
ServerBootstrap sb = new ServerBootstrap();
|
||||||
sb.group(serverGroup);
|
sb.group(serverGroup);
|
||||||
sb.channel(LocalServerChannel.class);
|
sb.channel(LocalServerChannel.class);
|
||||||
@ -48,12 +48,12 @@ class BaseChannelTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Bootstrap getLocalClientBootstrap() {
|
Bootstrap getLocalClientBootstrap() {
|
||||||
EventLoopGroup clientGroup = new LocalEventLoopGroup();
|
EventLoopGroup clientGroup = new DefaultEventLoopGroup();
|
||||||
Bootstrap cb = new Bootstrap();
|
Bootstrap cb = new Bootstrap();
|
||||||
cb.channel(LocalChannel.class);
|
cb.channel(LocalChannel.class);
|
||||||
cb.group(clientGroup);
|
cb.group(clientGroup);
|
||||||
|
|
||||||
cb.handler(this.loggingHandler);
|
cb.handler(loggingHandler);
|
||||||
|
|
||||||
return cb;
|
return cb;
|
||||||
}
|
}
|
||||||
@ -65,16 +65,16 @@ class BaseChannelTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void assertLog(String expected) {
|
void assertLog(String expected) {
|
||||||
String actual = this.loggingHandler.getLog();
|
String actual = loggingHandler.getLog();
|
||||||
assertEquals(expected, actual);
|
assertEquals(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearLog() {
|
void clearLog() {
|
||||||
this.loggingHandler.clear();
|
loggingHandler.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setInterest(LoggingHandler.Event... events) {
|
void setInterest(LoggingHandler.Event... events) {
|
||||||
this.loggingHandler.setInterest(events);
|
loggingHandler.setInterest(events);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ import io.netty.bootstrap.ServerBootstrap;
|
|||||||
import io.netty.channel.ChannelHandler.Sharable;
|
import io.netty.channel.ChannelHandler.Sharable;
|
||||||
import io.netty.channel.local.LocalAddress;
|
import io.netty.channel.local.LocalAddress;
|
||||||
import io.netty.channel.local.LocalChannel;
|
import io.netty.channel.local.LocalChannel;
|
||||||
import io.netty.channel.local.LocalEventLoopGroup;
|
|
||||||
import io.netty.channel.local.LocalServerChannel;
|
import io.netty.channel.local.LocalServerChannel;
|
||||||
import io.netty.util.AbstractReferenceCounted;
|
import io.netty.util.AbstractReferenceCounted;
|
||||||
import io.netty.util.ReferenceCountUtil;
|
import io.netty.util.ReferenceCountUtil;
|
||||||
@ -43,7 +42,7 @@ import static org.junit.Assert.*;
|
|||||||
|
|
||||||
public class DefaultChannelPipelineTest {
|
public class DefaultChannelPipelineTest {
|
||||||
|
|
||||||
private static final EventLoopGroup group = new LocalEventLoopGroup(1);
|
private static final EventLoopGroup group = new DefaultEventLoopGroup(1);
|
||||||
|
|
||||||
private Channel self;
|
private Channel self;
|
||||||
private Channel peer;
|
private Channel peer;
|
||||||
|
@ -22,6 +22,7 @@ import io.netty.channel.Channel;
|
|||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
|
import io.netty.channel.DefaultEventLoopGroup;
|
||||||
import io.netty.channel.EventLoopGroup;
|
import io.netty.channel.EventLoopGroup;
|
||||||
import io.netty.channel.SimpleChannelInboundHandler;
|
import io.netty.channel.SimpleChannelInboundHandler;
|
||||||
import io.netty.util.internal.logging.InternalLogger;
|
import io.netty.util.internal.logging.InternalLogger;
|
||||||
@ -43,8 +44,8 @@ public class LocalChannelTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testLocalAddressReuse() throws Exception {
|
public void testLocalAddressReuse() throws Exception {
|
||||||
for (int i = 0; i < 2; i ++) {
|
for (int i = 0; i < 2; i ++) {
|
||||||
EventLoopGroup clientGroup = new LocalEventLoopGroup();
|
EventLoopGroup clientGroup = new DefaultEventLoopGroup();
|
||||||
EventLoopGroup serverGroup = new LocalEventLoopGroup();
|
EventLoopGroup serverGroup = new DefaultEventLoopGroup();
|
||||||
LocalAddress addr = new LocalAddress(LOCAL_ADDR_ID);
|
LocalAddress addr = new LocalAddress(LOCAL_ADDR_ID);
|
||||||
Bootstrap cb = new Bootstrap();
|
Bootstrap cb = new Bootstrap();
|
||||||
ServerBootstrap sb = new ServerBootstrap();
|
ServerBootstrap sb = new ServerBootstrap();
|
||||||
@ -97,8 +98,8 @@ public class LocalChannelTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWriteFailsFastOnClosedChannel() throws Exception {
|
public void testWriteFailsFastOnClosedChannel() throws Exception {
|
||||||
EventLoopGroup clientGroup = new LocalEventLoopGroup();
|
EventLoopGroup clientGroup = new DefaultEventLoopGroup();
|
||||||
EventLoopGroup serverGroup = new LocalEventLoopGroup();
|
EventLoopGroup serverGroup = new DefaultEventLoopGroup();
|
||||||
LocalAddress addr = new LocalAddress(LOCAL_ADDR_ID);
|
LocalAddress addr = new LocalAddress(LOCAL_ADDR_ID);
|
||||||
Bootstrap cb = new Bootstrap();
|
Bootstrap cb = new Bootstrap();
|
||||||
ServerBootstrap sb = new ServerBootstrap();
|
ServerBootstrap sb = new ServerBootstrap();
|
||||||
@ -147,7 +148,7 @@ public class LocalChannelTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testServerCloseChannelSameEventLoop() throws Exception {
|
public void testServerCloseChannelSameEventLoop() throws Exception {
|
||||||
LocalAddress addr = new LocalAddress(LOCAL_ADDR_ID);
|
LocalAddress addr = new LocalAddress(LOCAL_ADDR_ID);
|
||||||
LocalEventLoopGroup group = new LocalEventLoopGroup(1);
|
EventLoopGroup group = new DefaultEventLoopGroup(1);
|
||||||
final CountDownLatch latch = new CountDownLatch(1);
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
ServerBootstrap sb = new ServerBootstrap()
|
ServerBootstrap sb = new ServerBootstrap()
|
||||||
.group(group)
|
.group(group)
|
||||||
|
@ -24,6 +24,7 @@ import io.netty.channel.ChannelHandlerContext;
|
|||||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
import io.netty.channel.ChannelPromise;
|
import io.netty.channel.ChannelPromise;
|
||||||
|
import io.netty.channel.DefaultEventLoopGroup;
|
||||||
import io.netty.channel.EventLoopGroup;
|
import io.netty.channel.EventLoopGroup;
|
||||||
import io.netty.util.ReferenceCountUtil;
|
import io.netty.util.ReferenceCountUtil;
|
||||||
import io.netty.util.concurrent.DefaultEventExecutorGroup;
|
import io.netty.util.concurrent.DefaultEventExecutorGroup;
|
||||||
@ -49,7 +50,7 @@ public class LocalTransportThreadModelTest {
|
|||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void init() {
|
public static void init() {
|
||||||
// Configure a test server
|
// Configure a test server
|
||||||
group = new LocalEventLoopGroup();
|
group = new DefaultEventLoopGroup();
|
||||||
ServerBootstrap sb = new ServerBootstrap();
|
ServerBootstrap sb = new ServerBootstrap();
|
||||||
sb.group(group)
|
sb.group(group)
|
||||||
.channel(LocalServerChannel.class)
|
.channel(LocalServerChannel.class)
|
||||||
@ -84,7 +85,7 @@ public class LocalTransportThreadModelTest {
|
|||||||
|
|
||||||
@Test(timeout = 5000)
|
@Test(timeout = 5000)
|
||||||
public void testStagedExecution() throws Throwable {
|
public void testStagedExecution() throws Throwable {
|
||||||
EventLoopGroup l = new LocalEventLoopGroup(4, new DefaultThreadFactory("l"));
|
EventLoopGroup l = new DefaultEventLoopGroup(4, new DefaultThreadFactory("l"));
|
||||||
EventExecutorGroup e1 = new DefaultEventExecutorGroup(4, new DefaultThreadFactory("e1"));
|
EventExecutorGroup e1 = new DefaultEventExecutorGroup(4, new DefaultThreadFactory("e1"));
|
||||||
EventExecutorGroup e2 = new DefaultEventExecutorGroup(4, new DefaultThreadFactory("e2"));
|
EventExecutorGroup e2 = new DefaultEventExecutorGroup(4, new DefaultThreadFactory("e2"));
|
||||||
ThreadNameAuditor h1 = new ThreadNameAuditor();
|
ThreadNameAuditor h1 = new ThreadNameAuditor();
|
||||||
@ -227,7 +228,7 @@ public class LocalTransportThreadModelTest {
|
|||||||
@Test(timeout = 30000)
|
@Test(timeout = 30000)
|
||||||
@Ignore
|
@Ignore
|
||||||
public void testConcurrentMessageBufferAccess() throws Throwable {
|
public void testConcurrentMessageBufferAccess() throws Throwable {
|
||||||
EventLoopGroup l = new LocalEventLoopGroup(4, new DefaultThreadFactory("l"));
|
EventLoopGroup l = new DefaultEventLoopGroup(4, new DefaultThreadFactory("l"));
|
||||||
EventExecutorGroup e1 = new DefaultEventExecutorGroup(4, new DefaultThreadFactory("e1"));
|
EventExecutorGroup e1 = new DefaultEventExecutorGroup(4, new DefaultThreadFactory("e1"));
|
||||||
EventExecutorGroup e2 = new DefaultEventExecutorGroup(4, new DefaultThreadFactory("e2"));
|
EventExecutorGroup e2 = new DefaultEventExecutorGroup(4, new DefaultThreadFactory("e2"));
|
||||||
EventExecutorGroup e3 = new DefaultEventExecutorGroup(4, new DefaultThreadFactory("e3"));
|
EventExecutorGroup e3 = new DefaultEventExecutorGroup(4, new DefaultThreadFactory("e3"));
|
||||||
|
@ -22,6 +22,7 @@ import io.netty.channel.ChannelFuture;
|
|||||||
import io.netty.channel.ChannelHandler.Sharable;
|
import io.netty.channel.ChannelHandler.Sharable;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||||
|
import io.netty.channel.DefaultEventLoopGroup;
|
||||||
import io.netty.util.ReferenceCountUtil;
|
import io.netty.util.ReferenceCountUtil;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@ -40,14 +41,14 @@ public class LocalTransportThreadModelTest2 {
|
|||||||
ServerBootstrap serverBootstrap = new ServerBootstrap();
|
ServerBootstrap serverBootstrap = new ServerBootstrap();
|
||||||
LocalHander serverHandler = new LocalHander("SERVER");
|
LocalHander serverHandler = new LocalHander("SERVER");
|
||||||
serverBootstrap
|
serverBootstrap
|
||||||
.group(new LocalEventLoopGroup(), new LocalEventLoopGroup())
|
.group(new DefaultEventLoopGroup(), new DefaultEventLoopGroup())
|
||||||
.channel(LocalServerChannel.class)
|
.channel(LocalServerChannel.class)
|
||||||
.childHandler(serverHandler);
|
.childHandler(serverHandler);
|
||||||
|
|
||||||
Bootstrap clientBootstrap = new Bootstrap();
|
Bootstrap clientBootstrap = new Bootstrap();
|
||||||
LocalHander clientHandler = new LocalHander("CLIENT");
|
LocalHander clientHandler = new LocalHander("CLIENT");
|
||||||
clientBootstrap
|
clientBootstrap
|
||||||
.group(new LocalEventLoopGroup())
|
.group(new DefaultEventLoopGroup())
|
||||||
.channel(LocalChannel.class)
|
.channel(LocalChannel.class)
|
||||||
.remoteAddress(new LocalAddress(LOCAL_CHANNEL)).handler(clientHandler);
|
.remoteAddress(new LocalAddress(LOCAL_CHANNEL)).handler(clientHandler);
|
||||||
|
|
||||||
@ -100,7 +101,7 @@ public class LocalTransportThreadModelTest2 {
|
|||||||
|
|
||||||
public final AtomicInteger count = new AtomicInteger(0);
|
public final AtomicInteger count = new AtomicInteger(0);
|
||||||
|
|
||||||
public LocalHander(String name) {
|
LocalHander(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ import io.netty.channel.ChannelHandlerContext;
|
|||||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
import io.netty.channel.ChannelPromise;
|
import io.netty.channel.ChannelPromise;
|
||||||
|
import io.netty.channel.DefaultEventLoopGroup;
|
||||||
import io.netty.channel.EventLoopGroup;
|
import io.netty.channel.EventLoopGroup;
|
||||||
import io.netty.util.ReferenceCountUtil;
|
import io.netty.util.ReferenceCountUtil;
|
||||||
import io.netty.util.concurrent.DefaultEventExecutorGroup;
|
import io.netty.util.concurrent.DefaultEventExecutorGroup;
|
||||||
@ -62,7 +63,7 @@ public class LocalTransportThreadModelTest3 {
|
|||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void init() {
|
public static void init() {
|
||||||
// Configure a test server
|
// Configure a test server
|
||||||
group = new LocalEventLoopGroup();
|
group = new DefaultEventLoopGroup();
|
||||||
ServerBootstrap sb = new ServerBootstrap();
|
ServerBootstrap sb = new ServerBootstrap();
|
||||||
sb.group(group)
|
sb.group(group)
|
||||||
.channel(LocalServerChannel.class)
|
.channel(LocalServerChannel.class)
|
||||||
@ -116,7 +117,7 @@ public class LocalTransportThreadModelTest3 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void testConcurrentAddRemove(boolean inbound) throws Exception {
|
private static void testConcurrentAddRemove(boolean inbound) throws Exception {
|
||||||
EventLoopGroup l = new LocalEventLoopGroup(4, new DefaultThreadFactory("l"));
|
EventLoopGroup l = new DefaultEventLoopGroup(4, new DefaultThreadFactory("l"));
|
||||||
EventExecutorGroup e1 = new DefaultEventExecutorGroup(4, new DefaultThreadFactory("e1"));
|
EventExecutorGroup e1 = new DefaultEventExecutorGroup(4, new DefaultThreadFactory("e1"));
|
||||||
EventExecutorGroup e2 = new DefaultEventExecutorGroup(4, new DefaultThreadFactory("e2"));
|
EventExecutorGroup e2 = new DefaultEventExecutorGroup(4, new DefaultThreadFactory("e2"));
|
||||||
EventExecutorGroup e3 = new DefaultEventExecutorGroup(4, new DefaultThreadFactory("e3"));
|
EventExecutorGroup e3 = new DefaultEventExecutorGroup(4, new DefaultThreadFactory("e3"));
|
||||||
@ -210,7 +211,7 @@ public class LocalTransportThreadModelTest3 {
|
|||||||
for (;;) {
|
for (;;) {
|
||||||
EventType event = events.poll();
|
EventType event = events.poll();
|
||||||
if (event == null) {
|
if (event == null) {
|
||||||
Assert.assertTrue("Missing events:" + expectedEvents.toString(), expectedEvents.isEmpty());
|
Assert.assertTrue("Missing events:" + expectedEvents, expectedEvents.isEmpty());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Assert.assertEquals(event, expectedEvents.poll());
|
Assert.assertEquals(event, expectedEvents.poll());
|
||||||
@ -258,7 +259,7 @@ public class LocalTransportThreadModelTest3 {
|
|||||||
private final Queue<EventType> events;
|
private final Queue<EventType> events;
|
||||||
private final boolean inbound;
|
private final boolean inbound;
|
||||||
|
|
||||||
public EventRecorder(Queue<EventType> events, boolean inbound) {
|
EventRecorder(Queue<EventType> events, boolean inbound) {
|
||||||
this.events = events;
|
this.events = events;
|
||||||
this.inbound = inbound;
|
this.inbound = inbound;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user