@Test public void testPaceController_timeout() throws InterruptedException { final RateLimiterController paceController = new RateLimiterController(500, 10d); final Node node = mock(Node.class); final AtomicInteger passcount = new AtomicInteger(); final AtomicInteger blockcount = new AtomicInteger(); final CountDownLatch countDown = new CountDownLatch(1); final AtomicInteger done = new AtomicInteger(); for (int i = 0; i < 10; i++) { Thread thread = new Thread(new Runnable() { @Override public void run() { boolean pass = paceController.canPass(node, 1); if (pass == true) { passcount.incrementAndGet(); } else { blockcount.incrementAndGet(); } done.incrementAndGet(); if (done.get() >= 10) { countDown.countDown(); } } }, "Thread " + i); thread.start(); } countDown.await(); System.out.println("pass:" + passcount.get()); System.out.println("block" + blockcount.get()); System.out.println("done" + done.get()); assertTrue(blockcount.get() > 0); }
@Override public boolean canPass(Node node, int acquireCount) { return canPass(node, acquireCount, false); }
RateLimiterController implements TrafficShapingController { @Override public boolean canPass(Node node, int acquireCount) { return canPass(node, acquireCount, false); } }
RateLimiterController implements TrafficShapingController { @Override public boolean canPass(Node node, int acquireCount) { return canPass(node, acquireCount, false); } RateLimiterController(int timeOut, double count); }
RateLimiterController implements TrafficShapingController { @Override public boolean canPass(Node node, int acquireCount) { return canPass(node, acquireCount, false); } RateLimiterController(int timeOut, double count); @Override boolean canPass(Node node, int acquireCount); @Override boolean canPass(Node node, int acquireCount, boolean prioritized); }
RateLimiterController implements TrafficShapingController { @Override public boolean canPass(Node node, int acquireCount) { return canPass(node, acquireCount, false); } RateLimiterController(int timeOut, double count); @Override boolean canPass(Node node, int acquireCount); @Override boolean canPass(Node node, int acquireCount, boolean prioritized);  }