Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ import java.time.Duration;
Schematic schematic = Schematic.builder()
.apiKey("YOUR_API_KEY")
.creditLeases(CreditLeaseConfig.builder()
.defaultReservationTtl(Duration.ofSeconds(60)) // just under an hour at most, which is as far out as the API will reserve credits
.defaultReservationTtl(Duration.ofSeconds(60)) // just under 24 hours at most, which is as far out as the API will reserve credits
.build())
.build();
```
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/schematic/api/Schematic.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private Schematic(Builder builder) {
Duration configuredTtl = creditLeases.getDefaultReservationTtl() != null
? creditLeases.getDefaultReservationTtl()
: CreditLeaseDefaults.RESERVATION_TTL;
// The API refuses a hold expiring more than an hour after its own clock, and this TTL
// The API refuses a hold expiring more than 24 hours after its own clock, and this TTL
// is applied to the caller's, so clamp a step below the cap to leave room for skew.
// Only server mode sends the value to the API: in client mode it sizes the local
// sweep, so clamping it there would shorten holds for no reason.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ public Builder defaultLeaseDuration(Duration defaultLeaseDuration) {
}

/**
* Reservation lifetime. Defaults to 60 seconds. In server mode it is capped at an hour
* less a minute of room for clock skew, since an hour out is the furthest the API will
* Reservation lifetime. Defaults to 60 seconds. In server mode it is capped at 24 hours
* less a minute of room for clock skew, since 24 hours out is the furthest the API will
* hold credits and it measures that against its own clock. Size it above the longest
* expected gap between a check and its settle: a settle arriving after the TTL still
* bills the server but no longer re-debits the local lease, so the local balance reads
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public final class CreditLeaseDefaults {
* The furthest out the API will hold credits, so a larger server-mode reservation TTL would
* fail every check.
*/
public static final Duration MAX_RESERVATION_TTL = Duration.ofHours(1);
public static final Duration MAX_RESERVATION_TTL = Duration.ofHours(24);

/**
* Held back from {@link #MAX_RESERVATION_TTL} because the API measures that hour against its
* Held back from {@link #MAX_RESERVATION_TTL} because the API measures that span against its
* own clock while the SDK computes {@code expiresAt} against the caller's: a client running
* ahead would otherwise be rejected at exactly the cap.
*/
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/com/schematic/api/TestSchematic.java
Original file line number Diff line number Diff line change
Expand Up @@ -510,18 +510,18 @@ void check_AutoModeFallsToServerGatingWhenTheDataStreamIsGone() throws Exception

@Test
void serverReservationTtl_IsClampedBelowTheApiCapButOnlyForServerMode() throws Exception {
Duration twoHours = Duration.ofHours(2);
Duration overCap = Duration.ofHours(25);
Duration clamped =
CreditLeaseDefaults.MAX_RESERVATION_TTL.minus(CreditLeaseDefaults.RESERVATION_TTL_SKEW_ALLOWANCE);

try (Schematic server = leasedClient(CreditLeaseMode.SERVER, twoHours);
Schematic client = leasedClient(CreditLeaseMode.CLIENT, twoHours)) {
try (Schematic server = leasedClient(CreditLeaseMode.SERVER, overCap);
Schematic client = leasedClient(CreditLeaseMode.CLIENT, overCap)) {
// The API refuses a hold expiring more than its cap ahead of its own clock, and this
// TTL is measured on ours, so the clamp leaves a step for the difference.
assertEquals(clamped, serverReservationTtl(server));
assertTrue(clamped.compareTo(CreditLeaseDefaults.MAX_RESERVATION_TTL) < 0);
// Client mode never sends it, so clamping there would shorten holds for nothing.
assertEquals(twoHours, serverReservationTtl(client));
assertEquals(overCap, serverReservationTtl(client));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void aTtlLongerThanTheApiWillHoldIsClampedForServerMode() {
.logger(logger)
.creditLeases(CreditLeaseConfig.builder()
.mode(CreditLeaseMode.SERVER)
.defaultReservationTtl(Duration.ofHours(2))
.defaultReservationTtl(Duration.ofHours(25))
.build())
.build()) {
verify(logger).warn(contains("longer than the API will hold"));
Expand Down
Loading