@Test
  public void healthCheckTest() throws InterruptedException, StoreException, IOException {

    //retrieves writeable partitions to test with
    List<? extends PartitionId> partitionIds = clusterMap.getWritablePartitionIds(DEFAULT_PARTITION_CLASS);
    JSONObject expectedJSONReponse = new JSONObject();
    expectedJSONReponse.put("brokenDisks", new JSONArray());
    expectedJSONReponse.put("unstablePartitions", new JSONArray());

    for (PartitionId id : partitionIds) {

      // Test 1: "Good" response excepted where the host state is in either Standby or Leader
      ReplicaState originalPartitionState = storageManager.getStore(id).getCurrentState();

      //change Partition to Standby or Leader
      storageManager.getStore(id)
          .setCurrentState(TestUtils.RANDOM.nextInt() % 2 == 0 ? ReplicaState.STANDBY : ReplicaState.LEADER);

      expectedJSONReponse.put("health", ServerHealthStatus.GOOD);
      doRequestAndHealthCheck(id, "Payload was expected to indicate healthy host", expectedJSONReponse);

      //Test 2: "BAD" response expected where we change partition to error State
      //change all replica states in partition to ERROR
      storageManager.getStore(id).setCurrentState(ReplicaState.ERROR);

      expectedJSONReponse.put("health", ServerHealthStatus.BAD);
      JSONArray unstablePartitions = new JSONArray();
      JSONObject unstablePartition = new JSONObject();
      unstablePartition.put("partitionId", id);
      unstablePartition.put("reason", ReplicaState.ERROR);
      unstablePartitions.put(unstablePartition);
      expectedJSONReponse.put("unstablePartitions", unstablePartitions);
      doRequestAndHealthCheck(id, "Payload was expected to be BAD with no disk healthchecks", expectedJSONReponse);

      //restore the state of the Partition
      storageManager.getStore(id).setCurrentState(originalPartitionState);
      expectedJSONReponse.put("unstablePartitions", new JSONArray());
    }

    //Test 3: "GOOD" response expected, enabling disk healthchecking on the partition of interest and
    // disk's should be healthy

    Properties currentProperties = createProperties(validateRequestOnStoreState, true);
    setPropertyToAmbryRequests(currentProperties, "disk.manager.disk.healthcheck.enabled", "true");
    TimeUnit.SECONDS.sleep(5); // Enough time to perform each step of disk healthcheck(create,write,read,delete)

    expectedJSONReponse.put("health", ServerHealthStatus.GOOD);
    doRequestAndHealthCheck(partitionIds.get(0),
        "Payload was expected to be GOOD with all disks passing disk healthcheck", expectedJSONReponse);

    //Restores the environment from no longer using disk healthchecks
    currentProperties = createProperties(validateRequestOnStoreState, true);
    setPropertyToAmbryRequests(currentProperties, "disk.manager.disk.healthcheck.enabled", "false");
  }
Tests Replica State and Disk State for appropriate responses from healthCheck admin endpoint
@throws InterruptedException
@throws IOException
ambry-server/src/test/java/com/github/ambry/server/AmbryServerRequestsTest.java