17
17
import static com .rabbitmq .stream .impl .TestUtils .b ;
18
18
import static com .rabbitmq .stream .impl .TestUtils .declareSuperStreamTopology ;
19
19
import static com .rabbitmq .stream .impl .TestUtils .deleteSuperStreamTopology ;
20
- import static com .rabbitmq .stream .impl .TestUtils .latchAssert ;
21
20
import static com .rabbitmq .stream .impl .TestUtils .streamName ;
22
21
import static com .rabbitmq .stream .impl .TestUtils .waitAtMost ;
23
22
import static org .assertj .core .api .Assertions .assertThat ;
32
31
import java .util .List ;
33
32
import java .util .Map ;
34
33
import java .util .concurrent .ConcurrentHashMap ;
35
- import java .util .concurrent .CountDownLatch ;
36
34
import java .util .concurrent .atomic .AtomicInteger ;
37
35
import java .util .concurrent .atomic .AtomicLong ;
38
36
import java .util .concurrent .atomic .AtomicReference ;
@@ -70,7 +68,6 @@ void secondSubscriptionShouldTakeOverAfterFirstOneUnsubscribes() throws Exceptio
70
68
AtomicLong lastReceivedOffset = new AtomicLong (0 );
71
69
Map <Byte , Boolean > consumerStates = consumerStates (2 );
72
70
Map <Byte , AtomicInteger > receivedMessages = receivedMessages (2 );
73
- CountDownLatch consumerUpdateLatch = new CountDownLatch (2 );
74
71
String consumerName = "foo" ;
75
72
ClientParameters clientParameters =
76
73
new ClientParameters ()
@@ -85,7 +82,6 @@ void secondSubscriptionShouldTakeOverAfterFirstOneUnsubscribes() throws Exceptio
85
82
.consumerUpdateListener (
86
83
(client , subscriptionId , active ) -> {
87
84
consumerStates .put (subscriptionId , active );
88
- consumerUpdateLatch .countDown ();
89
85
long storedOffset = writerClient .queryOffset (consumerName , stream ).getOffset ();
90
86
if (storedOffset == 0 ) {
91
87
return OffsetSpecification .first ();
@@ -104,7 +100,7 @@ void secondSubscriptionShouldTakeOverAfterFirstOneUnsubscribes() throws Exceptio
104
100
assertThat (response .isOk ()).isTrue ();
105
101
response = client .subscribe (b (1 ), stream , OffsetSpecification .first (), 2 , parameters );
106
102
assertThat (response .isOk ()).isTrue ();
107
- latchAssert ( consumerUpdateLatch ). completes ( );
103
+ waitAtMost (() -> consumerStates . get ( b ( 0 )) );
108
104
assertThat (consumerStates )
109
105
.hasSize (2 )
110
106
.containsEntry (b (0 ), Boolean .TRUE )
@@ -135,7 +131,7 @@ void secondSubscriptionShouldTakeOverAfterFirstOneUnsubscribes() throws Exceptio
135
131
}
136
132
137
133
@ Test
138
- void consumerUpdateListenerShouldBeCalledInOrder () throws Exception {
134
+ void consumerUpdateListenerShouldBeCalledOnlyWhenConsumerGetsActivated () throws Exception {
139
135
StringBuffer consumerUpdateHistory = new StringBuffer ();
140
136
Client client =
141
137
cf .get (
@@ -158,11 +154,6 @@ void consumerUpdateListenerShouldBeCalledInOrder() throws Exception {
158
154
response =
159
155
client .subscribe (subscriptionId , stream , OffsetSpecification .first (), 2 , parameters );
160
156
assertThat (response .isOk ()).isTrue ();
161
- waitAtMost (
162
- () ->
163
- consumerUpdateHistory
164
- .toString ()
165
- .contains (String .format ("<%d.%b>" , subscriptionId , false )));
166
157
}
167
158
168
159
for (int i = 0 ; i < 9 ; i ++) {
@@ -198,10 +189,10 @@ void noConsumerUpdateOnConnectionClosingIfSubscriptionNotUnsubscribed() throws E
198
189
assertThat (response .isOk ()).isTrue ();
199
190
response = client .subscribe (b (1 ), stream , OffsetSpecification .first (), 2 , parameters );
200
191
assertThat (response .isOk ()).isTrue ();
201
- waitAtMost (() -> consumerUpdateCount .get () == 2 );
192
+ waitAtMost (() -> consumerUpdateCount .get () == 1 );
202
193
203
194
client .close ();
204
- assertThat (consumerUpdateCount ).hasValue (2 );
195
+ assertThat (consumerUpdateCount ).hasValue (1 );
205
196
}
206
197
207
198
@ Test
@@ -301,7 +292,7 @@ void singleActiveConsumerShouldRolloverWhenAnotherJoinsPartition(TestInfo info)
301
292
response = client .unsubscribe (b (1 ));
302
293
assertThat (response .isOk ()).isTrue ();
303
294
waitAtMost (() -> consumerStates .get (b (0 )) == true );
304
- assertThat (consumerStates ).containsEntry (b (0 ), true ); // should not change when unsubscribing
295
+ assertThat (consumerStates ).containsEntry (b (1 ), true ); // should not change when unsubscribing
305
296
306
297
response = client .unsubscribe (b (0 ));
307
298
assertThat (response .isOk ()).isTrue ();
0 commit comments