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
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.concurrent.TimeoutException;
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 Down Expand Up @@ -116,7 +117,7 @@ public static String extractKey(RawMessage m) {
@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,12 +134,13 @@ public void testHasMessageAvailableWithoutBatch() throws Exception {
}
}
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;
Expand All @@ -163,13 +165,14 @@ public void testHasMessageAvailableWithBatch() throws Exception {
}
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 +188,13 @@ public void testRawReader() throws Exception {
}
}
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 +223,13 @@ public void testSeekToStart() throws Exception {
}
}
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 +267,7 @@ public void testSeekToMiddle() throws Exception {
}
}
Assert.assertTrue(readKeys.isEmpty());
reader.closeAsync().get(3, TimeUnit.SECONDS);
}

/**
Expand All @@ -270,7 +276,7 @@ public void testSeekToMiddle() throws Exception {
@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 +302,13 @@ public void testFlowControl() throws Exception {
}
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 +331,12 @@ public void testFlowControlBatch() throws Exception {
}
}
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 +371,7 @@ public void testBatchingExtractKeysAndIds() throws Exception {

@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 +400,7 @@ public void testBatchingRebatch() throws Exception {

@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 +436,7 @@ public void testBatchingRebatchWithBrokerEntryMetadata() throws Exception {
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 +467,14 @@ public void testAcknowledgeWithProperties() throws Exception {
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
Loading