Skip to content

Commit 23fd8c0

Browse files
committed
- Revert latch-based negative assertions back to Thread.sleep() in
constraint and integration tests, as testing for non-occurrence (await expecting false) still blocks for full timeout duration - Use chained assertion style for acknowledgment validations Signed-off-by: Soby Chacko <[email protected]>
1 parent 7b24247 commit 23fd8c0

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

spring-kafka/src/test/java/org/springframework/kafka/listener/ShareKafkaMessageListenerContainerConstraintTests.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ public void onShareRecord(ConsumerRecord<String, String> record,
122122
produceTestRecords(bootstrapServers, topic, 2);
123123

124124
// Wait and verify second batch is NOT processed yet
125-
// Using a latch that should NOT count down to verify blocking behavior
126-
assertThat(secondBatchLatch.await(3, TimeUnit.SECONDS)).isFalse();
125+
Thread.sleep(3000);
127126
assertThat(totalProcessed.get()).isEqualTo(3);
128127
assertThat(secondBatchLatch.getCount()).isEqualTo(2);
129128

@@ -199,8 +198,7 @@ public void onShareRecord(ConsumerRecord<String, String> record,
199198
produceTestRecords(bootstrapServers, topic, 1);
200199

201200
// Should not process new records while one is still pending
202-
// Using a latch that should NOT count down to verify blocking behavior
203-
assertThat(nextPollLatch.await(3, TimeUnit.SECONDS)).isFalse();
201+
Thread.sleep(3000);
204202
assertThat(totalProcessed.get()).isEqualTo(4);
205203

206204
// Acknowledge the last pending record

spring-kafka/src/test/java/org/springframework/kafka/listener/ShareKafkaMessageListenerContainerIntegrationTests.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,10 @@ public void onShareRecord(ConsumerRecord<String, String> record,
161161
try {
162162
assertThat(latch.await(30, TimeUnit.SECONDS)).isTrue();
163163
assertThat(received).hasSize(3);
164-
assertThat(acknowledgments).hasSize(3);
165-
assertThat(acknowledgments).allMatch(Objects::nonNull);
166-
assertThat(acknowledgments).allMatch(ShareKafkaMessageListenerContainerIntegrationTests::isAcknowledgedInternal);
167-
assertThat(acknowledgments).allMatch(ack -> getAcknowledgmentTypeInternal(ack) == AcknowledgeType.ACCEPT);
164+
assertThat(acknowledgments).hasSize(3)
165+
.allMatch(Objects::nonNull)
166+
.allMatch(ShareKafkaMessageListenerContainerIntegrationTests::isAcknowledgedInternal)
167+
.allMatch(ack -> AcknowledgeType.ACCEPT.equals(getAcknowledgmentTypeInternal(ack)));
168168
}
169169
finally {
170170
container.stop();
@@ -270,8 +270,7 @@ public void onShareRecord(ConsumerRecord<String, String> record,
270270
produceTestRecords(bootstrapServers, topic, 3);
271271

272272
// Verify second batch is NOT processed yet while acknowledgments are pending
273-
// Using a latch that should NOT count down to verify blocking behavior
274-
assertThat(secondBatchLatch.await(2, TimeUnit.SECONDS)).isFalse();
273+
Thread.sleep(2000);
275274
assertThat(processedCount.get()).isEqualTo(3);
276275

277276
// Acknowledge first batch

0 commit comments

Comments
 (0)