Search in sources :

Example 11 with Limiter

use of org.apache.gobblin.util.limiter.Limiter in project incubator-gobblin by apache.

the class RatedControlledFileSystemTest method setUp.

@BeforeClass
public void setUp() throws IOException, ExecutionException {
    Limiter limiter = new RateBasedLimiter(20);
    this.rateControlledFs = new TestRateControlledFileSystem(FileSystem.getLocal(new Configuration()), 20, limiter);
    this.rateControlledFs.startRateControl();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) RateBasedLimiter(org.apache.gobblin.util.limiter.RateBasedLimiter) RateBasedLimiter(org.apache.gobblin.util.limiter.RateBasedLimiter) Limiter(org.apache.gobblin.util.limiter.Limiter) BeforeClass(org.testng.annotations.BeforeClass)

Example 12 with Limiter

use of org.apache.gobblin.util.limiter.Limiter in project incubator-gobblin by apache.

the class ThrottledFileSystemTest method testSimpleCalls.

@Test
public void testSimpleCalls() throws Exception {
    FileSystem fs = Mockito.mock(FileSystem.class);
    Mockito.when(fs.getFileStatus(Mockito.any(Path.class))).thenReturn(new FileStatus(0, false, 0, 0, 0, new Path("/")));
    Limiter limiter = new CountBasedLimiter(2);
    ThrottledFileSystem throttledFileSystem = new ThrottledFileSystem(fs, limiter, "testService");
    Assert.assertNotNull(throttledFileSystem.getFileStatus(new Path("/myFile")));
    Assert.assertNotNull(throttledFileSystem.getFileStatus(new Path("/myFile")));
    try {
        throttledFileSystem.getFileStatus(new Path("/myFile"));
        Assert.fail();
    } catch (NotEnoughPermitsException expected) {
    // Expected
    }
}
Also used : Path(org.apache.hadoop.fs.Path) CountBasedLimiter(org.apache.gobblin.util.limiter.CountBasedLimiter) FileStatus(org.apache.hadoop.fs.FileStatus) FileSystem(org.apache.hadoop.fs.FileSystem) NotEnoughPermitsException(org.apache.gobblin.util.limiter.NotEnoughPermitsException) Limiter(org.apache.gobblin.util.limiter.Limiter) CountBasedLimiter(org.apache.gobblin.util.limiter.CountBasedLimiter) Test(org.testng.annotations.Test)

Example 13 with Limiter

use of org.apache.gobblin.util.limiter.Limiter in project incubator-gobblin by apache.

the class ThrottledInputStreamTest method test.

@Test
public void test() throws Exception {
    ByteArrayInputStream inputStream = new ByteArrayInputStream("abcde".getBytes(Charsets.UTF_8));
    MeteredInputStream meteredInputStream = MeteredInputStream.builder().in(inputStream).updateFrequency(1).build();
    Limiter limiter = new CountBasedLimiter(4);
    InputStream throttled = new ThrottledInputStream(meteredInputStream, limiter, meteredInputStream);
    try {
        String output = IOUtils.toString(throttled, Charsets.UTF_8);
        Assert.fail();
    } catch (RuntimeException re) {
    // Expected
    }
    meteredInputStream.reset();
    limiter = new CountBasedLimiter(5);
    throttled = new ThrottledInputStream(meteredInputStream, limiter, meteredInputStream);
    Assert.assertEquals(IOUtils.toString(throttled, Charsets.UTF_8), "abcde");
}
Also used : CountBasedLimiter(org.apache.gobblin.util.limiter.CountBasedLimiter) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Limiter(org.apache.gobblin.util.limiter.Limiter) CountBasedLimiter(org.apache.gobblin.util.limiter.CountBasedLimiter) Test(org.testng.annotations.Test)

Example 14 with Limiter

use of org.apache.gobblin.util.limiter.Limiter 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)

Example 15 with Limiter

use of org.apache.gobblin.util.limiter.Limiter in project incubator-gobblin by apache.

the class SharedLimiterFactoryTest method testEmptyConfig.

@Test
public void testEmptyConfig() throws Exception {
    SharedResourcesBrokerImpl<SimpleScopeType> broker = getBrokerForConfigMap(ImmutableMap.<String, String>of());
    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 NoopLimiter);
}
Also used : ResourceInstance(org.apache.gobblin.broker.ResourceInstance) NoopLimiter(org.apache.gobblin.util.limiter.NoopLimiter) 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

Limiter (org.apache.gobblin.util.limiter.Limiter)15 Test (org.testng.annotations.Test)10 CountBasedLimiter (org.apache.gobblin.util.limiter.CountBasedLimiter)7 MultiLimiter (org.apache.gobblin.util.limiter.MultiLimiter)6 NoopLimiter (org.apache.gobblin.util.limiter.NoopLimiter)6 ResourceInstance (org.apache.gobblin.broker.ResourceInstance)4 SimpleScopeType (org.apache.gobblin.broker.SimpleScopeType)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 Method (java.lang.reflect.Method)3 Properties (java.util.Properties)3 NotConfiguredException (org.apache.gobblin.broker.iface.NotConfiguredException)3 Extractor (org.apache.gobblin.source.extractor.Extractor)3 WorkUnit (org.apache.gobblin.source.workunit.WorkUnit)3 NotEnoughPermitsException (org.apache.gobblin.util.limiter.NotEnoughPermitsException)2 RateBasedLimiter (org.apache.gobblin.util.limiter.RateBasedLimiter)2 FileStatus (org.apache.hadoop.fs.FileStatus)2 FileSystem (org.apache.hadoop.fs.FileSystem)2 Path (org.apache.hadoop.fs.Path)2 Config (com.typesafe.config.Config)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1