Search in sources :

Example 1 with SimpleScope

use of org.apache.gobblin.broker.SimpleScope in project incubator-gobblin by apache.

the class SharedLimiterFactoryTest method testMultiLevelLimiter.

@Test
public void testMultiLevelLimiter() throws Exception {
    SharedResourcesBrokerImpl<SimpleScopeType> broker = getBrokerForConfigMap(ImmutableMap.of(JOINER.join(BrokerConstants.GOBBLIN_BROKER_CONFIG_PREFIX, SharedLimiterFactory.NAME, SimpleScopeType.GLOBAL, SharedLimiterFactory.LIMITER_CLASS_KEY), "CountBasedLimiter", JOINER.join(BrokerConstants.GOBBLIN_BROKER_CONFIG_PREFIX, SharedLimiterFactory.NAME, SimpleScopeType.GLOBAL, CountBasedLimiter.Factory.COUNT_KEY), "10", JOINER.join(BrokerConstants.GOBBLIN_BROKER_CONFIG_PREFIX, SharedLimiterFactory.NAME, SimpleScopeType.LOCAL, SharedLimiterFactory.LIMITER_CLASS_KEY), "CountBasedLimiter", JOINER.join(BrokerConstants.GOBBLIN_BROKER_CONFIG_PREFIX, SharedLimiterFactory.NAME, SimpleScopeType.LOCAL, CountBasedLimiter.Factory.COUNT_KEY), "5"));
    SharedResourcesBroker<SimpleScopeType> localBroker1 = broker.newSubscopedBuilder(new SimpleScope<>(SimpleScopeType.LOCAL, "local1")).build();
    SharedResourcesBroker<SimpleScopeType> localBroker2 = broker.newSubscopedBuilder(new SimpleScope<>(SimpleScopeType.LOCAL, "local2")).build();
    SharedLimiterFactory<SimpleScopeType> factory = new SharedLimiterFactory<>();
    Limiter limiter1 = ((ResourceInstance<Limiter>) factory.createResource(localBroker1, broker.getConfigView(SimpleScopeType.LOCAL, new SharedLimiterKey("resource"), factory.getName()))).getResource();
    Limiter limiter2 = ((ResourceInstance<Limiter>) factory.createResource(localBroker2, broker.getConfigView(SimpleScopeType.LOCAL, new SharedLimiterKey("resource"), factory.getName()))).getResource();
    Assert.assertTrue(limiter1 instanceof MultiLimiter);
    Assert.assertTrue(limiter2 instanceof MultiLimiter);
    Assert.assertEquals(((CountBasedLimiter) ((MultiLimiter) limiter1).getUnderlyingLimiters().get(0)).getCountLimit(), 5);
    Assert.assertEquals(((CountBasedLimiter) ((MultiLimiter) limiter1).getUnderlyingLimiters().get(1)).getCountLimit(), 10);
    Assert.assertEquals(((CountBasedLimiter) ((MultiLimiter) limiter2).getUnderlyingLimiters().get(0)).getCountLimit(), 5);
    Assert.assertEquals(((CountBasedLimiter) ((MultiLimiter) limiter2).getUnderlyingLimiters().get(1)).getCountLimit(), 10);
    Assert.assertNotEquals(((MultiLimiter) limiter1).getUnderlyingLimiters().get(0), ((MultiLimiter) limiter2).getUnderlyingLimiters().get(0));
    Assert.assertEquals(((MultiLimiter) limiter1).getUnderlyingLimiters().get(1), ((MultiLimiter) limiter2).getUnderlyingLimiters().get(1));
}
Also used : SimpleScope(org.apache.gobblin.broker.SimpleScope) ResourceInstance(org.apache.gobblin.broker.ResourceInstance) MultiLimiter(org.apache.gobblin.util.limiter.MultiLimiter) SimpleScopeType(org.apache.gobblin.broker.SimpleScopeType) Limiter(org.apache.gobblin.util.limiter.Limiter) CountBasedLimiter(org.apache.gobblin.util.limiter.CountBasedLimiter) MultiLimiter(org.apache.gobblin.util.limiter.MultiLimiter) NoopLimiter(org.apache.gobblin.util.limiter.NoopLimiter) Test(org.testng.annotations.Test)

Aggregations

ResourceInstance (org.apache.gobblin.broker.ResourceInstance)1 SimpleScope (org.apache.gobblin.broker.SimpleScope)1 SimpleScopeType (org.apache.gobblin.broker.SimpleScopeType)1 CountBasedLimiter (org.apache.gobblin.util.limiter.CountBasedLimiter)1 Limiter (org.apache.gobblin.util.limiter.Limiter)1 MultiLimiter (org.apache.gobblin.util.limiter.MultiLimiter)1 NoopLimiter (org.apache.gobblin.util.limiter.NoopLimiter)1 Test (org.testng.annotations.Test)1