Search in sources :

Example 1 with ThreadPerTaskExecutor

use of io.netty.util.concurrent.ThreadPerTaskExecutor in project netty by netty.

the class EpollEventLoopTest method testScheduleBigDelayNotOverflow.

@Test
public void testScheduleBigDelayNotOverflow() {
    final AtomicReference<Throwable> capture = new AtomicReference<Throwable>();
    final EventLoopGroup group = new EpollEventLoop(null, new ThreadPerTaskExecutor(new DefaultThreadFactory(getClass())), 0, DefaultSelectStrategyFactory.INSTANCE.newSelectStrategy(), RejectedExecutionHandlers.reject(), null, null) {

        @Override
        void handleLoopException(Throwable t) {
            capture.set(t);
            super.handleLoopException(t);
        }
    };
    try {
        final EventLoop eventLoop = group.next();
        Future<?> future = eventLoop.schedule(new Runnable() {

            @Override
            public void run() {
            // NOOP
            }
        }, Long.MAX_VALUE, TimeUnit.MILLISECONDS);
        assertFalse(future.awaitUninterruptibly(1000));
        assertTrue(future.cancel(true));
        assertNull(capture.get());
    } finally {
        group.shutdownGracefully();
    }
}
Also used : DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) ThreadPerTaskExecutor(io.netty.util.concurrent.ThreadPerTaskExecutor) EventLoopGroup(io.netty.channel.EventLoopGroup) EventLoop(io.netty.channel.EventLoop) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test) AbstractSingleThreadEventLoopTest(io.netty.testsuite.transport.AbstractSingleThreadEventLoopTest)

Example 2 with ThreadPerTaskExecutor

use of io.netty.util.concurrent.ThreadPerTaskExecutor in project netty by netty.

the class NioEventLoopTest method testCustomQueue.

@Test
public void testCustomQueue() {
    final AtomicBoolean called = new AtomicBoolean();
    NioEventLoopGroup group = new NioEventLoopGroup(1, new ThreadPerTaskExecutor(new DefaultThreadFactory(NioEventLoopGroup.class)), DefaultEventExecutorChooserFactory.INSTANCE, SelectorProvider.provider(), DefaultSelectStrategyFactory.INSTANCE, RejectedExecutionHandlers.reject(), new EventLoopTaskQueueFactory() {

        @Override
        public Queue<Runnable> newTaskQueue(int maxCapacity) {
            called.set(true);
            return new LinkedBlockingQueue<Runnable>(maxCapacity);
        }
    });
    final NioEventLoop loop = (NioEventLoop) group.next();
    try {
        loop.submit(new Runnable() {

            @Override
            public void run() {
            // NOOP.
            }
        }).syncUninterruptibly();
        assertTrue(called.get());
    } finally {
        group.shutdownGracefully();
    }
}
Also used : DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) EventLoopTaskQueueFactory(io.netty.channel.EventLoopTaskQueueFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ThreadPerTaskExecutor(io.netty.util.concurrent.ThreadPerTaskExecutor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Queue(java.util.Queue) AbstractEventLoopTest(io.netty.channel.AbstractEventLoopTest) Test(org.junit.jupiter.api.Test)

Aggregations

DefaultThreadFactory (io.netty.util.concurrent.DefaultThreadFactory)2 ThreadPerTaskExecutor (io.netty.util.concurrent.ThreadPerTaskExecutor)2 Test (org.junit.jupiter.api.Test)2 AbstractEventLoopTest (io.netty.channel.AbstractEventLoopTest)1 EventLoop (io.netty.channel.EventLoop)1 EventLoopGroup (io.netty.channel.EventLoopGroup)1 EventLoopTaskQueueFactory (io.netty.channel.EventLoopTaskQueueFactory)1 AbstractSingleThreadEventLoopTest (io.netty.testsuite.transport.AbstractSingleThreadEventLoopTest)1 Queue (java.util.Queue)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1