?????????????????????????????????????
????"throw exception once reached the limit [naive??flaky]" in new ctx {
????for (i <- 1 to maxCount) {
????Future {
????throttler(waitForever())
????}
????}
????throttler {} must throwA[ThrottledException]
????????????? maxCount ?????????? Future{}???????? waitForever ???????ú????????????????????????????????????????????????? —— maxCount + 1????????????????????? ThrottledException ????????????????????????????????????????????????????? future ???????У?future ???????????????????????????
????????????????????????????????????????????????????????????Υ???????????????????е????????????????? waitForever ?????б????????????????????????????Щ???????????? future ?????????????????????????????????????????????? sleep ????????Щ????????
????"throw exception once reached the limit [naive?? bad]" in new ctx {
????for (i <- 1 to maxCount) {
????Future {
????throttler(waitForever())
????}
????}
????Thread.sleep(1000)
????throttler {} must throwA[ThrottledException]
????}
??????????????????????????????????????????????????????????????????
?????????????????????????????ú??”????????”????á?
??????????????????£??????????????????????????????????????
?????????????е??????????????? Google ????????
?????????????????????????(future)????????????????????????????????????? java.util.concurrent ????? CountDownLatch ??
????"throw exception once reached the limit [working]" in new ctx {
????val barrier = new CountDownLatch(maxCount)
????for (i <- 1 to maxCount) {
????Future {
????throttler {
????barrier.countDown()
????waitForever()
????}
????}
????}
????barrier.await(5?? TimeUnit.SECONDS) must beTrue
????throttler {} must throwA[ThrottledException]
????}
??????????? CountDownLatch ??????????????????????????????????????????????? 0?????????????????У????????Щ?????????? future???????? future ??????? countDown ?????????????? 1???????????? 0?????е? future ????????е? waitForever ?????????
?????????????????????? throttler ???????????д???????maxCount??????????????????????? throttler ????????????????????????????????????????????????????????? throttler??????????????????????????? 0 ???? CountDownLatch ???????????
????????Щ???????????鷢??????????ó?????????????????????????????????????鷢????????????????????????????????????????????????????????????????????????
????????
???????????????????????????????????????????????????????????????κ??????????????????????????????????????????? Thread.sleep ???????????????????????????????????
??????????????£????????????б????????????????????????? CountDownLatch ???? Thead.sleep????? CountDownlatch ????????????????????????????????????????????????????????????????????????????????????????????????????? waiting ?????????? waitForever ?????????????????? Thread.sleep(Long.MAX_VALUE) ?????????????????????????????ò??????????