Skip to content

Commit 59c4ef2

Browse files
committed
Add more unit tests for auto-retry
1 parent ecfdba6 commit 59c4ef2

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/test/java/com/box/sdk/BoxAPIRequestTest.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,44 @@ public void requestRetriesTheDefaultNumberOfTimesWhenServerReturns500() throws M
3636
verify(BoxAPIConnection.DEFAULT_MAX_ATTEMPTS, getRequestedFor(urlEqualTo("/")));
3737
}
3838
}
39+
40+
@Test
41+
@Category(UnitTest.class)
42+
public void requestRetriesTheDefaultNumberOfTimesWhenServerReturns429() throws MalformedURLException {
43+
stubFor(get(urlEqualTo("/")).willReturn(aResponse().withStatus(429)));
44+
Time mockTime = mock(Time.class);
45+
BackoffCounter backoffCounter = new BackoffCounter(mockTime);
46+
47+
URL url = new URL("http://localhost:8080/");
48+
BoxAPIRequest request = new BoxAPIRequest(url, "GET");
49+
request.setBackoffCounter(backoffCounter);
50+
51+
try {
52+
request.send();
53+
} catch (BoxAPIException e) {
54+
verify(BoxAPIConnection.DEFAULT_MAX_ATTEMPTS, getRequestedFor(urlEqualTo("/")));
55+
}
56+
}
57+
58+
@Test
59+
@Category(UnitTest.class)
60+
public void requestRetriesTheNumberOfTimesConfiguredInTheAPIConnection() throws MalformedURLException {
61+
final int expectedNumAttempts = 1;
62+
stubFor(get(urlEqualTo("/")).willReturn(aResponse().withStatus(500)));
63+
Time mockTime = mock(Time.class);
64+
BackoffCounter backoffCounter = new BackoffCounter(mockTime);
65+
66+
BoxAPIConnection api = new BoxAPIConnection("");
67+
api.setMaxAttempts(expectedNumAttempts);
68+
69+
URL url = new URL("http://localhost:8080/");
70+
BoxAPIRequest request = new BoxAPIRequest(api, url, "GET");
71+
request.setBackoffCounter(backoffCounter);
72+
73+
try {
74+
request.send();
75+
} catch (BoxAPIException e) {
76+
verify(expectedNumAttempts, getRequestedFor(urlEqualTo("/")));
77+
}
78+
}
3979
}

0 commit comments

Comments
 (0)