public void testCustomCircuitBreakerRegistration() throws Exception {
    Iterable<CircuitBreakerService> serviceIter =
        internalCluster().getInstances(CircuitBreakerService.class);

    final String breakerName = "customBreaker";
    BreakerSettings breakerSettings = new BreakerSettings(breakerName, 8, 1.03);
    CircuitBreaker breaker = null;

    for (CircuitBreakerService s : serviceIter) {
      s.registerBreaker(breakerSettings);
      breaker = s.getBreaker(breakerSettings.getName());
    }

    if (breaker != null) {
      try {
        breaker.addEstimateBytesAndMaybeBreak(16, "test");
      } catch (CircuitBreakingException e) {
        // ignore, we forced a circuit break
      }
    }

    NodesStatsResponse stats =
        client().admin().cluster().prepareNodesStats().clear().setBreaker(true).get();
    int breaks = 0;
    for (NodeStats stat : stats.getNodes()) {
      CircuitBreakerStats breakerStats = stat.getBreaker().getStats(breakerName);
      breaks += breakerStats.getTrippedCount();
    }
    assertThat(breaks, greaterThanOrEqualTo(1));
  }
 /**
  * Adjust the breaker when no terms were actually loaded, but the field data takes up space
  * regardless. For instance, when ordinals are used.
  *
  * @param actualUsed bytes actually used
  */
 public void adjustForNoTerms(long actualUsed) {
   breaker.addWithoutBreaking(actualUsed);
 }
 /**
  * Adjusts the breaker based on the aggregated value from the RamAccountingTermsEnum
  *
  * @param termsEnum terms that were wrapped and loaded
  * @param actualUsed actual field data memory usage
  */
 @Override
 public void afterLoad(TermsEnum termsEnum, long actualUsed) {
   assert termsEnum instanceof RamAccountingTermsEnum;
   long estimatedBytes = ((RamAccountingTermsEnum) termsEnum).getTotalBytes();
   breaker.addWithoutBreaking(-(estimatedBytes - actualUsed));
 }