@@ -75,15 +75,15 @@ public void decorateCheckedSupplier() throws Throwable {
75
75
CheckedFunction0 supplier = mock (CheckedFunction0 .class );
76
76
CheckedFunction0 decorated = RateLimiter .decorateCheckedSupplier (limit , supplier );
77
77
78
- when (limit .acquirePermission (config . getTimeoutDuration () ))
78
+ when (limit .acquirePermission ())
79
79
.thenReturn (false );
80
80
81
81
Try decoratedSupplierResult = Try .of (decorated );
82
82
then (decoratedSupplierResult .isFailure ()).isTrue ();
83
83
then (decoratedSupplierResult .getCause ()).isInstanceOf (RequestNotPermitted .class );
84
84
verify (supplier , never ()).apply ();
85
85
86
- when (limit .acquirePermission (config . getTimeoutDuration () ))
86
+ when (limit .acquirePermission ())
87
87
.thenReturn (true );
88
88
Try secondSupplierResult = Try .of (decorated );
89
89
then (secondSupplierResult .isSuccess ()).isTrue ();
@@ -95,15 +95,15 @@ public void decorateCheckedRunnable() throws Throwable {
95
95
CheckedRunnable runnable = mock (CheckedRunnable .class );
96
96
CheckedRunnable decorated = RateLimiter .decorateCheckedRunnable (limit , runnable );
97
97
98
- when (limit .acquirePermission (config . getTimeoutDuration () ))
98
+ when (limit .acquirePermission ())
99
99
.thenReturn (false );
100
100
101
101
Try decoratedRunnableResult = Try .run (decorated );
102
102
then (decoratedRunnableResult .isFailure ()).isTrue ();
103
103
then (decoratedRunnableResult .getCause ()).isInstanceOf (RequestNotPermitted .class );
104
104
verify (runnable , never ()).run ();
105
105
106
- when (limit .acquirePermission (config . getTimeoutDuration () ))
106
+ when (limit .acquirePermission ())
107
107
.thenReturn (true );
108
108
Try secondRunnableResult = Try .run (decorated );
109
109
then (secondRunnableResult .isSuccess ()).isTrue ();
@@ -115,15 +115,15 @@ public void decorateCheckedFunction() throws Throwable {
115
115
CheckedFunction1 <Integer , String > function = mock (CheckedFunction1 .class );
116
116
CheckedFunction1 <Integer , String > decorated = RateLimiter .decorateCheckedFunction (limit , function );
117
117
118
- when (limit .acquirePermission (config . getTimeoutDuration () ))
118
+ when (limit .acquirePermission ())
119
119
.thenReturn (false );
120
120
121
121
Try <String > decoratedFunctionResult = Try .success (1 ).mapTry (decorated );
122
122
then (decoratedFunctionResult .isFailure ()).isTrue ();
123
123
then (decoratedFunctionResult .getCause ()).isInstanceOf (RequestNotPermitted .class );
124
124
verify (function , never ()).apply (any ());
125
125
126
- when (limit .acquirePermission (config . getTimeoutDuration () ))
126
+ when (limit .acquirePermission ())
127
127
.thenReturn (true );
128
128
Try secondFunctionResult = Try .success (1 ).mapTry (decorated );
129
129
then (secondFunctionResult .isSuccess ()).isTrue ();
@@ -135,15 +135,15 @@ public void decorateSupplier() throws Exception {
135
135
Supplier supplier = mock (Supplier .class );
136
136
Supplier decorated = RateLimiter .decorateSupplier (limit , supplier );
137
137
138
- when (limit .acquirePermission (config . getTimeoutDuration () ))
138
+ when (limit .acquirePermission ())
139
139
.thenReturn (false );
140
140
141
141
Try decoratedSupplierResult = Try .success (decorated ).map (Supplier ::get );
142
142
then (decoratedSupplierResult .isFailure ()).isTrue ();
143
143
then (decoratedSupplierResult .getCause ()).isInstanceOf (RequestNotPermitted .class );
144
144
verify (supplier , never ()).get ();
145
145
146
- when (limit .acquirePermission (config . getTimeoutDuration () ))
146
+ when (limit .acquirePermission ())
147
147
.thenReturn (true );
148
148
Try secondSupplierResult = Try .success (decorated ).map (Supplier ::get );
149
149
then (secondSupplierResult .isSuccess ()).isTrue ();
@@ -155,15 +155,15 @@ public void decorateConsumer() throws Exception {
155
155
Consumer <Integer > consumer = mock (Consumer .class );
156
156
Consumer <Integer > decorated = RateLimiter .decorateConsumer (limit , consumer );
157
157
158
- when (limit .acquirePermission (config . getTimeoutDuration () ))
158
+ when (limit .acquirePermission ())
159
159
.thenReturn (false );
160
160
161
161
Try <Integer > decoratedConsumerResult = Try .success (1 ).andThen (decorated );
162
162
then (decoratedConsumerResult .isFailure ()).isTrue ();
163
163
then (decoratedConsumerResult .getCause ()).isInstanceOf (RequestNotPermitted .class );
164
164
verify (consumer , never ()).accept (any ());
165
165
166
- when (limit .acquirePermission (config . getTimeoutDuration () ))
166
+ when (limit .acquirePermission ())
167
167
.thenReturn (true );
168
168
Try secondConsumerResult = Try .success (1 ).andThen (decorated );
169
169
then (secondConsumerResult .isSuccess ()).isTrue ();
@@ -175,15 +175,15 @@ public void decorateRunnable() throws Exception {
175
175
Runnable runnable = mock (Runnable .class );
176
176
Runnable decorated = RateLimiter .decorateRunnable (limit , runnable );
177
177
178
- when (limit .acquirePermission (config . getTimeoutDuration () ))
178
+ when (limit .acquirePermission ())
179
179
.thenReturn (false );
180
180
181
181
Try decoratedRunnableResult = Try .success (decorated ).andThen (Runnable ::run );
182
182
then (decoratedRunnableResult .isFailure ()).isTrue ();
183
183
then (decoratedRunnableResult .getCause ()).isInstanceOf (RequestNotPermitted .class );
184
184
verify (runnable , never ()).run ();
185
185
186
- when (limit .acquirePermission (config . getTimeoutDuration () ))
186
+ when (limit .acquirePermission ())
187
187
.thenReturn (true );
188
188
Try secondRunnableResult = Try .success (decorated ).andThen (Runnable ::run );
189
189
then (secondRunnableResult .isSuccess ()).isTrue ();
@@ -195,15 +195,15 @@ public void decorateFunction() throws Exception {
195
195
Function <Integer , String > function = mock (Function .class );
196
196
Function <Integer , String > decorated = RateLimiter .decorateFunction (limit , function );
197
197
198
- when (limit .acquirePermission (config . getTimeoutDuration () ))
198
+ when (limit .acquirePermission ())
199
199
.thenReturn (false );
200
200
201
201
Try <String > decoratedFunctionResult = Try .success (1 ).map (decorated );
202
202
then (decoratedFunctionResult .isFailure ()).isTrue ();
203
203
then (decoratedFunctionResult .getCause ()).isInstanceOf (RequestNotPermitted .class );
204
204
verify (function , never ()).apply (any ());
205
205
206
- when (limit .acquirePermission (config . getTimeoutDuration () ))
206
+ when (limit .acquirePermission ())
207
207
.thenReturn (true );
208
208
Try secondFunctionResult = Try .success (1 ).map (decorated );
209
209
then (secondFunctionResult .isSuccess ()).isTrue ();
@@ -218,7 +218,7 @@ public void decorateCompletionStage() throws Exception {
218
218
219
219
Supplier <CompletionStage <String >> decorated = RateLimiter .decorateCompletionStage (limit , completionStage );
220
220
221
- when (limit .acquirePermission (config . getTimeoutDuration () ))
221
+ when (limit .acquirePermission ())
222
222
.thenReturn (false );
223
223
224
224
AtomicReference <Throwable > error = new AtomicReference <>(null );
@@ -232,7 +232,7 @@ public void decorateCompletionStage() throws Exception {
232
232
then (error .get ()).isExactlyInstanceOf (RequestNotPermitted .class );
233
233
verify (supplier , never ()).get ();
234
234
235
- when (limit .acquirePermission (config . getTimeoutDuration () ))
235
+ when (limit .acquirePermission ())
236
236
.thenReturn (true );
237
237
238
238
AtomicReference <Throwable > shouldBeEmpty = new AtomicReference <>(null );
@@ -248,25 +248,25 @@ public void decorateCompletionStage() throws Exception {
248
248
249
249
@ Test
250
250
public void waitForPermissionWithOne () throws Exception {
251
- when (limit .acquirePermission (config . getTimeoutDuration () ))
251
+ when (limit .acquirePermission ())
252
252
.thenReturn (true );
253
253
RateLimiter .waitForPermission (limit );
254
254
verify (limit , times (1 ))
255
- .acquirePermission (config . getTimeoutDuration () );
255
+ .acquirePermission ();
256
256
}
257
257
258
258
@ Test (expected = RequestNotPermitted .class )
259
259
public void waitForPermissionWithoutOne () throws Exception {
260
- when (limit .acquirePermission (config . getTimeoutDuration () ))
260
+ when (limit .acquirePermission ())
261
261
.thenReturn (false );
262
262
RateLimiter .waitForPermission (limit );
263
263
verify (limit , times (1 ))
264
- .acquirePermission (config . getTimeoutDuration () );
264
+ .acquirePermission ();
265
265
}
266
266
267
267
@ Test
268
268
public void waitForPermissionWithInterruption () throws Exception {
269
- when (limit .acquirePermission (config . getTimeoutDuration () ))
269
+ when (limit .acquirePermission ())
270
270
.then (invocation -> {
271
271
LockSupport .parkNanos (5_000_000_000L );
272
272
return null ;
0 commit comments