private void testHeartbeatSleepScenario(final LongUnaryOperator actualSleepPeriod,
      final String expectedLogWarning) {

    /*
     * Creating a class here because it's a convenient to provide (mutable) variables needed
     * by the lambdas. Without the class, each of them would have to be arrays or atomics
     * or some other kind of "holder object". By creating a class they can simply be fields.
     */
    new Runnable() {
      // the thing we're testing
      final GMSHealthMonitor.Heart heart = gmsHealthMonitor.new Heart();
      int periodNumber = 0; // index into times
      String capturedMessage; // warning message (if any) generated by heart

      @Override
      public void run() {
        heart.sendPeriodicHeartbeats(sleepMillis -> {
        },
            () -> {
              switch (periodNumber++) {
                case 0:
                  return 0L;
                case 1:
                default:
                  gmsHealthMonitor.stop();
                  return actualSleepPeriod.applyAsLong(heart.sleepLimitNanos);
              }
            },
            msg -> capturedMessage = msg);
        assertThat(capturedMessage).isEqualTo(expectedLogWarning);
      }
    }.run();
  }
Same test as above but with request to initiate removal
geode-membership/src/integrationTest/java/org/apache/geode/distributed/internal/membership/gms/fd/GMSHealthMonitorJUnitTest.java