19
19
import static com .rabbitmq .stream .oauth2 .TokenCredentialsManager .DEFAULT_REFRESH_DELAY_STRATEGY ;
20
20
import static java .time .Duration .ofMillis ;
21
21
import static java .time .Duration .ofSeconds ;
22
+ import static java .util .concurrent .TimeUnit .MILLISECONDS ;
22
23
import static java .util .stream .Collectors .toList ;
23
24
import static java .util .stream .IntStream .range ;
24
25
import static org .assertj .core .api .Assertions .assertThat ;
25
26
import static org .mockito .Mockito .when ;
26
27
28
+ import com .rabbitmq .stream .oauth2 .CredentialsManager .Registration ;
29
+ import com .rabbitmq .stream .oauth2 .OAuth2TestUtils .Pair ;
27
30
import java .time .Duration ;
28
31
import java .time .Instant ;
29
32
import java .util .List ;
30
33
import java .util .concurrent .CountDownLatch ;
31
34
import java .util .concurrent .Executors ;
32
35
import java .util .concurrent .ScheduledExecutorService ;
33
- import java .util .concurrent .TimeUnit ;
34
36
import java .util .concurrent .atomic .AtomicInteger ;
35
37
import java .util .function .Function ;
36
38
import org .junit .jupiter .api .AfterEach ;
@@ -72,22 +74,17 @@ void refreshShouldStopOnceUnregistered() throws InterruptedException {
72
74
this .requester , this .scheduledExecutorService , DEFAULT_REFRESH_DELAY_STRATEGY );
73
75
int expectedRefreshCount = 3 ;
74
76
AtomicInteger refreshCount = new AtomicInteger ();
75
- CountDownLatch refreshSync = new CountDownLatch (expectedRefreshCount );
76
- CredentialsManager . Registration registration =
77
+ CountDownLatch refreshLatch = new CountDownLatch (expectedRefreshCount );
78
+ Registration registration =
77
79
credentials .register (
78
80
"" ,
79
81
(u , p ) -> {
80
82
refreshCount .incrementAndGet ();
81
- refreshSync .countDown ();
83
+ refreshLatch .countDown ();
82
84
});
83
85
registration .connect (connectionCallback (() -> {}));
84
86
assertThat (requestCount ).hasValue (1 );
85
- try {
86
- assertThat (refreshSync .await (ofSeconds (10 ).toMillis (), TimeUnit .MILLISECONDS )).isTrue ();
87
- } catch (InterruptedException e ) {
88
- Thread .currentThread ().interrupt ();
89
- throw new RuntimeException (e );
90
- }
87
+ assertThat (refreshLatch .await (ofSeconds (10 ).toMillis (), MILLISECONDS )).isTrue ();
91
88
assertThat (requestCount ).hasValue (expectedRefreshCount + 1 );
92
89
registration .close ();
93
90
assertThat (refreshCount ).hasValue (expectedRefreshCount );
@@ -110,12 +107,12 @@ void severalRegistrationsShouldBeRefreshed() throws Exception {
110
107
int expectedRefreshCountPerConnection = 3 ;
111
108
int connectionCount = 10 ;
112
109
AtomicInteger totalRefreshCount = new AtomicInteger ();
113
- List <OAuth2TestUtils . Pair <CredentialsManager . Registration , CountDownLatch >> registrations =
110
+ List <Pair <Registration , CountDownLatch >> registrations =
114
111
range (0 , connectionCount )
115
112
.mapToObj (
116
113
ignored -> {
117
114
CountDownLatch sync = new CountDownLatch (expectedRefreshCountPerConnection );
118
- CredentialsManager . Registration r =
115
+ Registration r =
119
116
credentials .register (
120
117
"" ,
121
118
(username , password ) -> {
@@ -127,15 +124,8 @@ void severalRegistrationsShouldBeRefreshed() throws Exception {
127
124
.collect (toList ());
128
125
129
126
registrations .forEach (r -> r .v1 ().connect (connectionCallback (() -> {})));
130
- for (OAuth2TestUtils .Pair <CredentialsManager .Registration , CountDownLatch > registrationPair :
131
- registrations ) {
132
- try {
133
- assertThat (registrationPair .v2 ().await (ofSeconds (10 ).toMillis (), TimeUnit .MILLISECONDS ))
134
- .isTrue ();
135
- } catch (InterruptedException e ) {
136
- Thread .currentThread ().interrupt ();
137
- throw new RuntimeException (e );
138
- }
127
+ for (Pair <Registration , CountDownLatch > registrationPair : registrations ) {
128
+ assertThat (registrationPair .v2 ().await (ofSeconds (10 ).toMillis (), MILLISECONDS )).isTrue ();
139
129
}
140
130
// all connections have been refreshed once
141
131
int refreshCountSnapshot = totalRefreshCount .get ();
0 commit comments