@@ -51,6 +51,7 @@ public class SuperStreamProducerTest {
51
51
int partitions = 3 ;
52
52
String superStream ;
53
53
String [] routingKeys = null ;
54
+ TestUtils .ClientFactory cf ;
54
55
55
56
@ BeforeEach
56
57
void init (TestInfo info ) throws Exception {
@@ -173,4 +174,68 @@ void allMessagesSentToSuperStreamWithRoutingKeyRoutingShouldBeThenConsumed() thr
173
174
assertThat (counts .values ().stream ().map (AtomicLong ::get ).reduce (0L , Long ::sum ))
174
175
.isEqualTo (messageCount );
175
176
}
177
+
178
+ @ Test
179
+ void getLastPublishingIdShouldReturnLowestValue () throws Exception {
180
+ int messageCount = 10_000 ;
181
+ declareSuperStreamTopology (connection , superStream , partitions );
182
+ String producerName = "super-stream-application" ;
183
+ Producer producer =
184
+ environment .producerBuilder ().name (producerName ).stream (superStream )
185
+ .routing (message -> message .getProperties ().getMessageIdAsString (), RoutingType .HASH )
186
+ .build ();
187
+
188
+ CountDownLatch publishLatch = new CountDownLatch (messageCount );
189
+ IntStream .range (0 , messageCount )
190
+ .forEach (
191
+ i ->
192
+ producer .send (
193
+ producer
194
+ .messageBuilder ()
195
+ .publishingId (i )
196
+ .properties ()
197
+ .messageId (UUID .randomUUID ().toString ())
198
+ .messageBuilder ()
199
+ .build (),
200
+ confirmationStatus -> publishLatch .countDown ()));
201
+
202
+ assertThat (latchAssert (publishLatch )).completes (5 );
203
+
204
+ long lastPublishingId = producer .getLastPublishingId ();
205
+ assertThat (lastPublishingId ).isNotZero ();
206
+ Client client = cf .get ();
207
+ IntStream .range (0 , partitions )
208
+ .mapToObj (i -> superStream + "-" + i )
209
+ .forEach (
210
+ stream -> {
211
+ long publishingId = client .queryPublisherSequence (producerName , stream );
212
+ assertThat (publishingId ).isGreaterThanOrEqualTo (lastPublishingId );
213
+ });
214
+
215
+ Map <String , AtomicLong > counts = new ConcurrentHashMap <>();
216
+ AtomicLong totalCount = new AtomicLong (0 );
217
+ IntStream .range (0 , partitions )
218
+ .mapToObj (i -> superStream + "-" + i )
219
+ .forEach (
220
+ stream -> {
221
+ AtomicLong streamCount = new AtomicLong (0 );
222
+ counts .put (stream , streamCount );
223
+ environment .consumerBuilder ().stream (stream )
224
+ .offset (OffsetSpecification .first ())
225
+ .messageHandler (
226
+ (context , message ) -> {
227
+ streamCount .incrementAndGet ();
228
+ totalCount .incrementAndGet ();
229
+ })
230
+ .build ();
231
+ });
232
+
233
+ waitAtMost (10 , () -> totalCount .get () == messageCount );
234
+
235
+ assertThat (counts .values ().stream ().map (AtomicLong ::get ))
236
+ .hasSize (partitions )
237
+ .doesNotContain (0L );
238
+ assertThat (counts .values ().stream ().map (AtomicLong ::get ).reduce (0L , Long ::sum ))
239
+ .isEqualTo (messageCount );
240
+ }
176
241
}
0 commit comments