File tree Expand file tree Collapse file tree 1 file changed +5
-3
lines changed
exercises/practice/rate-limiter/src/test/java Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -127,19 +127,21 @@ void exactBoundaryIsNewWindowEveryTime() {
127127 @ Test
128128 void supportsUuidKeys () {
129129 TimeSource clock = new TimeSource (Instant .EPOCH );
130- RateLimiter <UUID > limiter = new RateLimiter <>(1 , Duration .ofNanos (100L ), clock );
130+ // Use a seconds-long window and advance in smaller units to mix Duration usage
131+ RateLimiter <UUID > limiter = new RateLimiter <>(1 , Duration .ofSeconds (1L ), clock );
131132
132133 UUID a = UUID .fromString ("00000000-0000-0000-0000-000000000001" );
133134 UUID b = UUID .fromString ("00000000-0000-0000-0000-000000000002" );
134135
135136 assertThat (limiter .allow (a )).isTrue ();
136137 assertThat (limiter .allow (a )).isFalse ();
137138 // Advance slightly so the second client's window anchors later
138- clock .advance (Duration .ofNanos (1L ));
139+ clock .advance (Duration .ofMillis (1L ));
139140 assertThat (limiter .allow (b )).isTrue ();
140141 assertThat (limiter .allow (b )).isFalse ();
141142
142- clock .advance (Duration .ofNanos (100L ));
143+ // Advance exactly one second to hit the window boundary
144+ clock .advance (Duration .ofSeconds (1L ));
143145 assertThat (limiter .allow (a )).isTrue ();
144146 assertThat (limiter .allow (b )).isTrue ();
145147 }
You can’t perform that action at this time.
0 commit comments