Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
yildizsc committed Dec 14, 2023
1 parent d97460a commit b2e70e3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
18 changes: 9 additions & 9 deletions src/main/java/com/webex/events/RateLimiter.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ public class RateLimiter {
private int secondBasedCostThreshold = 0;
private int usedDailyBasedCost = 0;
private int dailyBasedCostThreshold = 0;
private int dailyRetryAfter = 0;
private int secondlyRetryAfter = 0;
private int dailyRetryAfterInSecond = 0;
private int secondlyRetryAfterInMs = 0;
private HttpHeaders headers;

RateLimiter(Response response) {
this.headers = response.headers();
// Todo: remove this line after mock response headers on test level.
// Todo: remove this line after mocking response headers on test level.
if (headers == null) {
return;
}
Expand All @@ -39,12 +39,12 @@ public class RateLimiter {

String dailyRetryAfter = getHeaderValue(DAILY_RETRY_AFTER);
if (!dailyRetryAfter.isEmpty()) {
this.dailyRetryAfter = Integer.parseInt(dailyRetryAfter);
this.dailyRetryAfterInSecond = Integer.parseInt(dailyRetryAfter);
}

String secondlyRetryAfter = getHeaderValue(SECONDLY_RETRY_AFTER);
if (!secondlyRetryAfter.isEmpty()) {
this.secondlyRetryAfter = Integer.parseInt(secondlyRetryAfter);
this.secondlyRetryAfterInMs = Integer.parseInt(secondlyRetryAfter);
}
}

Expand All @@ -64,12 +64,12 @@ int getDailyBasedCostThreshold() {
return this.dailyBasedCostThreshold;
}

int getDailyRetryAfter() {
return this.dailyRetryAfter;
int getDailyRetryAfterInSecond() {
return this.dailyRetryAfterInSecond;
}

int getSecondlyRetryAfter() {
return this.secondlyRetryAfter;
int getSecondlyRetryAfterInMs() {
return this.secondlyRetryAfterInMs;
}

private String getHeaderValue(String header) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void testDailyRetryAfter() {
when(response.headers()).thenReturn(HttpHeaders.of(headersMap, (k, v) -> true));
rateLimiter = new RateLimiter(response);

assertEquals(rateLimiter.getDailyRetryAfter(), 3);
assertEquals(rateLimiter.getDailyRetryAfterInSecond(), 3);
}

@Test
Expand All @@ -71,6 +71,6 @@ void testSecondlyRetryAfter() {
when(response.headers()).thenReturn(HttpHeaders.of(headersMap, (k, v) -> true));
rateLimiter = new RateLimiter(response);

assertEquals(rateLimiter.getSecondlyRetryAfter(), 30);
assertEquals(rateLimiter.getSecondlyRetryAfterInMs(), 30);
}
}

0 comments on commit b2e70e3

Please sign in to comment.