@@ -108,6 +108,11 @@ private void setupStubs(List<RateLimit> scenarios) throws Exception {
108108 githubApi .stubFor (get (urlEqualTo ("/meta" ))
109109 .willReturn (aResponse ().withStatus (200 ).withBody ("{\" verifiable_password_authentication\" : false}" )));
110110
111+ githubApi .stubFor (get (urlEqualTo ("/licenses/MIT" ))
112+ .willReturn (aResponse ()
113+ .withStatus (200 )
114+ .withBody ("{" + "\" key\" : \" mit\" ," + "\" name\" : \" MIT License\" }" )));
115+
111116 githubApi .stubFor (get (urlEqualTo ("/" ))
112117 .willReturn (aResponse ()
113118 .withStatus (200 )
@@ -174,15 +179,15 @@ public void NoCheckerConfigured() throws Exception {
174179 setupStubs (scenarios );
175180
176181 GitHubConfiguration .get ().setApiRateLimitChecker (ApiRateLimitChecker .ThrottleForNormalize );
177- github .getMeta ( );
182+ github .getLicense ( "MIT" );
178183 ApiRateLimitChecker .resetLocalChecker ();
179184
180185 GitHubConfiguration .get ().setApiRateLimitChecker (ApiRateLimitChecker .ThrottleOnOver );
181- github .getMeta ( );
186+ github .getLicense ( "MIT" );
182187 ApiRateLimitChecker .resetLocalChecker ();
183188
184189 GitHubConfiguration .get ().setApiRateLimitChecker (ApiRateLimitChecker .NoThrottle );
185- github .getMeta ( );
190+ github .getLicense ( "MIT" );
186191
187192 assertEquals (3 , countOfOutputLinesContaining ("LocalChecker for rate limit was not set for this thread." ));
188193 assertEquals (3 , countOfOutputLinesContaining ("with API URL 'https://api.github.com'" ));
@@ -249,7 +254,7 @@ public void ThrottleOnOverTestWithQuota() throws Exception {
249254 // Given a full rate limit quota, then we expect no throttling
250255 // Also only 1 call to get rate limit, since rate limit record is valid for a while
251256 for (int i = 0 ; i < 100 ; i ++) {
252- github .getMeta ( );
257+ github .getLicense ( "MIT" );
253258 }
254259
255260 assertEquals (0 , countOfOutputLinesContaining ("Sleeping" ));
@@ -277,7 +282,7 @@ public void ThrottleOnNormalizeTestWithQuota() throws Exception {
277282
278283 // Given a full rate limit quota, then we expect no throttling
279284 for (int i = 0 ; i < 100 ; i ++) {
280- github .getMeta ( );
285+ github .getLicense ( "MIT" );
281286 }
282287
283288 assertEquals (0 , countOfOutputLinesContaining ("Sleeping" ));
@@ -303,7 +308,7 @@ public void NoThrottleTestShouldNotThrottle() throws Exception {
303308 ApiRateLimitChecker .configureThreadLocalChecker (listener , github );
304309
305310 for (int i = 0 ; i < 100 ; i ++) {
306- github .getMeta ( );
311+ github .getLicense ( "MIT" );
307312 }
308313
309314 // there should be no output
@@ -331,6 +336,8 @@ public void NoThrottleTestShouldNotThrottle404() throws Exception {
331336
332337 ApiRateLimitChecker .configureThreadLocalChecker (listener , github );
333338
339+ // sanity cached to limit queries to once per second
340+ Thread .sleep (1001 );
334341 github .getMeta ();
335342
336343 // The core should be unknown, but different from initial
@@ -368,6 +375,8 @@ public void NoThrottleTestShouldFallbackToThrottleOnOverForGitHubDotCom() throws
368375
369376 ApiRateLimitChecker .configureThreadLocalChecker (listener , spy );
370377
378+ // sanity cached to limit queries to once per second
379+ Thread .sleep (1001 );
371380 spy .getMeta ();
372381
373382 assertEquals (1 , countOfOutputLinesContaining ("ThrottleOnOver will be used instead" ));
@@ -408,6 +417,8 @@ public void ThrottleOnOverTest() throws Exception {
408417 // does not happen until under buffer
409418 for (int i = 0 ; i < 11 ; i ++) {
410419 assertFalse (currentChecker .checkRateLimit (github .getRateLimit ().getCore (), 0 ));
420+ // sanity cached to limit queries to once per second
421+ Thread .sleep (1001 );
411422 }
412423
413424 // should be no output
@@ -418,10 +429,14 @@ public void ThrottleOnOverTest() throws Exception {
418429 // check rate limit to hit the next 9 scenarios
419430 for (int i = 0 ; i < 10 ; i ++) {
420431 assertTrue (currentChecker .checkRateLimit (github .getRateLimit ().getCore (), i ));
432+ // sanity cached to limit queries to once per second
433+ Thread .sleep (1001 );
421434 }
422435 // This simulates the waiting until refreshed
423436 currentChecker .resetExpiration ();
424437 assertFalse (currentChecker .checkRateLimit (github .getRateLimit ().getCore (), 10 ));
438+ // sanity cached to limit queries to once per second
439+ Thread .sleep (1001 );
425440
426441 // output for all the throttled scenarios. Sleeps normally on the first and then the `notify`
427442 // hits the next 9
@@ -492,6 +507,8 @@ public void ThrottleForNormalizeTestWithinIdeal() throws Exception {
492507
493508 // First check will not say under budget (add counts)
494509 github .getMeta ();
510+ // sanity cached to limit queries to once per second
511+ Thread .sleep (1001 );
495512
496513 assertEquals (4 , getRequestCount (githubApi ));
497514 // Feature removed, no output for under budget
@@ -503,13 +520,17 @@ public void ThrottleForNormalizeTestWithinIdeal() throws Exception {
503520 // check rate limit to hit the next 6 scenarios
504521 for (int i = 0 ; i < 6 ; i ++) {
505522 assertTrue (currentChecker .checkRateLimit (github .getRateLimit ().getCore (), i ));
523+ // sanity cached to limit queries to once per second
524+ Thread .sleep (1001 );
506525 }
507526
508527 assertEquals (initialRequestCount + 5 , handler .getView ().size ());
509528
510529 // This simulates the waiting until refreshed
511530 currentChecker .resetExpiration ();
512531 assertFalse (currentChecker .checkRateLimit (github .getRateLimit ().getCore (), 9 ));
532+ // sanity cached to limit queries to once per second
533+ Thread .sleep (1001 );
513534
514535 assertEquals (initialRequestCount + 9 , getRequestCount (githubApi ));
515536 // Functionality removed
@@ -557,11 +578,18 @@ public void NormalizeThrottleWithBurnedBuffer() throws Exception {
557578 ApiRateLimitChecker .LocalChecker currentChecker = ApiRateLimitChecker .getLocalChecker ();
558579
559580 assertTrue (currentChecker .checkRateLimit (github .getRateLimit ().getCore (), 0 ));
581+ // sanity cached to limit queries to once per second
582+ Thread .sleep (1001 );
560583 assertTrue (currentChecker .checkRateLimit (github .getRateLimit ().getCore (), 1 ));
584+ Thread .sleep (1001 );
561585 assertTrue (currentChecker .checkRateLimit (github .getRateLimit ().getCore (), 2 ));
586+ Thread .sleep (1001 );
562587 assertTrue (currentChecker .checkRateLimit (github .getRateLimit ().getCore (), 3 ));
588+ Thread .sleep (1001 );
563589 assertTrue (currentChecker .checkRateLimit (github .getRateLimit ().getCore (), 4 ));
590+ Thread .sleep (1001 );
564591 assertTrue (currentChecker .checkRateLimit (github .getRateLimit ().getCore (), 5 ));
592+ Thread .sleep (1001 );
565593
566594 // Expect a triggered throttle for normalize
567595 // GitHubRateLimitChecker add 1 second to notification loop, this hides the entropy value
@@ -618,6 +646,8 @@ public void OnOverThrottleTimingRateLimitCheck() throws Exception {
618646 github .getRateLimit ();
619647 // calls rateLimit() for first loop so we have to getRateLimit() for each loop
620648 github .getMeta ();
649+ // sanity cached to limit queries to once per second
650+ Thread .sleep (1001 );
621651 }
622652
623653 // (rate_limit + meta) x 6
@@ -631,10 +661,14 @@ public void OnOverThrottleTimingRateLimitCheck() throws Exception {
631661 // check rate limit to hit the next 5 scenarios
632662 for (int i = 0 ; i < 5 ; i ++) {
633663 assertTrue (currentChecker .checkRateLimit (github .getRateLimit ().getCore (), i ));
664+ // sanity cached to limit queries to once per second
665+ Thread .sleep (1001 );
634666 }
635667 // This simulates the waiting until refreshed
636668 currentChecker .resetExpiration ();
637669 assertFalse (currentChecker .checkRateLimit (github .getRateLimit ().getCore (), 5 ));
670+ // sanity cached to limit queries to once per second
671+ Thread .sleep (1001 );
638672
639673 assertEquals (initialRequestCount + 18 , getRequestCount (githubApi ));
640674
@@ -689,6 +723,8 @@ public void NormalizeThrottleTimingRateLimitCheck() throws Exception {
689723 ApiRateLimitChecker .configureThreadLocalChecker (listener , github );
690724
691725 github .getMeta ();
726+ // sanity cached to limit queries to once per second
727+ Thread .sleep (1001 );
692728
693729 // start timing
694730 long start = System .currentTimeMillis ();
@@ -697,11 +733,16 @@ public void NormalizeThrottleTimingRateLimitCheck() throws Exception {
697733 ApiRateLimitChecker .LocalChecker currentChecker = ApiRateLimitChecker .getLocalChecker ();
698734
699735 assertTrue (currentChecker .checkRateLimit (github .getRateLimit ().getCore (), 0 ));
736+ // sanity cached to limit queries to once per second
737+ Thread .sleep (1001 );
700738 assertTrue (currentChecker .checkRateLimit (github .getRateLimit ().getCore (), 1 ));
739+ Thread .sleep (1001 );
701740 assertTrue (currentChecker .checkRateLimit (github .getRateLimit ().getCore (), 2 ));
741+ Thread .sleep (1001 );
702742 // This simulates the waiting until refreshed
703743 currentChecker .resetExpiration ();
704744 assertFalse (currentChecker .checkRateLimit (github .getRateLimit ().getCore (), 3 ));
745+ Thread .sleep (1001 );
705746
706747 assertEquals (initialRequestCount + 6 , getRequestCount (githubApi ));
707748
@@ -777,6 +818,8 @@ public void NormalizeExpectedIdealOverTime() throws Exception {
777818 }
778819 // calls rateLimit() for first loop so we have to getRateLimit() for each loop
779820 github .getMeta ();
821+ // sanity cached to limit queries to once per second
822+ Thread .sleep (1001 );
780823 }
781824
782825 // rate_limit + meta x 12
@@ -829,6 +872,8 @@ public void OnOverExpectedIdealOverTime() throws Exception {
829872 }
830873 // calls rateLimit() for first loop so we have to getRateLimit() for each loop
831874 github .getMeta ();
875+ // sanity cached to limit queries to once per second
876+ Thread .sleep (1001 );
832877 }
833878
834879 assertEquals (12 , getRequestCount (githubApi ));
0 commit comments