@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 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")); }