Class EventLoopGroupExtension

java.lang.Object
com.linecorp.armeria.testing.junit5.common.AbstractAllOrEachExtension
com.linecorp.armeria.testing.junit5.common.EventLoopGroupExtension
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 EventLoopGroupExtension extends AbstractAllOrEachExtension
An Extension that provides an EventLoopGroup. For example:

 > public class MyTest {
 >     @RegisterExtension
 >     public static final EventLoopGroupExtension eventLoopGroup = new EventLoopGroupExtension(4);
 >
 >     @Test
 >     public void test() {
 >         ClientFactory f = ClientFactory.builder()
 >                                        .workerGroup(eventLoopGroup.get())
 >                                        .build();
 >         ...
 >     }
 > }
 
See Also:
  • Constructor Details

    • EventLoopGroupExtension

      public EventLoopGroupExtension(int numThreads)
      Creates a new Extension that provides an EventLoopGroup.
      Parameters:
      numThreads - the number of event loop threads
    • EventLoopGroupExtension

      public EventLoopGroupExtension(int numThreads, boolean useDaemonThreads)
      Creates a new Extension that provides an EventLoopGroup.
      Parameters:
      numThreads - the number of event loop threads
      useDaemonThreads - whether to create daemon threads or not
    • EventLoopGroupExtension

      public EventLoopGroupExtension(int numThreads, String threadNamePrefix)
      Creates a new Extension that provides an EventLoopGroup.
      Parameters:
      numThreads - the number of event loop threads
      threadNamePrefix - the prefix of thread names
    • EventLoopGroupExtension

      public EventLoopGroupExtension(int numThreads, String threadNamePrefix, boolean useDaemonThreads)
      Creates a new Extension that provides an EventLoopGroup.
      Parameters:
      numThreads - the number of event loop threads
      threadNamePrefix - the prefix of thread names
      useDaemonThreads - whether to create daemon threads or not
    • EventLoopGroupExtension

      public EventLoopGroupExtension(int numThreads, ThreadFactory threadFactory)
      Creates a new Extension that provides an EventLoopGroup.
      Parameters:
      numThreads - the number of event loop threads
      threadFactory - the factory used to create threads.
  • Method Details

    • get

      public io.netty.channel.EventLoopGroup get()
      Returns the EventLoopGroup.
    • 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