@Test
  public void validateRequestsTest() {
    // choose several replicas and make them in different states (there are 10 replicas on current node)
    List<ReplicaId> localReplicas = clusterMap.getReplicaIds(dataNodeId);
    Map<ReplicaState, ReplicaId> stateToReplica = new HashMap<>();
    int cnt = 0;
    for (ReplicaState state : EnumSet.complementOf(EnumSet.of(ReplicaState.ERROR))) {
      stateToReplica.put(state, localReplicas.get(cnt));
      cnt++;
    }
    // set store state
    for (Map.Entry<ReplicaState, ReplicaId> entry : stateToReplica.entrySet()) {
      storageManager.getStore(entry.getValue().getPartitionId()).setCurrentState(entry.getKey());
    }

    for (RequestOrResponseType request : EnumSet.of(RequestOrResponseType.PutRequest, RequestOrResponseType.GetRequest,
        RequestOrResponseType.DeleteRequest, RequestOrResponseType.BatchDeleteRequest, RequestOrResponseType.TtlUpdateRequest,
        RequestOrResponseType.UndeleteRequest)) {
      for (Map.Entry<ReplicaState, ReplicaId> entry : stateToReplica.entrySet()) {
        if (request == RequestOrResponseType.PutRequest) {
          // for PUT request, it is not allowed on OFFLINE,BOOTSTRAP and INACTIVE when validateRequestOnStoreState = true
          if (AmbryServerRequests.PUT_ALLOWED_STORE_STATES.contains(entry.getKey())) {
            assertEquals("Error code is not expected for PUT request", ServerErrorCode.NoError,
                ambryRequests.validateRequest(entry.getValue().getPartitionId(), request, false));
          } else {
            assertEquals("Error code is not expected for PUT request",
                validateRequestOnStoreState ? ServerErrorCode.TemporarilyDisabled : ServerErrorCode.NoError,
                ambryRequests.validateRequest(entry.getValue().getPartitionId(), request, false));
          }
        } else if (AmbryServerRequests.UPDATE_REQUEST_TYPES.contains(request)) {
          // for UNDELETE/DELETE/TTL Update request, they are not allowed on OFFLINE,BOOTSTRAP and INACTIVE when validateRequestOnStoreState = true
          if (AmbryServerRequests.UPDATE_ALLOWED_STORE_STATES.contains(entry.getKey())) {
            assertEquals("Error code is not expected for DELETE/TTL Update", ServerErrorCode.NoError,
                ambryRequests.validateRequest(entry.getValue().getPartitionId(), request, false));
          } else {
            assertEquals("Error code is not expected for DELETE/TTL Update",
                validateRequestOnStoreState ? ServerErrorCode.TemporarilyDisabled : ServerErrorCode.NoError,
                ambryRequests.validateRequest(entry.getValue().getPartitionId(), request, false));
          }
        } else {
          // for GET request, all states should be allowed
          assertEquals("Error code is not expected for GET request", ServerErrorCode.NoError,
              ambryRequests.validateRequest(entry.getValue().getPartitionId(), request, false));
        }
      }
    }
    // reset all stores state to STANDBY
    for (Map.Entry<ReplicaState, ReplicaId> entry : stateToReplica.entrySet()) {
      storageManager.getStore(entry.getValue().getPartitionId()).setCurrentState(ReplicaState.STANDBY);
    }
  }
Tests that requests are validated based on local store state.
ambry-server/src/test/java/com/github/ambry/server/AmbryServerRequestsTest.java