Class StrictContextStorage

  • All Implemented Interfaces:
    ContextStorage, java.lang.AutoCloseable

    final class StrictContextStorage
    extends java.lang.Object
    implements ContextStorage, java.lang.AutoCloseable
    A ContextStorage which keeps track of opened and closed Scopes, reporting caller information if a Scope is closed incorrectly or not at all.

    Calling close() will check at the moment it's called whether there are any scopes that have been opened but not closed yet. This could be called at the end of a unit test to ensure the tested code cleaned up scopes correctly.

    • Constructor Detail

      • StrictContextStorage

        private StrictContextStorage​(ContextStorage delegate)
    • Method Detail

      • close

        public void close()
        Ensures all scopes that have been created by this storage have been closed. This can be useful to call at the end of a test to make sure everything has been cleaned up.

        Note: It is important to close all resources prior to calling this, so that in-flight operations are not mistaken as scope leaks. If this raises an error, consider if a Context.wrap(Executor) wrapped executor} is still running.

        Specified by:
        close in interface java.lang.AutoCloseable
        Throws:
        java.lang.AssertionError - if any scopes were left unclosed.