@Override public void stop() { for (Limiter limiter : this.underlyingLimiters) { limiter.stop(); } } }
@Override public void close() throws IOException { try { this.extractor.close(); } finally { this.limiter.stop(); } } }
@Override public void stop() { this.underlying.stop(); if (this.underlying instanceof RestliServiceBasedLimiter) { RestliServiceBasedLimiter restliLimiter = (RestliServiceBasedLimiter) this.underlying; RateComputingLimiterContainer.this.unusedPermitsCounts.add(restliLimiter.getUnusedPermits()); log.info("Unused permits: " + restliLimiter.getUnusedPermits()); } RateComputingLimiterContainer.this.subLimiterPermitCounts.remove(this.localPermitCount); } }
@AfterClass public void tearDown() { this.limiter.stop(); } }
@AfterClass public void tearDown() { this.limiter.stop(); } }
@Override public void close() throws IOException { getRateLimiter().stop(); super.close(); }
@Override protected void map(Text key, NullWritable value, Context context) throws IOException, InterruptedException { try { Configuration configuration = context.getConfiguration(); Stressor stressor = context.getConfiguration().getClass(StressTestUtils.STRESSOR_CLASS, StressTestUtils.DEFAULT_STRESSOR_CLASS, Stressor.class).newInstance(); stressor.configure(context.getConfiguration()); RateComputingLimiterContainer limiterContainer = new RateComputingLimiterContainer(); Limiter limiter = limiterContainer.decorateLimiter(createLimiter(configuration, this.broker)); ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); ScheduledFuture<?> future = executor.scheduleAtFixedRate(new Recorder(limiterContainer, context, true), 0, 15, TimeUnit.SECONDS); limiter.start(); stressor.run(limiter); limiter.stop(); future.cancel(false); ExecutorsUtils.shutdownExecutorService(executor, Optional.<Logger>absent(), 10, TimeUnit.SECONDS); } catch (ReflectiveOperationException roe) { throw new IOException(roe); } } }
@Override public void run() { try { this.limiter.start(); this.stressor.run(this.limiter); this.limiter.stop(); } catch (InterruptedException ie) { log.error("Error: ", ie); } } }
@Test public void testThrottling() throws InterruptedException { Limiter limiter = new CountBasedLimiter(10); limiter.start(); for (int i = 0; i < 10; i++) { Assert.assertTrue(limiter.acquirePermits(1) != null); } Assert.assertTrue(limiter.acquirePermits(1) == null); limiter.stop(); } }
@Override public void stop() { for (Limiter limiter : this.underlyingLimiters) { limiter.stop(); } } }
@Override public void close() throws IOException { try { this.extractor.close(); } finally { this.limiter.stop(); } } }
@Override public void close() throws IOException { getRateLimiter().stop(); super.close(); }