@Test
  public void testIncrementRLCounterNonExistent() {
    providerImpl.addActiveRL(rl_key, createModel());

    providerImpl.incrementRLCounter(rl_key + "02");
    assertEquals(
        "rl_key counter should remain in 1", 1, providerImpl.getActiveRL(rl_key).getCount());
  }
  @Test
  public void testSetRLCounter() {

    providerImpl.setRLCounter(rl_key, 1);
    assertEquals("rl_key counter should be 1", 1, providerImpl.getActiveRL(rl_key).getCount());

    providerImpl.setRLCounter(rl_key, 5);
    assertEquals("rl_key counter should be 5", 5, providerImpl.getActiveRL(rl_key).getCount());
  }
  @Test
  public void testSetActive() {
    providerImpl.addActiveRL(rl_key, createModel());
    providerImpl.addActiveRL(rl_key + "01", createModel());

    providerImpl.setRLActive(rl_key, false);
    assertEquals(
        "rl_key counter should be false", false, providerImpl.getActiveRL(rl_key).isActive());
    assertEquals(
        "rl_key counter should be true", true, providerImpl.getActiveRL(rl_key + "01").isActive());
  }
  @Test
  public void testAddActiveRL() {
    providerImpl.addActiveRL(rl_key, rateLimiterPolicyModel_1);

    RateLimiterPolicyModel activeRL = providerImpl.getActiveRL(rl_key);
    assertNotNull("rateLimiterPolicyModel_1 element must exist for key" + rl_key, activeRL);
    assertEquals(rateLimiterPolicyModel_1.getCount(), activeRL.getCount());
    assertEquals(rateLimiterPolicyModel_1.getEffect(), activeRL.getEffect());
    assertEquals(rateLimiterPolicyModel_1.getEffectDuration(), activeRL.getEffectDuration());
    assertEquals(rateLimiterPolicyModel_1.getIp(), activeRL.getIp());
    assertEquals(rateLimiterPolicyModel_1.getRolloverPeriod(), activeRL.getRolloverPeriod());
    assertEquals(new Date(createdTime).getTime(), activeRL.getTimestamp().getTime());
  }
 @Test
 public void testSetTimestamp() {
   providerImpl.addActiveRL(rl_key, createModel());
   providerImpl.addActiveRL(rl_key + "01", createModel());
   long newCreatedTime = System.currentTimeMillis();
   providerImpl.setRLTimestamp(rl_key, new Date(newCreatedTime));
   assertEquals(
       "rl_key counter should be " + newCreatedTime,
       newCreatedTime,
       providerImpl.getActiveRL(rl_key).getTimestamp().getTime());
   assertEquals(
       "rl_key counter should be " + createdTime,
       createdTime,
       providerImpl.getActiveRL(rl_key + "01").getTimestamp().getTime());
 }
 @Test
 public void testSetEffectDuration() {
   providerImpl.addActiveRL(rl_key, createModel());
   providerImpl.addActiveRL(rl_key + "01", createModel());
   long effectDuration = createdTime + 3600L * 1000;
   providerImpl.setRLEffectDuration(rl_key, 5000L);
   assertEquals(
       "rl_key counter should be 5000 as long",
       5000L,
       providerImpl.getActiveRL(rl_key).getEffectDuration().longValue());
   assertEquals(
       "rl_key counter should be " + effectDuration + " as Long",
       effectDuration,
       providerImpl.getActiveRL(rl_key + "01").getEffectDuration().longValue());
 }
  @Test
  public void testSetEffect() {
    providerImpl.addActiveRL(rl_key, createModel());
    providerImpl.addActiveRL(rl_key + "01", createModel());

    providerImpl.setRLEffect(rl_key, RateLimiterStatus.SERVE_GIF);
    assertEquals(
        "rl_key counter should be SERVE_GIF",
        RateLimiterStatus.SERVE_GIF,
        providerImpl.getActiveRL(rl_key).getEffect());
    assertEquals(
        "rl_key counter should be BLOCK",
        RateLimiterStatus.BLOCK,
        providerImpl.getActiveRL(rl_key + "01").getEffect());
  }
  @Test
  public void testSetRolloverPeriod() {
    providerImpl.addActiveRL(rl_key, createModel());
    providerImpl.addActiveRL(rl_key + "01", createModel());

    providerImpl.setRLRolloverPeriod(rl_key, 1000L);
    assertEquals(
        "rl_key counter should be 1000 as Long",
        1000L,
        providerImpl.getActiveRL(rl_key).getRolloverPeriod().longValue());

    assertEquals(
        "rl_key counter should be 60 as Long",
        60L,
        providerImpl.getActiveRL(rl_key + "01").getRolloverPeriod().longValue());
  }
  @Test
  public void testRessetEffect()
      throws SecurityException, NoSuchFieldException, IllegalArgumentException,
          IllegalAccessException {
    providerImpl.addActiveEffect(effect_key, createModel());
    providerImpl.addActiveRL(effect_key, createModel());
    RateLimiterPolicyModel rateLimiterPolicyModel_2 = createModel();

    rateLimiterPolicyModel_2.setEffectDuration(createdTime - 60 * 1000);
    providerImpl.addActiveEffect(effect_key + "01", rateLimiterPolicyModel_2);

    providerImpl.resetEffects();

    Field field = RateLimiterCounterCassandraProviderImpl.class.getDeclaredField("activeEffectDao");
    field.setAccessible(true);
    ActiveEffectDaoImpl activeEffectDaoImpl = (ActiveEffectDaoImpl) field.get(providerImpl);

    assertTrue(
        effect_key + " key must exist in effect CF ", activeEffectDaoImpl.containsKey(effect_key));
    assertNotNull(effect_key + " should not be null", activeEffectDaoImpl.find(effect_key));
    assertNull(effect_key + " 01 must be null", activeEffectDaoImpl.find(effect_key + "01"));
  }
  @Test
  public void testIncrementRLCounter() {
    providerImpl.addActiveRL(rl_key, createModel());
    providerImpl.addActiveRL(rl_key + "01", createModel());

    assertTrue("No element found in activeRL map", providerImpl.cointainKeyInActiveRL(rl_key));

    providerImpl.incrementRLCounter(rl_key);
    assertEquals("rl_key counter should be 2", 2, providerImpl.getActiveRL(rl_key).getCount());

    providerImpl.incrementRLCounter(rl_key);
    assertEquals("rl_key counter should be 3", 3, providerImpl.getActiveRL(rl_key).getCount());

    assertEquals(
        "rl_key counter should be 1", 1, providerImpl.getActiveRL(rl_key + "01").getCount());
  }
  @Test
  public void testGetActiveRLKeys() {
    Set<String> activeRLKeys = providerImpl.getActiveRLKeys();
    assertNotNull(activeRLKeys);
    assertTrue(activeRLKeys.isEmpty());

    providerImpl.addActiveRL(rl_key, rateLimiterPolicyModel_1);
    RateLimiterPolicyModel rateLimiterPolicyModel_2 = new RateLimiterPolicyModel();
    rateLimiterPolicyModel_2.setActive(false);
    rateLimiterPolicyModel_2.setCount(rateLimiterPolicyModel_1.getCount());
    rateLimiterPolicyModel_2.setEffect(rateLimiterPolicyModel_1.getEffect());
    rateLimiterPolicyModel_2.setEffectDuration(rateLimiterPolicyModel_1.getEffectDuration());
    rateLimiterPolicyModel_2.setIp(rateLimiterPolicyModel_1.getIp());
    rateLimiterPolicyModel_2.setRolloverPeriod(rateLimiterPolicyModel_1.getRolloverPeriod());
    rateLimiterPolicyModel_2.setTimestamp(rateLimiterPolicyModel_1.getTimestamp());

    providerImpl.addActiveRL(rl_key, rateLimiterPolicyModel_1);
    providerImpl.addActiveRL(rl_key + "01", rateLimiterPolicyModel_2);
    Set<String> activeRLKeys2 = providerImpl.getActiveRLKeys();
    assertEquals("activeRL should have 2 elements", 2, activeRLKeys2.size());
    assertTrue(rl_key + " should be in activeRLCF ", activeRLKeys2.contains(rl_key));
    assertTrue(rl_key + "01" + " should be in activeRLCF ", activeRLKeys2.contains(rl_key + "01"));
  }
  @Test
  public void testAddActiveEffect() throws Exception {
    providerImpl.addActiveEffect(effect_key, rateLimiterPolicyModel_1);

    Field field = RateLimiterCounterCassandraProviderImpl.class.getDeclaredField("activeEffectDao");
    field.setAccessible(true);
    ActiveEffectDaoImpl activeEffectDaoImpl = (ActiveEffectDaoImpl) field.get(providerImpl);

    assertTrue(
        effect_key + " key must exist in effect CF ", activeEffectDaoImpl.containsKey(effect_key));

    RateLimiterPolicyModel activeEffect = activeEffectDaoImpl.find(effect_key);
    assertNotNull("rateLimiterPolicyModel_1 element must exist for key" + effect_key, activeEffect);
    assertEquals(rateLimiterPolicyModel_1.getCount(), activeEffect.getCount());
    assertEquals(rateLimiterPolicyModel_1.getEffect(), activeEffect.getEffect());
    assertEquals(rateLimiterPolicyModel_1.getEffectDuration(), activeEffect.getEffectDuration());
    assertEquals(rateLimiterPolicyModel_1.getIp(), activeEffect.getIp());
    assertEquals(rateLimiterPolicyModel_1.getRolloverPeriod(), activeEffect.getRolloverPeriod());
    assertEquals(new Date(createdTime).getTime(), activeEffect.getTimestamp().getTime());
  }
 @Test
 public void testCointainKeyInActiveRL() {
   providerImpl.addActiveRL(rl_key, rateLimiterPolicyModel_1);
   assertTrue(
       rl_key + " key must exist in activeRLCF ", providerImpl.cointainKeyInActiveRL(rl_key));
 }