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

[issue #3975] Bugfix NPE on non durable consumer #3988

Merged
merged 1 commit into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -193,6 +193,7 @@ public interface ManagedLedger {
* @return the new NonDurableCursor
*/
ManagedCursor newNonDurableCursor(Position startCursorPosition) throws ManagedLedgerException;
ManagedCursor newNonDurableCursor(Position startPosition, String subscriptionName) throws ManagedLedgerException;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that the correct action here would be to modify existing newNonDurableCursor instead of adding a new one, but I did that way in order to leave this change as easy as possible, please let me know what you think.


/**
* Delete a ManagedCursor asynchronously.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,16 @@ public ManagedCursor newNonDurableCursor(Position startCursorPosition) throws Ma
return new NonDurableCursorImpl(bookKeeper, config, this, null, (PositionImpl) startCursorPosition);
}

@Override
public ManagedCursor newNonDurableCursor(Position startCursorPosition, String cursorName)
throws ManagedLedgerException {
checkManagedLedgerIsOpen();
checkFenced();

return new NonDurableCursorImpl(bookKeeper, config, this, cursorName,
(PositionImpl) startCursorPosition);
}

@Override
public Iterable<ManagedCursor> getCursors() {
return cursors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ private CompletableFuture<? extends Subscription> getNonDurableSubscription(Stri
Position startPosition = new PositionImpl(ledgerId, entryId);
ManagedCursor cursor = null;
try {
cursor = ledger.newNonDurableCursor(startPosition);
cursor = ledger.newNonDurableCursor(startPosition, subscriptionName);
} catch (ManagedLedgerException e) {
subscriptionFuture.completeExceptionally(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
import java.util.concurrent.TimeUnit;
import org.apache.pulsar.client.impl.BatchMessageIdImpl;
import org.apache.pulsar.client.impl.MessageImpl;
import org.apache.pulsar.client.impl.ReaderImpl;
import org.apache.pulsar.common.policies.data.TopicStats;
import org.apache.pulsar.common.util.RelativeTimeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
Expand Down Expand Up @@ -479,9 +481,33 @@ public void testMessageAvailableAfterRestart() throws Exception {
assertTrue(reader.hasMessageAvailable());

String readOut = new String(reader.readNext().getData());
assertTrue(readOut.equals(content));
assertEquals(content, readOut);
assertFalse(reader.hasMessageAvailable());
}

}

@Test(timeOut = 10000)
public void testReaderNonDurableIsAbleToSeekRelativeTime() throws Exception {
final int numOfMessage = 10;
final String topicName = "persistent://my-property/my-ns/ReaderSeek";

Producer<byte[]> producer = pulsarClient.newProducer()
.topic(topicName).create();

for (int i = 0; i < numOfMessage; i++) {
producer.send(String.format("msg num %d", i).getBytes());
}

Reader<byte[]> reader = pulsarClient.newReader().topic(topicName)
.startMessageId(MessageId.earliest).create();
assertTrue(reader.hasMessageAvailable());

((ReaderImpl) reader).getConsumer().seek(RelativeTimeUtil.parseRelativeTimeInSeconds("-1m"));

assertTrue(reader.hasMessageAvailable());

reader.close();
producer.close();
}
}