@@ -93,16 +93,21 @@ public void testThrottleConsume3() {
93
93
94
94
@ Test
95
95
public void testThrottleConsume4 () {
96
- AsyncNetworkBandwidthLimiter bucket = new AsyncNetworkBandwidthLimiter (AsyncNetworkBandwidthLimiter .Type .INBOUND , 100 , 1000 );
96
+ AsyncNetworkBandwidthLimiter bucket = new AsyncNetworkBandwidthLimiter (
97
+ AsyncNetworkBandwidthLimiter .Type .INBOUND , 100 , 1000 );
97
98
bucket .consume (ThrottleStrategy .BYPASS , 1000 );
98
99
Assertions .assertEquals (-100 , bucket .getAvailableTokens ());
99
- CompletableFuture <Void > cf = bucket .consume (ThrottleStrategy .CATCH_UP , 5 );
100
- bucket .consume (ThrottleStrategy .CATCH_UP , 10 );
101
- CompletableFuture <Void > result = cf .whenComplete ((v , e ) -> {
102
- Assertions .assertNull (e );
103
- Assertions .assertEquals (95 , bucket .getAvailableTokens ());
100
+ CompletableFuture <Boolean > firstCompleted = new CompletableFuture <>();
101
+ CompletableFuture <Void > cf1 = bucket .consume (ThrottleStrategy .CATCH_UP , 5 );
102
+ cf1 = cf1 .thenApply (v -> {
103
+ firstCompleted .complete (true );
104
+ return null ;
105
+ });
106
+ CompletableFuture <Void > cf2 = bucket .consume (ThrottleStrategy .CATCH_UP , 10 );
107
+ CompletableFuture <Void > result = cf2 .thenAccept (v -> {
108
+ Assertions .assertTrue (firstCompleted .isDone (),
109
+ "First request should complete before second request" );
104
110
});
105
- cf .join ();
106
111
result .join ();
107
112
}
108
113
0 commit comments