Class TestProfilerBackendIsolated

java.lang.Object
org.apache.hadoop.hbase.http.TestProfilerBackendIsolated

@Tag("org.apache.hadoop.hbase.testclassification.MiscTests") @Tag("org.apache.hadoop.hbase.testclassification.SmallTests") public class TestProfilerBackendIsolated extends Object
Verifies ProfilerBackend.detect(java.lang.String) fallback behaviour when one.profiler.AsyncProfiler is absent from the classpath.

Each test loads ProfilerBackend through a custom ClassLoader that blocks one.profiler.*, simulating a deployment where the async-profiler JAR was never packaged. This is the exact scenario for users who have async-profiler installed as a native binary (ASYNC_PROFILER_HOME) but are not allowed to bundle the JAR.

The split of LibraryBackend into its own file is what makes this possible: ProfilerBackend.class carries no static reference to AsyncProfiler, so the isolated loader can load it without a NoClassDefFoundError.

  • Field Details

  • Constructor Details

  • Method Details

    • testDetectReturnsNullWhenLibraryAbsentAndNoHome

      When the library is absent AND no home is set, detect() must return null so that HttpServer registers DisabledServlet instead of crashing.
      Throws:
      Exception
    • testDetectReturnsBinaryBackendWhenLibraryAbsentButHomeSet

      User has async-profiler installed as a native binary (ASYNC_PROFILER_HOME set, bin/asprof present) but no JAR on the classpath. detect() must return BinaryBackend.
      Throws:
      Exception
    • testDetectReturnsLibraryBackendWhenLibraryPresent

      When the library IS on the classpath (normal test classpath), detect() must return LibraryBackend regardless of whether a home is set — library takes priority.
    • testDetectPrefersLibraryWhenBothPresent

      Library present AND home set — LibraryBackend must still win (priority check).
      Throws:
      Exception
    • isolatedLoader

      Returns a ClassLoader that: - blocks one.profiler.* entirely (simulates absent async-profiler JAR) - reloads org.apache.hadoop.hbase.http.* classes fresh (so LibraryBackend resolves its own imports through this loader and also sees one.profiler.* as absent) - delegates everything else to the parent
    • detectMethod

      private Method detectMethod(ClassLoader loader) throws Exception
      Loads ProfilerBackend through the given loader and returns its detect(String) method, made accessible across loader boundaries.
      Throws:
      Exception