boolean reviewLeaseRequest(GetRegisterLeasePRequest request) {
    long blockCount = request.getBlockCount();
    long bytesAvailable = getAvailableBytes();
    long estimatedSpace = blockCount * BLOCK_COUNT_MULTIPLIER;
    if (bytesAvailable > estimatedSpace) {
      LOG.info("{} bytes available on master. The register request with {} blocks is estimated to"
          + " need {} bytes. ", bytesAvailable, blockCount, estimatedSpace);
      return true;
    } else {
      LOG.info("{} bytes available on master. The register request with {} blocks is estimated to"
              + " need {} bytes. Rejected the request.",
          bytesAvailable, blockCount, estimatedSpace);
      return false;
    }
  }
@Test
  public void reviewJvmUsage() {
    long usedBytes = 0L;
    long maxBytes = 1000L;

    // Mock the gauges
    MetricRegistry mockRegistry = mock(MetricRegistry.class);
    SortedMap<String, Gauge> heapGauges = new TreeMap<>();
    Gauge<Long> usedSpaceGauge = mock(Gauge.class);
    when(usedSpaceGauge.getValue()).thenReturn(usedBytes);
    Gauge<Long> maxSpaceGauge = mock(Gauge.class);
    when(maxSpaceGauge.getValue()).thenReturn(maxBytes);
    heapGauges.put("heap.used", usedSpaceGauge);
    heapGauges.put("heap.max", maxSpaceGauge);
    when(mockRegistry.getGauges(any())).thenReturn(heapGauges);

    Runtime mockRuntime = mock(Runtime.class);
    // max - (total - free) = 1000L
    when(mockRuntime.maxMemory()).thenReturn(1200L);
    when(mockRuntime.freeMemory()).thenReturn(0L);
    when(mockRuntime.totalMemory()).thenReturn(200L);

    JvmSpaceReviewer reviewer = new JvmSpaceReviewer(mockRuntime);

    // Determine how many blocks will be accepted
    long maxBlocks = (maxBytes - usedBytes) / JvmSpaceReviewer.BLOCK_COUNT_MULTIPLIER;

    GetRegisterLeasePRequest noBlocks = GetRegisterLeasePRequest.newBuilder()
        .setWorkerId(WORKER_ID).setBlockCount(0).build();
    assertTrue(reviewer.reviewLeaseRequest(noBlocks));

    GetRegisterLeasePRequest adequateBlocks = GetRegisterLeasePRequest.newBuilder()
        .setWorkerId(WORKER_ID).setBlockCount(maxBlocks).build();
    assertTrue(reviewer.reviewLeaseRequest(adequateBlocks));

    GetRegisterLeasePRequest tooManyBlocks = GetRegisterLeasePRequest.newBuilder()
        .setWorkerId(WORKER_ID).setBlockCount(maxBlocks + 1).build();
    assertFalse(reviewer.reviewLeaseRequest(tooManyBlocks));
  }