use of org.apache.gobblin.util.limiter.CountBasedLimiter in project incubator-gobblin by apache.
the class SharedLimiterFactoryTest method testCountLimiter.
@Test
public void testCountLimiter() throws Exception {
SharedResourcesBrokerImpl<SimpleScopeType> broker = getBrokerForConfigMap(ImmutableMap.of(JOINER.join(BrokerConstants.GOBBLIN_BROKER_CONFIG_PREFIX, SharedLimiterFactory.NAME, SharedLimiterFactory.LIMITER_CLASS_KEY), "CountBasedLimiter", JOINER.join(BrokerConstants.GOBBLIN_BROKER_CONFIG_PREFIX, SharedLimiterFactory.NAME, CountBasedLimiter.Factory.COUNT_KEY), "10"));
SharedLimiterFactory<SimpleScopeType> factory = new SharedLimiterFactory<>();
Assert.assertEquals(factory.getAutoScope(broker, broker.getConfigView(SimpleScopeType.LOCAL, new SharedLimiterKey("resource"), factory.getName())), SimpleScopeType.GLOBAL);
Limiter limiter = ((ResourceInstance<Limiter>) factory.createResource(broker, broker.getConfigView(SimpleScopeType.GLOBAL, new SharedLimiterKey("resource"), factory.getName()))).getResource();
Assert.assertTrue(limiter instanceof CountBasedLimiter);
Assert.assertEquals(((CountBasedLimiter) limiter).getCountLimit(), 10);
}
Aggregations