Class AbuseLimitHandlerTest

java.lang.Object
org.kohsuke.github.AbstractGitHubWireMockTest
org.kohsuke.github.AbuseLimitHandlerTest

public class AbuseLimitHandlerTest extends AbstractGitHubWireMockTest
Test showing the behavior of OkHttpConnector with and without cache.

Key take aways:

  • These tests are artificial and intended to highlight the differences in behavior between scenarios. However, the differences they indicate are stark.
  • Caching reduces rate limit consumption by at least a factor of two in even the simplest case.
  • The OkHttp cache is pretty smart and will often connect read and write requests made on the same client and invalidate caches.
  • Changes made outside the current client cause the OkHttp cache to return stale data. This is expected and correct behavior.
  • "max-age=0" addresses the problem of external changes by revalidating caches for each request. This produces the same number of requests as OkHttp without caching, but those requests only count towards the GitHub rate limit if data has changes.
Author:
Liam Newman
  • Constructor Details

    • AbuseLimitHandlerTest

      public AbuseLimitHandlerTest()
      Instantiates a new abuse limit handler test.
  • Method Details

    • getWireMockOptions

      protected com.github.tomakehurst.wiremock.core.WireMockConfiguration getWireMockOptions()
      Gets the wire mock options.
      Overrides:
      getWireMockOptions in class AbstractGitHubWireMockTest
      Returns:
      the wire mock options
    • testHandler_Fail

      public void testHandler_Fail() throws Exception
      Test handler fail.
      Throws:
      Exception - the exception
    • testHandler_HttpStatus_Fail

      public void testHandler_HttpStatus_Fail() throws Exception
      Test handler http status fail.
      Throws:
      Exception - the exception
    • testHandler_Wait

      public void testHandler_Wait() throws Exception
      Test handler wait.
      Throws:
      Exception - the exception
    • testHandler_WaitStuck

      public void testHandler_WaitStuck() throws Exception
      Test handler wait stuck.
      Throws:
      Exception - the exception
    • testHandler_Wait_Secondary_Limits

      public void testHandler_Wait_Secondary_Limits() throws Exception
      Tests the behavior of the GitHub API client when the abuse limit handler is set to WAIT then the handler waits appropriately when secondary rate limits are encountered.
      Throws:
      Exception - if any error occurs during the test execution.
    • testHandler_Wait_Secondary_Limits_Too_Many_Requests

      public void testHandler_Wait_Secondary_Limits_Too_Many_Requests() throws Exception
      Tests the behavior of the GitHub API client when the abuse limit handler is set to WAIT then the handler waits appropriately when secondary rate limits are encountered.
      Throws:
      Exception - if any error occurs during the test execution.
    • testHandler_Wait_Secondary_Limits_Too_Many_Requests_Date_Retry_After

      public void testHandler_Wait_Secondary_Limits_Too_Many_Requests_Date_Retry_After() throws Exception
      Tests the behavior of the GitHub API client when the abuse limit handler with a date retry.
      Throws:
      Exception - if any error occurs during the test execution.
    • testHandler_Wait_Secondary_Limits_Too_Many_Requests_No_Retry_After

      public void testHandler_Wait_Secondary_Limits_Too_Many_Requests_No_Retry_After() throws Exception
      Tests the behavior of the GitHub API client when the abuse limit handler with a no retry after header.
      Throws:
      Exception - if any error occurs during the test execution.