11import org .junit .jupiter .api .Disabled ;
2+ import org .junit .jupiter .api .DisplayName ;
23import org .junit .jupiter .api .Test ;
34import java .time .Duration ;
45import java .time .Instant ;
910class RateLimiterTest {
1011
1112 @ Test
13+ @ DisplayName ("Allows up to window limit" )
1214 void allowsUpToLimit () {
1315 TimeSource clock = new TimeSource (Instant .EPOCH );
1416 RateLimiter <String > limiter = new RateLimiter <>(3 , Duration .ofNanos (10_000L ), clock );
@@ -23,6 +25,7 @@ void allowsUpToLimit() {
2325
2426 @ Disabled ("Remove to run test" )
2527 @ Test
28+ @ DisplayName ("Denies requests just before boundary" )
2629 void denyCloseToBoundary () {
2730 TimeSource clock = new TimeSource (Instant .EPOCH );
2831 RateLimiter <String > limiter = new RateLimiter <>(2 , Duration .ofNanos (10_000L ), clock );
@@ -38,6 +41,7 @@ void denyCloseToBoundary() {
3841
3942 @ Disabled ("Remove to run test" )
4043 @ Test
44+ @ DisplayName ("Allows first request at exact boundary" )
4145 void allowsNewBoundary () {
4246 TimeSource clock = new TimeSource (Instant .EPOCH );
4347 RateLimiter <String > limiter = new RateLimiter <>(2 , Duration .ofNanos (10_000L ), clock );
@@ -53,6 +57,7 @@ void allowsNewBoundary() {
5357
5458 @ Disabled ("Remove to run test" )
5559 @ Test
60+ @ DisplayName ("Resets at boundary, then counts within window" )
5661 void continuesCountingWithinWindowAfterBoundaryReset () {
5762 TimeSource clock = new TimeSource (Instant .EPOCH );
5863 RateLimiter <String > limiter = new RateLimiter <>(2 , Duration .ofNanos (5_000L ), clock );
@@ -71,6 +76,7 @@ void continuesCountingWithinWindowAfterBoundaryReset() {
7176
7277 @ Disabled ("Remove to run test" )
7378 @ Test
79+ @ DisplayName ("Independent counters/windows per key" )
7480 void separateKeysHaveIndependentCountersAndWindows () {
7581 TimeSource clock = new TimeSource (Instant .EPOCH .plusNanos (42L ));
7682 RateLimiter <String > limiter = new RateLimiter <>(1 , Duration .ofNanos (100L ), clock );
@@ -89,6 +95,7 @@ void separateKeysHaveIndependentCountersAndWindows() {
8995
9096 @ Disabled ("Remove to run test" )
9197 @ Test
98+ @ DisplayName ("Long gaps reset window" )
9299 void longGapsResetWindow () {
93100 TimeSource clock = new TimeSource (Instant .EPOCH .plusNanos (1_000L ));
94101 RateLimiter <String > limiter = new RateLimiter <>(2 , Duration .ofNanos (50L ), clock );
@@ -107,6 +114,7 @@ void longGapsResetWindow() {
107114
108115 @ Disabled ("Remove to run test" )
109116 @ Test
117+ @ DisplayName ("Exact boundary starts a new window each time" )
110118 void exactBoundaryIsNewWindowEveryTime () {
111119 TimeSource clock = new TimeSource (Instant .EPOCH );
112120 RateLimiter <String > limiter = new RateLimiter <>(1 , Duration .ofNanos (10L ), clock );
@@ -125,6 +133,7 @@ void exactBoundaryIsNewWindowEveryTime() {
125133
126134 @ Disabled ("Remove to run test" )
127135 @ Test
136+ @ DisplayName ("Supports UUID keys with mixed time units" )
128137 void supportsUuidKeys () {
129138 TimeSource clock = new TimeSource (Instant .EPOCH );
130139 // Use a seconds-long window and advance in smaller units to mix Duration usage
@@ -148,6 +157,7 @@ void supportsUuidKeys() {
148157
149158 @ Disabled ("Remove to run test" )
150159 @ Test
160+ @ DisplayName ("Supports Integer keys" )
151161 void supportsIntegerKeys () {
152162 TimeSource clock = new TimeSource (Instant .EPOCH );
153163 RateLimiter <Integer > limiter = new RateLimiter <>(1 , Duration .ofNanos (100L ), clock );
@@ -165,6 +175,7 @@ void supportsIntegerKeys() {
165175
166176 @ Disabled ("Remove to run test" )
167177 @ Test
178+ @ DisplayName ("Supports Long keys" )
168179 void supportsLongKeys () {
169180 TimeSource clock = new TimeSource (Instant .EPOCH );
170181 RateLimiter <Long > limiter = new RateLimiter <>(2 , Duration .ofNanos (50L ), clock );
0 commit comments