Class EventLoopRule
java.lang.Object
org.junit.rules.ExternalResource
com.linecorp.armeria.testing.junit4.common.EventLoopRule
- All Implemented Interfaces:
org.junit.rules.TestRule
public final class EventLoopRule
extends org.junit.rules.ExternalResource
A
TestRule
that provides an EventLoopGroup
. For example:
> public class MyTest {
> @ClassRule
> public static final EventLoopRule eventLoop = new EventLoopRule();
>
> @Test
> public void test() {
> eventLoop.get().execute(() -> System.out.println("Hello!"));
> }
> }
- See Also:
-
Constructor Summary
ConstructorDescriptionCreates a newTestRule
that provides anEventLoop
.EventLoopRule
(boolean useDaemonThread) Creates a newTestRule
that provides anEventLoop
.EventLoopRule
(String threadNamePrefix) Creates a newTestRule
that provides anEventLoop
.EventLoopRule
(String threadNamePrefix, boolean useDaemonThread) Creates a newTestRule
that provides anEventLoop
.EventLoopRule
(ThreadFactory threadFactory) Creates a newTestRule
that provides anEventLoop
. -
Method Summary
Methods inherited from class org.junit.rules.ExternalResource
apply
-
Constructor Details
-
EventLoopRule
public EventLoopRule()Creates a newTestRule
that provides anEventLoop
. -
EventLoopRule
public EventLoopRule(boolean useDaemonThread) Creates a newTestRule
that provides anEventLoop
.- Parameters:
useDaemonThread
- whether to create a daemon thread or not
-
EventLoopRule
Creates a newTestRule
that provides anEventLoop
.- Parameters:
threadNamePrefix
- the prefix of a thread name
-
EventLoopRule
Creates a newTestRule
that provides anEventLoop
.- Parameters:
threadNamePrefix
- the prefix of a thread nameuseDaemonThread
- whether to create a daemon thread or not
-
EventLoopRule
Creates a newTestRule
that provides anEventLoop
.- Parameters:
threadFactory
- the factory used to create threads.
-
-
Method Details
-
get
public io.netty.channel.EventLoop get()Returns theEventLoop
. -
before
- Overrides:
before
in classorg.junit.rules.ExternalResource
- Throws:
Throwable
-
after
protected void after()Shuts down all threads created by thisTestRule
asynchronously. Callrule.get().shutdownGracefully().sync()
if you want to wait for complete termination.- Overrides:
after
in classorg.junit.rules.ExternalResource
-