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

    Constructors
    Constructor
    Description
    Creates a new TestRule that provides an EventLoop.
    EventLoopRule(boolean useDaemonThread)
    Creates a new TestRule that provides an EventLoop.
    EventLoopRule(String threadNamePrefix)
    Creates a new TestRule that provides an EventLoop.
    EventLoopRule(String threadNamePrefix, boolean useDaemonThread)
    Creates a new TestRule that provides an EventLoop.
    Creates a new TestRule that provides an EventLoop.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Shuts down all threads created by this TestRule asynchronously.
    protected void
     
    io.netty.channel.EventLoop
    get()
    Returns the EventLoop.

    Methods inherited from class org.junit.rules.ExternalResource

    apply

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • EventLoopRule

      public EventLoopRule()
      Creates a new TestRule that provides an EventLoop.
    • EventLoopRule

      public EventLoopRule(boolean useDaemonThread)
      Creates a new TestRule that provides an EventLoop.
      Parameters:
      useDaemonThread - whether to create a daemon thread or not
    • EventLoopRule

      public EventLoopRule(String threadNamePrefix)
      Creates a new TestRule that provides an EventLoop.
      Parameters:
      threadNamePrefix - the prefix of a thread name
    • EventLoopRule

      public EventLoopRule(String threadNamePrefix, boolean useDaemonThread)
      Creates a new TestRule that provides an EventLoop.
      Parameters:
      threadNamePrefix - the prefix of a thread name
      useDaemonThread - whether to create a daemon thread or not
    • EventLoopRule

      public EventLoopRule(ThreadFactory threadFactory)
      Creates a new TestRule that provides an EventLoop.
      Parameters:
      threadFactory - the factory used to create threads.
  • Method Details

    • get

      public io.netty.channel.EventLoop get()
      Returns the EventLoop.
    • before

      protected void before() throws Throwable
      Overrides:
      before in class org.junit.rules.ExternalResource
      Throws:
      Throwable
    • after

      protected void after()
      Shuts down all threads created by this TestRule asynchronously. Call rule.get().shutdownGracefully().sync() if you want to wait for complete termination.
      Overrides:
      after in class org.junit.rules.ExternalResource