@Override
  public String attemptRequest() throws RemoteServiceException {
    evaluateState();
    if (state == State.OPEN) {
      // return cached response if the circuit is in OPEN state
      return this.lastFailureResponse;
    } else {
      // Make the API request if the circuit is not OPEN
      try {
        //In a real application, this would be run in a thread and the timeout
        //parameter of the circuit breaker would be utilized to know if service
        //is working. Here, we simulate that based on server response itself
        var response = service.call();
        // Yay!! the API responded fine. Let's reset everything.
        recordSuccess();
        return response;
      } catch (RemoteServiceException ex) {
        recordFailure(ex.getMessage());
        throw ex;
      }
    }
  }
@Test
  void testApiResponses() throws RemoteServiceException {
    RemoteService mockService = new RemoteService() {
      @Override
      public String call() throws RemoteServiceException {
        return "Remote Success";
      }
    };
    var circuitBreaker = new DefaultCircuitBreaker(mockService, 1, 1, 100);
    //Call with the parameter start_time set to huge amount of time in past so that service
    //replies with "Ok". Also, state is CLOSED in start
    var serviceStartTime = System.nanoTime() - 60 * 1000 * 1000 * 1000;
    var response = circuitBreaker.attemptRequest();
    assertEquals(response, "Remote Success");
  }