MemoryMonitor implements Runnable, StatusDataProvider { @VisibleForTesting static MemoryMonitor forTest( GCStatsProvider gcStatsProvider, long sleepTimeMillis, int shutDownAfterNumGCThrashing, boolean canDumpHeap, double gcThrashingPercentagePerPeriod, @Nullable String uploadToGCSPath, File localDumpFolder) { return new MemoryMonitor( gcStatsProvider, sleepTimeMillis, shutDownAfterNumGCThrashing, canDumpHeap, gcThrashingPercentagePerPeriod, uploadToGCSPath, localDumpFolder); } private  MemoryMonitor(
      GCStatsProvider gcStatsProvider,
      long sleepTimeMillis,
      int shutDownAfterNumGCThrashing,
      boolean canDumpHeap,
      double gcThrashingPercentagePerPeriod,
      @Nullable String uploadToGCSPath,
      File localDumpFolder); static MemoryMonitor fromOptions(PipelineOptions options); @VisibleForTesting void waitForThrashingState(boolean desiredThrashingState); void stop(); boolean isThrashing(); @Nullable File tryToDumpHeap(); @Override void run(); void waitForResources(String context); File dumpHeap(); @Override void appendSummaryHtml(PrintWriter writer); static final long DEFAULT_SLEEP_TIME_MILLIS; }
@Test public void disableMemoryMonitor() throws Exception { MemoryMonitor disabledMonitor = MemoryMonitor.forTest(provider, 10, 0, true, 100.0, null, localDumpFolder); Thread disabledMonitorThread = new Thread(disabledMonitor); disabledMonitorThread.start(); disabledMonitorThread.join(10000); assertFalse(disabledMonitorThread.isAlive()); assertTrue(thread.isAlive()); }