Skip to content

Commit

Permalink
Resolve the flaky test ReplicatorTest.testCloseReplicatorStartProducer (
Browse files Browse the repository at this point in the history
apache#1815)

### Motivation

Fixed the flaky behavior by ensuring the read operation completes with the expected failure instead of throwing assertion error in background.
  • Loading branch information
merlimat authored and sijie committed May 23, 2018
1 parent 9bf943f commit e8c8c37
Showing 1 changed file with 7 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,6 @@ public void testResumptionAfterBacklogRelaxed() throws Exception {
*/
@Test(timeOut = 15000)
public void testCloseReplicatorStartProducer() throws Exception {

TopicName dest = TopicName.get("persistent://pulsar/ns1/closeCursor");
// Producer on r1
MessageProducer producer1 = new MessageProducer(url1, dest);
Expand All @@ -815,27 +814,20 @@ public void testCloseReplicatorStartProducer() throws Exception {
ManagedCursor cursor = (ManagedCursor) cursorField.get(replicator);
cursor.close();
// try to read entries
CountDownLatch latch = new CountDownLatch(1);
producer1.produce(10);
cursor.asyncReadEntriesOrWait(10, new ReadEntriesCallback() {
@Override
public void readEntriesComplete(List<Entry> entries, Object ctx) {
latch.countDown();
fail("it should have been failed");
}

@Override
public void readEntriesFailed(ManagedLedgerException exception, Object ctx) {
latch.countDown();
assertTrue(exception instanceof CursorAlreadyClosedException);
}
}, null);
try {
cursor.readEntriesOrWait(10);
fail("It should have failed");
} catch (Exception e) {
assertEquals(e.getClass(), CursorAlreadyClosedException.class);
}

// replicator-readException: cursorAlreadyClosed
replicator.readEntriesFailed(new CursorAlreadyClosedException("Cursor already closed exception"), null);

// wait replicator producer to be closed
Thread.sleep(1000);
Thread.sleep(100);

// Replicator producer must be closed
Field producerField = AbstractReplicator.class.getDeclaredField("producer");
Expand Down

0 comments on commit e8c8c37

Please sign in to comment.