Skip to content

Commit

Permalink
Fix: close() never gets called for BatchSource (apache#7866)
Browse files Browse the repository at this point in the history
Motivation
close() method never gets called in BatchSource
  • Loading branch information
jerrypeng authored Aug 21, 2020
1 parent 7d9319d commit 2ee109e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ private void stop() throws Exception {
intermediateTopicConsumer.close();
intermediateTopicConsumer = null;
}
if (batchSource != null) {
batchSource.close();
}
}

private void setupInstanceSubscription() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public static class TestBatchSource implements BatchSource<String> {
private static int discoverCount;
@Getter
private static int recordCount;
@Getter
private static int closeCount;
private Record record = Mockito.mock(Record.class);
public TestBatchSource() { }

Expand Down Expand Up @@ -87,7 +89,7 @@ public Record<String> readNext() throws Exception {

@Override
public void close() throws Exception {

closeCount++;
}
}

Expand All @@ -98,6 +100,8 @@ public static class TestBatchPushSource extends BatchPushSource<String> {
private static int discoverCount;
@Getter
private static int recordCount;
@Getter
private static int closeCount;
private Record record = Mockito.mock(Record.class);
public TestBatchPushSource() { }

Expand Down Expand Up @@ -127,7 +131,7 @@ public void prepare(byte[] task) throws Exception {

@Override
public void close() throws Exception {

closeCount++;
}
}

Expand Down Expand Up @@ -344,6 +348,8 @@ public void testLifeCycle() throws Exception {
discoveryBarrier.await();
Assert.assertTrue(testBatchSource.getDiscoverCount() >= 2);
Assert.assertTrue(testBatchSource.getDiscoverCount() <= 3);
batchSourceExecutor.close();
Assert.assertEquals(testBatchSource.getCloseCount(), 1);
}

@Test
Expand All @@ -362,5 +368,7 @@ public void testPushLifeCycle() throws Exception {
discoveryBarrier.await();
Assert.assertTrue(testBatchPushSource.getDiscoverCount() >= 2);
Assert.assertTrue(testBatchPushSource.getDiscoverCount() <= 3);
batchSourceExecutor.close();
Assert.assertEquals(testBatchPushSource.getCloseCount(), 1);
}
}

0 comments on commit 2ee109e

Please sign in to comment.