ExecutionStateTracker implements Comparable<ExecutionStateTracker> { public void reset() { trackedThread = null; currentState = null; numTransitions = 0; millisSinceLastTransition = 0; transitionsAtLastSample = 0; nextLullReportMs = LULL_REPORT_MS; CURRENT_TRACKERS.entrySet().removeIf(entry -> entry.getValue() == this); } ExecutionStateTracker(ExecutionStateSampler sampler); void reset(); @VisibleForTesting static ExecutionStateTracker newForTest(); @Override int hashCode(); @SuppressFBWarnings("EQ_COMPARETO_USE_OBJECT_EQUALS") @Override int compareTo(ExecutionStateTracker o); static @Nullable ExecutionState getCurrentExecutionState(); Closeable activate(); @VisibleForTesting synchronized Closeable activate(Thread thread); Thread getTrackedThread(); ExecutionState getCurrentState(); Closeable enterState(ExecutionState newState); long getNumTransitions(); long getMillisSinceLastTransition(); long getTransitionsAtLastSample(); long getNextLullReportMs(); static final String START_STATE_NAME; static final String PROCESS_STATE_NAME; static final String PROCESS_TIMERS_STATE_NAME; static final String FINISH_STATE_NAME; static final String ABORT_STATE_NAME; }
@Test public void testReset() throws Exception { ExecutionStateTracker tracker = createTracker(); try (Closeable c1 = tracker.activate(new Thread())) { try (Closeable c2 = tracker.enterState(testExecutionState)) { sampler.doSampling(400); assertThat(testExecutionState.totalMillis, equalTo(400L)); } } tracker.reset(); assertThat(tracker.getTrackedThread(), equalTo(null)); assertThat(tracker.getCurrentState(), equalTo(null)); assertThat(tracker.getNumTransitions(), equalTo(0L)); assertThat(tracker.getMillisSinceLastTransition(), equalTo(0L)); assertThat(tracker.getTransitionsAtLastSample(), equalTo(0L)); assertThat(tracker.getNextLullReportMs(), equalTo(TimeUnit.MINUTES.toMillis(5))); }