public static DegraderImpl.Config toDegraderConfig(Map<String, String> properties)
  {
    DegraderImpl.Config config = new DegraderImpl.Config();
    if (properties == null || properties.isEmpty())
    {
      return config;
    }
    else
    {
      // we are not modifying config's callTracker, name, clock and overrideDropRate because
      // that will be set during the construction of TrackerClient
      config.setLogEnabled(MapUtil.getWithDefault(properties,
                                                  PropertyKeys.DEGRADER_LOG_ENABLED,
                                                  DegraderImpl.DEFAULT_LOG_ENABLED));

      config.setLogThreshold(MapUtil.getWithDefault(properties, PropertyKeys.DEGRADER_LOG_THRESHOLD,
          DegraderImpl.DEFAULT_LOG_THRESHOLD));

      if (properties.get(PropertyKeys.DEGRADER_LATENCY_TO_USE) != null)
      {
        try
        {
          config.setLatencyToUse(DegraderImpl.LatencyToUse.valueOf(properties.get(PropertyKeys.
                                                                                      DEGRADER_LATENCY_TO_USE)));
        }
        catch (IllegalArgumentException e)
        {
          warn(_log, "Received an illegal enum for latencyToUse in the cluster properties. The enum is " +
              properties.get(PropertyKeys.DEGRADER_LATENCY_TO_USE), e);
          config.setLatencyToUse(DegraderImpl.DEFAULT_LATENCY_TO_USE);
        }
      }

      config.setMaxDropRate(MapUtil.getWithDefault(properties, PropertyKeys.DEGRADER_MAX_DROP_RATE,
                                                   DegraderImpl.DEFAULT_MAX_DROP_RATE));

      config.setMaxDropDuration(MapUtil.getWithDefault(properties,
                                                       PropertyKeys.DEGRADER_MAX_DROP_DURATION,
                                                       DegraderImpl.DEFAULT_MAX_DROP_DURATION ));

      config.setUpStep(MapUtil.getWithDefault(properties, PropertyKeys.DEGRADER_UP_STEP,
                                              DegraderImpl.DEFAULT_UP_STEP));

      config.setDownStep(MapUtil.getWithDefault(properties, PropertyKeys.DEGRADER_DOWN_STEP,
                                                DegraderImpl.DEFAULT_DOWN_STEP));

      config.setMinCallCount(MapUtil.getWithDefault(properties,
                                                    PropertyKeys.DEGRADER_MIN_CALL_COUNT,
                                                    DegraderImpl.DEFAULT_MIN_CALL_COUNT));

      config.setHighLatency(MapUtil.getWithDefault(properties,
                                                   PropertyKeys.DEGRADER_HIGH_LATENCY,
                                                   DegraderImpl.DEFAULT_HIGH_LATENCY));

      config.setLowLatency(MapUtil.getWithDefault(properties,
                                                  PropertyKeys.DEGRADER_LOW_LATENCY,
                                                  DegraderImpl.DEFAULT_LOW_LATENCY));

      config.setHighErrorRate(MapUtil.getWithDefault(properties,
                                                     PropertyKeys.DEGRADER_HIGH_ERROR_RATE,
                                                     DegraderImpl.DEFAULT_HIGH_ERROR_RATE));

      config.setLowErrorRate(MapUtil.getWithDefault(properties,
                                                    PropertyKeys.DEGRADER_LOW_ERROR_RATE,
                                                    DegraderImpl.DEFAULT_LOW_ERROR_RATE));

      config.setHighOutstanding(MapUtil.getWithDefault(properties,
                                                       PropertyKeys.DEGRADER_HIGH_OUTSTANDING,
                                                       DegraderImpl.DEFAULT_HIGH_OUTSTANDING));

      config.setLowOutstanding(MapUtil.getWithDefault(properties,
                                                      PropertyKeys.DEGRADER_LOW_OUTSTANDING,
                                                      DegraderImpl.DEFAULT_LOW_OUTSTANDING));

      config.setMinOutstandingCount(MapUtil.getWithDefault(properties,
                                                           PropertyKeys.DEGRADER_MIN_OUTSTANDING_COUNT,
                                                           DegraderImpl.DEFAULT_MIN_OUTSTANDING_COUNT));

      config.setOverrideMinCallCount(MapUtil.getWithDefault(properties,
                                                            PropertyKeys.DEGRADER_OVERRIDE_MIN_CALL_COUNT,
                                                            DegraderImpl.DEFAULT_OVERRIDE_MIN_CALL_COUNT));

      config.setInitialDropRate(MapUtil.getWithDefault(properties,
                                                       PropertyKeys.DEGRADER_INITIAL_DROP_RATE,
                                                       DegraderImpl.DEFAULT_INITIAL_DROP_RATE));

      config.setSlowStartThreshold(MapUtil.getWithDefault(properties,
                                                          PropertyKeys.DEGRADER_SLOW_START_THRESHOLD,
                                                          DegraderImpl.DEFAULT_SLOW_START_THRESHOLD));

      config.setPreemptiveRequestTimeoutRate(MapUtil.getWithDefault(properties,
                                                                    PropertyKeys.DEGRADER_PREEMPTIVE_REQUEST_TIMEOUT_RATE,
                                                                    DegraderImpl.DEFAULT_PREEMPTIVE_REQUEST_TIMEOUT_RATE));
    }
    return config;
  }
@Test
  public void testToDegraderConfig()
  {
    Map<String,String> properties = new HashMap<>();;
    Boolean logEnabled = false;
    DegraderImpl.LatencyToUse latencyToUse = DegraderImpl.LatencyToUse.PCT95;
    Double maxDropRate = 0.33;
    Long maxDropDuration = 23190l;
    Double upStep = 0.3;
    Double downstep = 0.2;
    Integer minCallCount = 22;
    Long highLatency = 30000000l;
    Long lowLatency = 244499l;
    Double highErrorRate = 0.5;
    Double lowErrorRate = 0.1;
    Long highOutstanding = 10000l;
    Long lowOutstanding = 3000l;
    Integer minOutstandingCount = 10;
    Integer overrideMinCallCount = 5;
    Double logThreshold = 0.8;
    Double preemptiveRequestTimeoutRate = 0.5;
    properties.put(PropertyKeys.DEGRADER_LOG_ENABLED, logEnabled.toString());
    properties.put(PropertyKeys.DEGRADER_LATENCY_TO_USE, latencyToUse.toString());
    properties.put(PropertyKeys.DEGRADER_MAX_DROP_RATE, maxDropRate.toString());
    properties.put(PropertyKeys.DEGRADER_MAX_DROP_DURATION, maxDropDuration.toString());
    properties.put(PropertyKeys.DEGRADER_UP_STEP, upStep.toString());
    properties.put(PropertyKeys.DEGRADER_DOWN_STEP, downstep.toString());
    properties.put(PropertyKeys.DEGRADER_MIN_CALL_COUNT, minCallCount.toString());
    properties.put(PropertyKeys.DEGRADER_HIGH_LATENCY, highLatency.toString());
    properties.put(PropertyKeys.DEGRADER_LOW_LATENCY, lowLatency.toString());
    properties.put(PropertyKeys.DEGRADER_HIGH_ERROR_RATE, highErrorRate.toString());
    properties.put(PropertyKeys.DEGRADER_LOW_ERROR_RATE, lowErrorRate.toString());
    properties.put(PropertyKeys.DEGRADER_HIGH_OUTSTANDING, highOutstanding.toString());
    properties.put(PropertyKeys.DEGRADER_LOW_OUTSTANDING, lowOutstanding.toString());
    properties.put(PropertyKeys.DEGRADER_MIN_OUTSTANDING_COUNT, minOutstandingCount.toString());
    properties.put(PropertyKeys.DEGRADER_OVERRIDE_MIN_CALL_COUNT, overrideMinCallCount.toString());
    properties.put(PropertyKeys.DEGRADER_LOG_THRESHOLD, logThreshold.toString());
    properties.put(PropertyKeys.DEGRADER_PREEMPTIVE_REQUEST_TIMEOUT_RATE, preemptiveRequestTimeoutRate.toString());
    DegraderImpl.Config config = DegraderConfigFactory.toDegraderConfig(properties);
    assertEquals(config.isLogEnabled(), logEnabled.booleanValue());
    assertEquals(config.getLatencyToUse(), latencyToUse);
    assertEquals(config.getMaxDropRate(), maxDropRate);
    assertEquals(config.getMaxDropDuration(), maxDropDuration.longValue());
    assertEquals(config.getUpStep(), upStep.doubleValue());
    assertEquals(config.getDownStep(), downstep.doubleValue());
    assertEquals(config.getMinCallCount(), minCallCount.intValue());
    assertEquals(config.getHighLatency(), highLatency.longValue());
    assertEquals(config.getLowLatency(), lowLatency.longValue());
    assertEquals(config.getHighErrorRate(), highErrorRate.doubleValue());
    assertEquals(config.getLowErrorRate(), lowErrorRate.doubleValue());
    assertEquals(config.getHighOutstanding(), highOutstanding.longValue());
    assertEquals(config.getLowOutstanding(), lowOutstanding.longValue());
    assertEquals(config.getMinOutstandingCount(), minOutstandingCount.longValue());
    assertEquals(config.getOverrideMinCallCount(), overrideMinCallCount.intValue());
    assertEquals(config.getLogThreshold(), logThreshold);
    assertEquals(config.getPreemptiveRequestTimeoutRate(), preemptiveRequestTimeoutRate);
  }