@AdviseWith(adviceClasses = PropsUtilAdvice.class)
  @Test
  public void testValidSetting() {
    Map<String, String> props = new HashMap<String, String>();

    props.put(PropsKeys.BUFFERED_INCREMENT_ENABLED, "false");
    props.put(PropsKeys.BUFFERED_INCREMENT_STANDBY_QUEUE_THRESHOLD, "10");
    props.put(PropsKeys.BUFFERED_INCREMENT_STANDBY_TIME_UPPER_LIMIT, "20");
    props.put(PropsKeys.BUFFERED_INCREMENT_THREADPOOL_KEEP_ALIVE_TIME, "30");
    props.put(PropsKeys.BUFFERED_INCREMENT_THREADPOOL_MAX_SIZE, "40");

    PropsUtilAdvice.setProps(props);

    BufferedIncrementConfiguration bufferedIncrementConfiguration =
        new BufferedIncrementConfiguration(StringPool.BLANK);

    Assert.assertFalse(bufferedIncrementConfiguration.isEnabled());
    Assert.assertEquals(10, bufferedIncrementConfiguration.getStandbyQueueThreshold());
    Assert.assertEquals(20, bufferedIncrementConfiguration.getStandbyTimeUpperLimit());
    Assert.assertEquals(30, bufferedIncrementConfiguration.getThreadpoolKeepAliveTime());
    Assert.assertEquals(40, bufferedIncrementConfiguration.getThreadpoolMaxSize());
    Assert.assertTrue(bufferedIncrementConfiguration.isStandbyEnabled());

    try {
      bufferedIncrementConfiguration.calculateStandbyTime(-1);
    } catch (IllegalArgumentException iae) {
      Assert.assertEquals("Negative queue length -1", iae.getMessage());
    }

    int standbyQueueThreshold = bufferedIncrementConfiguration.getStandbyQueueThreshold();
    long standbyTimeUpperLimit = bufferedIncrementConfiguration.getStandbyTimeUpperLimit();

    long standbyTime = bufferedIncrementConfiguration.calculateStandbyTime(0);

    Assert.assertEquals(standbyTimeUpperLimit * 1000, standbyTime);

    standbyTime = bufferedIncrementConfiguration.calculateStandbyTime(standbyQueueThreshold / 2);

    Assert.assertEquals(standbyTimeUpperLimit * 1000 / 2, standbyTime);

    standbyTime = bufferedIncrementConfiguration.calculateStandbyTime(standbyQueueThreshold);

    Assert.assertEquals(0, standbyTime);

    standbyTime = bufferedIncrementConfiguration.calculateStandbyTime(standbyQueueThreshold + 1);

    Assert.assertEquals(0, standbyTime);

    standbyTime = bufferedIncrementConfiguration.calculateStandbyTime(standbyQueueThreshold * 2);

    Assert.assertEquals(0, standbyTime);
  }
  private CaptureHandler _doTestInvalidSetting(Level level) {
    Map<String, String> props = new HashMap<String, String>();

    props.put(PropsKeys.BUFFERED_INCREMENT_ENABLED, "false");

    if (level == Level.OFF) {
      props.put(PropsKeys.BUFFERED_INCREMENT_STANDBY_QUEUE_THRESHOLD, "1");
      props.put(PropsKeys.BUFFERED_INCREMENT_STANDBY_TIME_UPPER_LIMIT, "-1");
    } else {
      props.put(PropsKeys.BUFFERED_INCREMENT_STANDBY_QUEUE_THRESHOLD, "-1");
      props.put(PropsKeys.BUFFERED_INCREMENT_STANDBY_TIME_UPPER_LIMIT, "1");
    }

    props.put(PropsKeys.BUFFERED_INCREMENT_THREADPOOL_KEEP_ALIVE_TIME, "-3");
    props.put(PropsKeys.BUFFERED_INCREMENT_THREADPOOL_MAX_SIZE, "-4");

    PropsUtilAdvice.setProps(props);

    CaptureHandler captureHandler =
        JDKLoggerTestUtil.configureJDKLogger(BufferedIncrementConfiguration.class.getName(), level);

    BufferedIncrementConfiguration bufferedIncrementConfiguration =
        new BufferedIncrementConfiguration(StringPool.BLANK);

    Assert.assertFalse(bufferedIncrementConfiguration.isEnabled());

    if (level == Level.OFF) {
      Assert.assertEquals(1, bufferedIncrementConfiguration.getStandbyQueueThreshold());
      Assert.assertEquals(-1, bufferedIncrementConfiguration.getStandbyTimeUpperLimit());
    } else {
      Assert.assertEquals(-1, bufferedIncrementConfiguration.getStandbyQueueThreshold());
      Assert.assertEquals(1, bufferedIncrementConfiguration.getStandbyTimeUpperLimit());
    }

    Assert.assertEquals(0, bufferedIncrementConfiguration.getThreadpoolKeepAliveTime());
    Assert.assertEquals(1, bufferedIncrementConfiguration.getThreadpoolMaxSize());
    Assert.assertFalse(bufferedIncrementConfiguration.isStandbyEnabled());

    try {
      bufferedIncrementConfiguration.calculateStandbyTime(0);
    } catch (IllegalStateException ise) {
      Assert.assertEquals("Standby is disabled", ise.getMessage());
    }

    return captureHandler;
  }