Class EventLoopGroupRule

java.lang.Object
org.junit.rules.ExternalResource
com.linecorp.armeria.testing.junit4.common.EventLoopGroupRule
All Implemented Interfaces:
org.junit.rules.TestRule

public final class EventLoopGroupRule extends org.junit.rules.ExternalResource
A TestRule that provides an EventLoopGroup. For example:

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

    Constructors
    Constructor
    Description
    EventLoopGroupRule(int numThreads)
    Creates a new TestRule that provides an EventLoopGroup.
    EventLoopGroupRule(int numThreads, boolean useDaemonThreads)
    Creates a new TestRule that provides an EventLoopGroup.
    EventLoopGroupRule(int numThreads, String threadNamePrefix)
    Creates a new TestRule that provides an EventLoopGroup.
    EventLoopGroupRule(int numThreads, String threadNamePrefix, boolean useDaemonThreads)
    Creates a new TestRule that provides an EventLoopGroup.
    EventLoopGroupRule(int numThreads, ThreadFactory threadFactory)
    Creates a new TestRule that provides an EventLoopGroup.
  • Method Summary

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

    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

    • EventLoopGroupRule

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

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

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

      public EventLoopGroupRule(int numThreads, String threadNamePrefix, boolean useDaemonThreads)
      Creates a new TestRule 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
    • EventLoopGroupRule

      public EventLoopGroupRule(int numThreads, ThreadFactory threadFactory)
      Creates a new TestRule 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

      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