Class EventLoopExtension

java.lang.Object
com.linecorp.armeria.testing.junit5.common.AbstractAllOrEachExtension
com.linecorp.armeria.testing.junit5.common.EventLoopExtension
All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterAllCallback, org.junit.jupiter.api.extension.AfterEachCallback, org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.Extension

public class EventLoopExtension extends AbstractAllOrEachExtension
An Extension that provides an EventLoopGroup. For example:

 > public class MyTest {
 >     @RegisterExtension
 >     public static final EventLoopExtension eventLoop = new EventLoopExtension();
 >
 >     @Test
 >     public void test() {
 >         eventLoop.get().execute(() -> System.out.println("Hello!"));
 >     }
 > }
 
See Also:
  • Constructor Details

    • EventLoopExtension

      public EventLoopExtension()
      Creates a new Extension that provides an EventLoop.
    • EventLoopExtension

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

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

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

      public EventLoopExtension(ThreadFactory threadFactory)
      Creates a new Extension 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

      public void before(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
      Description copied from class: AbstractAllOrEachExtension
      A method that should be run at the beginning of a test lifecycle. If AbstractAllOrEachExtension.runForEachTest() returns false, this is run once before all tests, otherwise it is run before each test method.
      Specified by:
      before in class AbstractAllOrEachExtension
      Throws:
      Exception
    • after

      public void after(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
      Shuts down all threads created by this Extension asynchronously. Call rule.get().shutdownGracefully().sync() if you want to wait for complete termination.
      Specified by:
      after in class AbstractAllOrEachExtension
      Throws:
      Exception