-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[fix][test] Fix flaky test RawReaderTest #21008
Changes from 7 commits
9d65a87
13fafe1
84beb1f
6b2d1b9
75ece25
d31bed6
33681e6
b64ee22
71403af
06f9c56
28ad518
2618d2c
207fba5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,8 +30,11 @@ | |
import java.util.concurrent.Future; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.TimeoutException; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.bookkeeper.mledger.ManagedLedger; | ||
import org.apache.commons.lang3.tuple.ImmutableTriple; | ||
import org.apache.pulsar.broker.BrokerTestUtil; | ||
import org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest; | ||
import org.apache.pulsar.broker.service.persistent.PersistentTopic; | ||
import org.apache.pulsar.client.api.MessageId; | ||
|
@@ -51,6 +54,7 @@ | |
import org.testng.annotations.Test; | ||
|
||
@Test(groups = "broker-impl") | ||
@Slf4j | ||
public class RawReaderTest extends MockedPulsarServiceBaseTest { | ||
|
||
private static final String subscription = "foobar-sub"; | ||
|
@@ -62,6 +66,7 @@ | |
"org.apache.pulsar.common.intercept.AppendBrokerTimestampMetadataInterceptor", | ||
"org.apache.pulsar.common.intercept.AppendIndexMetadataInterceptor" | ||
)); | ||
conf.setSystemTopicEnabled(false); | ||
conf.setExposingBrokerEntryMetadataToClientEnabled(true); | ||
super.internalSetup(); | ||
|
||
|
@@ -116,7 +121,7 @@ | |
@Test | ||
public void testHasMessageAvailableWithoutBatch() throws Exception { | ||
int numKeys = 10; | ||
String topic = "persistent://my-property/my-ns/my-raw-topic"; | ||
String topic = "persistent://my-property/my-ns/" + BrokerTestUtil.newUniqueName("reader"); | ||
Set<String> keys = publishMessages(topic, numKeys); | ||
RawReader reader = RawReader.create(pulsarClient, topic, subscription).get(); | ||
while (true) { | ||
|
@@ -133,43 +138,56 @@ | |
} | ||
} | ||
Assert.assertTrue(keys.isEmpty()); | ||
reader.closeAsync().get(3, TimeUnit.SECONDS); | ||
} | ||
|
||
@Test | ||
public void testHasMessageAvailableWithBatch() throws Exception { | ||
int numKeys = 20; | ||
String topic = "persistent://my-property/my-ns/my-raw-topic"; | ||
String topic = "persistent://my-property/my-ns/" + BrokerTestUtil.newUniqueName("reader"); | ||
Set<String> keys = publishMessages(topic, numKeys, true); | ||
RawReader reader = RawReader.create(pulsarClient, topic, subscription).get(); | ||
int messageCount = 0; | ||
AtomicBoolean error = new AtomicBoolean(false); | ||
List<MessageId> ids = new ArrayList<>(); | ||
List<String> keys2 = new ArrayList<>(); | ||
while (true) { | ||
boolean hasMsg = reader.hasMessageAvailableAsync().get(); | ||
if (hasMsg && (messageCount == numKeys)) { | ||
Assert.fail("HasMessageAvailable shows still has message when there is no message"); | ||
error.set(true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you change this? If you are using the Atomicboolean, you need to break after the set. Otherwise, this test will be blocked at There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will revert this when find the root cause. |
||
} | ||
if (hasMsg) { | ||
try (RawMessage m = reader.readNextAsync().get()) { | ||
Check failure on line 160 in pulsar-broker/src/test/java/org/apache/pulsar/client/impl/RawReaderTest.java GitHub Actions / CI - Unit - Brokers - Client ImplRawReaderTest.testHasMessageAvailableWithBatch
|
||
MessageMetadata meta = Commands.parseMessageMetadata(m.getHeadersAndPayload()); | ||
messageCount += meta.getNumMessagesInBatch(); | ||
RawBatchConverter.extractIdsAndKeysAndSize(m).forEach(batchInfo -> { | ||
String key = batchInfo.getMiddle(); | ||
Assert.assertTrue(keys.remove(key)); | ||
keys2.add(key); | ||
ids.add(batchInfo.getLeft()); | ||
log.info("ids : {}, keys2 : {}", ids, keys2); | ||
if (!error.get()) { | ||
Assert.assertTrue(keys.remove(key)); | ||
} | ||
}); | ||
|
||
} | ||
} else { | ||
break; | ||
} | ||
} | ||
if (error.get()) { | ||
Assert.assertEquals(ids, keys2); | ||
} | ||
Assert.assertEquals(messageCount, numKeys); | ||
Assert.assertTrue(keys.isEmpty()); | ||
reader.closeAsync().get(3, TimeUnit.SECONDS); | ||
} | ||
|
||
@Test | ||
public void testRawReader() throws Exception { | ||
int numKeys = 10; | ||
|
||
String topic = "persistent://my-property/my-ns/my-raw-topic"; | ||
String topic = "persistent://my-property/my-ns/" + BrokerTestUtil.newUniqueName("reader"); | ||
|
||
Set<String> keys = publishMessages(topic, numKeys); | ||
|
||
|
@@ -185,12 +203,13 @@ | |
} | ||
} | ||
Assert.assertTrue(keys.isEmpty()); | ||
reader.closeAsync().get(3, TimeUnit.SECONDS); | ||
} | ||
|
||
@Test | ||
public void testSeekToStart() throws Exception { | ||
int numKeys = 10; | ||
String topic = "persistent://my-property/my-ns/my-raw-topic"; | ||
String topic = "persistent://my-property/my-ns/" + BrokerTestUtil.newUniqueName("reader"); | ||
|
||
publishMessages(topic, numKeys); | ||
|
||
|
@@ -219,12 +238,13 @@ | |
} | ||
} | ||
Assert.assertTrue(readKeys.isEmpty()); | ||
reader.closeAsync().get(3, TimeUnit.SECONDS); | ||
} | ||
|
||
@Test | ||
public void testSeekToMiddle() throws Exception { | ||
int numKeys = 10; | ||
String topic = "persistent://my-property/my-ns/my-raw-topic"; | ||
String topic = "persistent://my-property/my-ns/" + BrokerTestUtil.newUniqueName("reader"); | ||
|
||
publishMessages(topic, numKeys); | ||
|
||
|
@@ -262,6 +282,7 @@ | |
} | ||
} | ||
Assert.assertTrue(readKeys.isEmpty()); | ||
reader.closeAsync().get(3, TimeUnit.SECONDS); | ||
} | ||
|
||
/** | ||
|
@@ -270,7 +291,7 @@ | |
@Test | ||
public void testFlowControl() throws Exception { | ||
int numMessages = RawReaderImpl.DEFAULT_RECEIVER_QUEUE_SIZE * 5; | ||
String topic = "persistent://my-property/my-ns/my-raw-topic"; | ||
String topic = "persistent://my-property/my-ns/" + BrokerTestUtil.newUniqueName("reader"); | ||
|
||
publishMessages(topic, numMessages); | ||
|
||
|
@@ -296,12 +317,13 @@ | |
} | ||
Assert.assertEquals(timeouts, 1); | ||
Assert.assertEquals(keys.size(), numMessages); | ||
reader.closeAsync().get(3, TimeUnit.SECONDS); | ||
} | ||
|
||
@Test | ||
public void testFlowControlBatch() throws Exception { | ||
int numMessages = RawReaderImpl.DEFAULT_RECEIVER_QUEUE_SIZE * 5; | ||
String topic = "persistent://my-property/my-ns/my-raw-topic"; | ||
String topic = "persistent://my-property/my-ns/" + BrokerTestUtil.newUniqueName("reader"); | ||
|
||
publishMessages(topic, numMessages, true); | ||
|
||
|
@@ -324,11 +346,12 @@ | |
} | ||
} | ||
Assert.assertEquals(keys.size(), numMessages); | ||
reader.closeAsync().get(3, TimeUnit.SECONDS); | ||
} | ||
|
||
@Test | ||
public void testBatchingExtractKeysAndIds() throws Exception { | ||
String topic = "persistent://my-property/my-ns/my-raw-topic"; | ||
String topic = "persistent://my-property/my-ns/" + BrokerTestUtil.newUniqueName("reader"); | ||
|
||
try (Producer<byte[]> producer = pulsarClient.newProducer().topic(topic) | ||
.maxPendingMessages(3) | ||
|
@@ -363,7 +386,7 @@ | |
|
||
@Test | ||
public void testBatchingRebatch() throws Exception { | ||
String topic = "persistent://my-property/my-ns/my-raw-topic"; | ||
String topic = "persistent://my-property/my-ns/" + BrokerTestUtil.newUniqueName("reader"); | ||
|
||
try (Producer<byte[]> producer = pulsarClient.newProducer().topic(topic) | ||
.maxPendingMessages(3) | ||
|
@@ -392,7 +415,7 @@ | |
|
||
@Test | ||
public void testBatchingRebatchWithBrokerEntryMetadata() throws Exception { | ||
String topic = "persistent://my-property/my-ns/my-raw-topic"; | ||
String topic = "persistent://my-property/my-ns/" + BrokerTestUtil.newUniqueName("reader"); | ||
|
||
try (Producer<byte[]> producer = pulsarClient.newProducer().topic(topic) | ||
.maxPendingMessages(3) | ||
|
@@ -428,7 +451,7 @@ | |
public void testAcknowledgeWithProperties() throws Exception { | ||
int numKeys = 10; | ||
|
||
String topic = "persistent://my-property/my-ns/my-raw-topic"; | ||
String topic = "persistent://my-property/my-ns/" + BrokerTestUtil.newUniqueName("reader"); | ||
|
||
Set<String> keys = publishMessages(topic, numKeys); | ||
|
||
|
@@ -459,14 +482,14 @@ | |
Assert.assertEquals( | ||
ledger.openCursor(subscription).getProperties().get("foobar"), | ||
Long.valueOf(0xdeadbeefdecaL))); | ||
|
||
reader.closeAsync().get(3, TimeUnit.SECONDS); | ||
} | ||
|
||
@Test | ||
public void testReadCancellationOnClose() throws Exception { | ||
int numKeys = 10; | ||
|
||
String topic = "persistent://my-property/my-ns/my-raw-topic"; | ||
String topic = "persistent://my-property/my-ns/" + BrokerTestUtil.newUniqueName("reader"); | ||
publishMessages(topic, numKeys/2); | ||
|
||
RawReader reader = RawReader.create(pulsarClient, topic, subscription).get(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -529,7 +529,7 @@ protected void txnAckTest(boolean batchEnable, int maxBatchSize, | |
// after transaction abort, the messages could be received | ||
Transaction commitTxn = getTxn(); | ||
for (int i = 0; i < messageCnt; i++) { | ||
message = consumer.receive(2, TimeUnit.SECONDS); | ||
message = consumer.receive(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the network is not good, here will fail. so no need to add timeout for this. |
||
Assert.assertNotNull(message); | ||
consumer.acknowledgeAsync(message.getMessageId(), commitTxn).get(); | ||
log.info("receive msgId: {}, count: {}", message.getMessageId(), i); | ||
|
@@ -741,6 +741,7 @@ private void txnCumulativeAckTest(boolean batchEnable, int maxBatchSize, Subscri | |
for (int i = 0; i < messageCnt; i++){ | ||
producer.newMessage().value("hello".getBytes()).sendAsync(); | ||
} | ||
producer.flush(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
Message<byte[]> message = null; | ||
Thread.sleep(1000L); | ||
for (int i = 0; i < messageCnt; i++) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Locally run takes about 8s sometimes, so remove this.