amazon API requests : error 503 despite some delays

85 views Asked by At

I am using an amazon account to access to amazon book's database. My account is used only for this, and I don't sell anything with it. I can't access to the amazon API 5 times one after the other, in spite of a 2 seconds delay between each another : I get a 503 error.

here is my test code:

@Test
  public void testZERO_searchISBN_why503() throws Exception {

    //le livre recherché n' existe pas ou problème de communication avec Amazon
    setupSystemForTestsOfZERO_spyBookList();

    for (int i = 0; i < 5; i++) {
      execute(() -> statesManager.getState().searchISBN
              ("çè_ééàè\"à&à(à"));

      execute(() -> Thread.sleep(2000));
      execute(() -> statesManager.setZERO());
    }
    verify(bookList, times(5)).getBookByISBN("9782207301050");
  }

here are some explanations:

  • the parameter given to searchISBN() is the ISBN code, but the numbers are converted in their corresponding characters in the same key, for an azerty keyboard. anyway, this part works, there is no problem with that. consider it is a regular ISBN code ("978xxxxxxxxxx")
  • the execute() method comes from assertJ Swing test framework, this statement runs its lambda argument in the EDT. When running the test, I observe the 2 seconds delay, but I'm not sure this is the right statement for having the system to wait
  • the verify statement comes from mockito, it verifies the inner method destined to send the request to amazon is called 5 and only 5 times : no hidden calls that would justify the 503 error...

by the way, the 503 error, as I saw somewhere in SO, is sent by amazon in case of too fast requests, which not seems the case for my test.

thank you

0

There are 0 answers