Class LeakPresenceExtension

  • 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 final class LeakPresenceExtension
    extends java.lang.Object
    implements org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.AfterEachCallback, org.junit.jupiter.api.extension.AfterAllCallback
    Junit 5 extension for leak detection using LeakPresenceDetector.

    Leak presence is checked at the class level. Any resource must be closed at the end of the test class, by the time AfterAll has been called. Method-level detection is not possible because some tests retain resources between methods on the same class, notably parameterized tests that allocate different buffers before running the test methods with those buffers.

    This extension supports parallel test execution, but has to make some assumptions about the thread lifecycle. The resource scope for the class is created in BeforeAll, and then saved in a thread local on each BeforeEach. This appears to work well with junit's default parallelism, despite the use of a fork-join pool that can transfer tasks between threads, but it may lead to problems if tests make use of fork-join machinery themselves.

    The ThreadLocal holding the scope is inheritable, so that e.g. event loops created in a test are assigned to the test resource scope.

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void afterAll​(org.junit.jupiter.api.extension.ExtensionContext context)  
      void afterEach​(org.junit.jupiter.api.extension.ExtensionContext context)  
      void beforeAll​(org.junit.jupiter.api.extension.ExtensionContext context)  
      void beforeEach​(org.junit.jupiter.api.extension.ExtensionContext context)  
      • Methods inherited from class java.lang.Object

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

      • LeakPresenceExtension

        public LeakPresenceExtension()
    • Method Detail

      • beforeAll

        public void beforeAll​(org.junit.jupiter.api.extension.ExtensionContext context)
        Specified by:
        beforeAll in interface org.junit.jupiter.api.extension.BeforeAllCallback
      • beforeEach

        public void beforeEach​(org.junit.jupiter.api.extension.ExtensionContext context)
        Specified by:
        beforeEach in interface org.junit.jupiter.api.extension.BeforeEachCallback
      • afterEach

        public void afterEach​(org.junit.jupiter.api.extension.ExtensionContext context)
        Specified by:
        afterEach in interface org.junit.jupiter.api.extension.AfterEachCallback
      • afterAll

        public void afterAll​(org.junit.jupiter.api.extension.ExtensionContext context)
                      throws java.lang.InterruptedException
        Specified by:
        afterAll in interface org.junit.jupiter.api.extension.AfterAllCallback
        Throws:
        java.lang.InterruptedException