Skip to content
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

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public void testReadMessageWithBatchingWithMessageInclusive() throws Exception {
reader.close();
}

@Test(timeOut = 10000)
@Test
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public void testReaderWithTimeLong() throws Exception {
String ns = "my-property/my-ns";
String topic = "persistent://" + ns + "/testReadFromPartition" + UUID.randomUUID();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public void testNegativeAcksDeleteFromUnackedTracker() throws Exception {
negativeAcksTracker.close();
}

@Test(timeOut = 10000)
@Test
Copy link
Contributor Author

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.

public void testNegativeAcksWithBatchAckEnabled() throws Exception {
cleanup();
conf.setAcknowledgmentAtBatchIndexLevelEnabled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
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;
Expand All @@ -51,6 +53,7 @@
import org.testng.annotations.Test;

@Test(groups = "broker-impl")
@Slf4j
public class RawReaderTest extends MockedPulsarServiceBaseTest {

private static final String subscription = "foobar-sub";
Expand All @@ -62,6 +65,7 @@
"org.apache.pulsar.common.intercept.AppendBrokerTimestampMetadataInterceptor",
"org.apache.pulsar.common.intercept.AppendIndexMetadataInterceptor"
));
conf.setSystemTopicEnabled(false);
conf.setExposingBrokerEntryMetadataToClientEnabled(true);
super.internalSetup();

Expand Down Expand Up @@ -116,7 +120,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) {
Expand All @@ -133,19 +137,20 @@
}
}
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;
while (true) {
boolean hasMsg = reader.hasMessageAvailableAsync().get();
if (hasMsg && (messageCount == numKeys)) {
Assert.fail("HasMessageAvailable shows still has message when there is no message");

Check failure on line 153 in pulsar-broker/src/test/java/org/apache/pulsar/client/impl/RawReaderTest.java

View workflow job for this annotation

GitHub Actions / CI - Unit - Brokers - Client Impl

RawReaderTest.testHasMessageAvailableWithBatch

HasMessageAvailable shows still has message when there is no message
}
if (hasMsg) {
try (RawMessage m = reader.readNextAsync().get()) {
Expand All @@ -163,13 +168,14 @@
}
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);

Expand All @@ -185,12 +191,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);

Expand Down Expand Up @@ -219,12 +226,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);

Expand Down Expand Up @@ -262,6 +270,7 @@
}
}
Assert.assertTrue(readKeys.isEmpty());
reader.closeAsync().get(3, TimeUnit.SECONDS);
}

/**
Expand All @@ -270,7 +279,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);

Expand All @@ -296,12 +305,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);

Expand All @@ -324,11 +334,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)
Expand Down Expand Up @@ -363,7 +374,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)
Expand Down Expand Up @@ -392,7 +403,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)
Expand Down Expand Up @@ -428,7 +439,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);

Expand Down Expand Up @@ -459,14 +470,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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.
https://github.com/apache/pulsar/actions/runs/5899745435/job/16003227755?pr=21008

Assert.assertNotNull(message);
consumer.acknowledgeAsync(message.getMessageId(), commitTxn).get();
log.info("receive msgId: {}, count: {}", message.getMessageId(), i);
Expand Down Expand Up @@ -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();
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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++) {
Expand Down
Loading