Skip to content

Commit b65738e

Browse files
committed
Add unit tests for TrafficRegulator (#2366)
1 parent a817984 commit b65738e

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

s3stream/src/test/java/com/automq/stream/s3/operator/TrafficRegulatorTest.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
*
44
* The use of this file is governed by the Business Source License,
55
* as detailed in the file "/LICENSE.S3Stream" included in this repository.
6+
*
67
* As of the Change Date specified in that file, in accordance with
78
* the Business Source License, use of this software will be governed
89
* by the Apache License, Version 2.0
910
*/
11+
1012
package com.automq.stream.s3.operator;
1113

1214
import com.google.common.collect.EvictingQueue;
@@ -18,7 +20,9 @@
1820
import java.lang.reflect.Field;
1921

2022
import static org.junit.jupiter.api.Assertions.assertTrue;
21-
import static org.mockito.Mockito.*;
23+
import static org.mockito.Mockito.mock;
24+
import static org.mockito.Mockito.verify;
25+
import static org.mockito.Mockito.when;
2226

2327
@Tag("S3Unit")
2428
class TrafficRegulatorTest {
@@ -184,8 +188,13 @@ void testRegulateFailureDoesNotRecordSuccess() {
184188
assertTrue(queue.isEmpty(), "Queue should be empty as failure occurred");
185189
}
186190

191+
@SuppressWarnings("unchecked")
187192
private EvictingQueue<Double> getSuccessRateQueue() {
188-
return (EvictingQueue<Double>) getField(regulator, "successRateQueue");
193+
Object field = getField(regulator, "successRateQueue");
194+
if (field instanceof EvictingQueue) {
195+
return (EvictingQueue<Double>) field;
196+
}
197+
throw new IllegalStateException("Field 'successRateQueue' is not of expected type EvictingQueue<Double>");
189198
}
190199

191200
/**

0 commit comments

Comments
 (0)