Skip to content

Commit

Permalink
HTTPCORE-754: Correct formatting of infinite deadline
Browse files Browse the repository at this point in the history
  • Loading branch information
ok2c committed Sep 15, 2023
1 parent a56b383 commit 4695f25
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
12 changes: 10 additions & 2 deletions httpcore5/src/main/java/org/apache/hc/core5/util/Deadline.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,11 @@ public int hashCode() {
* @return a formatted string.
*/
public String format(final TimeUnit overdueTimeUnit) {
return String.format("Deadline: %s, %s overdue", formatTarget(), TimeValue.of(remaining(), overdueTimeUnit));
if (value == MAX_VALUE.value) {
return "No deadline (infinite)";
} else {
return String.format("Deadline: %s, %s overdue", formatTarget(), TimeValue.of(remaining(), overdueTimeUnit));
}
}

/**
Expand All @@ -190,7 +194,11 @@ public String format(final TimeUnit overdueTimeUnit) {
* @return a formatted string in the format {@value #DATE_FORMAT}.
*/
public String formatTarget() {
return DATE_TIME_FORMATTER.format(Instant.ofEpochMilli(value).atOffset(ZoneOffset.UTC));
if (value == MAX_VALUE.value) {
return "(infinite)";
} else {
return DATE_TIME_FORMATTER.format(Instant.ofEpochMilli(value).atOffset(ZoneOffset.UTC));
}
}

public Deadline freeze() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,11 @@ public void testMessage() {
DeadlineTimeoutException.from(deadline).getMessage());
}

@Test
public void testInfiniteDeadlineMessage() {
final Deadline deadline = Deadline.calculate(Timeout.ZERO_MILLISECONDS);
Assertions.assertEquals("No deadline (infinite)",
DeadlineTimeoutException.from(deadline).getMessage());
}

}

0 comments on commit 4695f25

Please sign in to comment.