Search in sources :

Example 6 with CountBasedLimiter

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);
}
Also used : CountBasedLimiter(org.apache.gobblin.util.limiter.CountBasedLimiter) ResourceInstance(org.apache.gobblin.broker.ResourceInstance) 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

CountBasedLimiter (org.apache.gobblin.util.limiter.CountBasedLimiter)6 Limiter (org.apache.gobblin.util.limiter.Limiter)6 Test (org.testng.annotations.Test)6 ResourceInstance (org.apache.gobblin.broker.ResourceInstance)2 SimpleScopeType (org.apache.gobblin.broker.SimpleScopeType)2 MultiLimiter (org.apache.gobblin.util.limiter.MultiLimiter)2 NoopLimiter (org.apache.gobblin.util.limiter.NoopLimiter)2 NotEnoughPermitsException (org.apache.gobblin.util.limiter.NotEnoughPermitsException)2 FileStatus (org.apache.hadoop.fs.FileStatus)2 FileSystem (org.apache.hadoop.fs.FileSystem)2 Path (org.apache.hadoop.fs.Path)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 SimpleScope (org.apache.gobblin.broker.SimpleScope)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1