@Override
 protected Settings nodeSettings(int nodeOrdinal) {
   return Settings.builder()
       .put(HierarchyCircuitBreakerService.FIELDDATA_CIRCUIT_BREAKER_TYPE_SETTING.getKey(), "noop")
       // This is set low, because if the "noop" is not a noop, it will break
       .put(HierarchyCircuitBreakerService.FIELDDATA_CIRCUIT_BREAKER_LIMIT_SETTING.getKey(), "10b")
       .put(HierarchyCircuitBreakerService.REQUEST_CIRCUIT_BREAKER_TYPE_SETTING.getKey(), "noop")
       // This is set low, because if the "noop" is not a noop, it will break
       .put(HierarchyCircuitBreakerService.REQUEST_CIRCUIT_BREAKER_LIMIT_SETTING.getKey(), "10b")
       .build();
 }
 /** Reset all breaker settings back to their defaults */
 private void reset() {
   logger.info("--> resetting breaker settings");
   Settings resetSettings =
       Settings.builder()
           .put(
               HierarchyCircuitBreakerService.FIELDDATA_CIRCUIT_BREAKER_LIMIT_SETTING.getKey(),
               HierarchyCircuitBreakerService.FIELDDATA_CIRCUIT_BREAKER_LIMIT_SETTING
                   .getDefaultRaw(null))
           .put(
               HierarchyCircuitBreakerService.FIELDDATA_CIRCUIT_BREAKER_OVERHEAD_SETTING.getKey(),
               HierarchyCircuitBreakerService.FIELDDATA_CIRCUIT_BREAKER_OVERHEAD_SETTING
                   .getDefaultRaw(null))
           .put(
               HierarchyCircuitBreakerService.REQUEST_CIRCUIT_BREAKER_LIMIT_SETTING.getKey(),
               HierarchyCircuitBreakerService.REQUEST_CIRCUIT_BREAKER_LIMIT_SETTING.getDefaultRaw(
                   null))
           .put(
               HierarchyCircuitBreakerService.REQUEST_CIRCUIT_BREAKER_OVERHEAD_SETTING.getKey(),
               1.0)
           .put(
               HierarchyCircuitBreakerService.IN_FLIGHT_REQUESTS_CIRCUIT_BREAKER_LIMIT_SETTING
                   .getKey(),
               HierarchyCircuitBreakerService.IN_FLIGHT_REQUESTS_CIRCUIT_BREAKER_LIMIT_SETTING
                   .getDefaultRaw(null))
           .put(
               HierarchyCircuitBreakerService.IN_FLIGHT_REQUESTS_CIRCUIT_BREAKER_OVERHEAD_SETTING
                   .getKey(),
               1.0)
           .put(
               HierarchyCircuitBreakerService.TOTAL_CIRCUIT_BREAKER_LIMIT_SETTING.getKey(),
               HierarchyCircuitBreakerService.TOTAL_CIRCUIT_BREAKER_LIMIT_SETTING.getDefaultRaw(
                   null))
           .build();
   assertAcked(
       client().admin().cluster().prepareUpdateSettings().setTransientSettings(resetSettings));
 }
  public void testRequestBreaker() throws Exception {
    if (noopBreakerUsed()) {
      logger.info("--> noop breakers used, skipping test");
      return;
    }
    assertAcked(
        prepareCreate(
            "cb-test", 1, Settings.builder().put(SETTING_NUMBER_OF_REPLICAS, between(0, 1))));
    Client client = client();

    // Make request breaker limited to a small amount
    Settings resetSettings =
        Settings.builder()
            .put(
                HierarchyCircuitBreakerService.REQUEST_CIRCUIT_BREAKER_LIMIT_SETTING.getKey(),
                "10b")
            .build();
    assertAcked(
        client.admin().cluster().prepareUpdateSettings().setTransientSettings(resetSettings));

    // index some different terms so we have some field data for loading
    int docCount = scaledRandomIntBetween(300, 1000);
    List<IndexRequestBuilder> reqs = new ArrayList<>();
    for (long id = 0; id < docCount; id++) {
      reqs.add(client.prepareIndex("cb-test", "type", Long.toString(id)).setSource("test", id));
    }
    indexRandom(true, reqs);

    // A cardinality aggregation uses BigArrays and thus the REQUEST breaker
    try {
      client
          .prepareSearch("cb-test")
          .setQuery(matchAllQuery())
          .addAggregation(cardinality("card").field("test"))
          .get();
      fail("aggregation should have tripped the breaker");
    } catch (Exception e) {
      String errMsg =
          "CircuitBreakingException[[request] Data too large, data for [<reused_arrays>] would be larger than limit of [10/10b]]";
      assertThat(
          "Exception: [" + e.toString() + "] should contain a CircuitBreakingException",
          e.toString(),
          containsString(errMsg));
    }
  }