danielxjd commented on a change in pull request #12223: URL: https://github.com/apache/beam/pull/12223#discussion_r479552231
########## File path: sdks/java/io/parquet/src/test/java/org/apache/beam/sdk/io/parquet/ParquetIOTest.java ########## @@ -69,6 +76,44 @@ "Faraday", "Newton", "Bohr", "Galilei", "Maxwell" }; + @Test + public void testBlockTracker() throws Exception { + OffsetRange range = new OffsetRange(0, 1); + ParquetIO.ReadFiles.BlockTracker tracker = new ParquetIO.ReadFiles.BlockTracker(range, 7, 3); + assertTrue(Math.abs(tracker.getProgress().getWorkRemaining() - 6) < 0.01); Review comment: Noted! ########## File path: sdks/java/io/parquet/src/test/java/org/apache/beam/sdk/io/parquet/ParquetIOTest.java ########## @@ -69,6 +76,44 @@ "Faraday", "Newton", "Bohr", "Galilei", "Maxwell" }; + @Test + public void testBlockTracker() throws Exception { + OffsetRange range = new OffsetRange(0, 1); + ParquetIO.ReadFiles.BlockTracker tracker = new ParquetIO.ReadFiles.BlockTracker(range, 7, 3); + assertTrue(Math.abs(tracker.getProgress().getWorkRemaining() - 6) < 0.01); + assertTrue(Math.abs(tracker.getProgress().getWorkCompleted()) < 0.01); + tracker.tryClaim((long) 0); Review comment: Noted! ########## File path: sdks/java/io/parquet/src/test/java/org/apache/beam/sdk/io/parquet/ParquetIOTest.java ########## @@ -69,6 +76,44 @@ "Faraday", "Newton", "Bohr", "Galilei", "Maxwell" }; + @Test + public void testBlockTracker() throws Exception { + OffsetRange range = new OffsetRange(0, 1); + ParquetIO.ReadFiles.BlockTracker tracker = new ParquetIO.ReadFiles.BlockTracker(range, 7, 3); + assertTrue(Math.abs(tracker.getProgress().getWorkRemaining() - 6) < 0.01); + assertTrue(Math.abs(tracker.getProgress().getWorkCompleted()) < 0.01); + tracker.tryClaim((long) 0); + tracker.makeProgress(); + assertTrue(Math.abs(tracker.getProgress().getWorkRemaining() - 4) < 0.01); + assertTrue(Math.abs(tracker.getProgress().getWorkCompleted() - 2) < 0.01); + assertThrows(RuntimeException.class, () -> tracker.tryClaim((long) 0)); + tracker.makeProgress(); + tracker.makeProgress(); + assertTrue(Math.abs(tracker.getProgress().getWorkRemaining() - 0) < 0.01); + assertTrue(Math.abs(tracker.getProgress().getWorkCompleted() - 6) < 0.01); + assertThrows("Making progress out of range", IOException.class, () -> tracker.makeProgress()); + } + + @Test + public void testSplitBlockWithLimit() { + ParquetIO.ReadFiles.SplitReadFn testFn = new ParquetIO.ReadFiles.SplitReadFn(null); + ArrayList<BlockMetaData> blockList = new ArrayList<BlockMetaData>(); + ArrayList<OffsetRange> rangeList; + BlockMetaData testBlock = mock(BlockMetaData.class); + when(testBlock.getTotalByteSize()).thenReturn((long) 60); + rangeList = testFn.splitBlockWithLimit(0, blockList.size(), blockList, 200); + assertTrue(rangeList.isEmpty()); + for (int i = 0; i < 6; i++) { + blockList.add(testBlock); + } + rangeList = testFn.splitBlockWithLimit(1, blockList.size(), blockList, 200); + assertTrue(rangeList.get(0).getFrom() == (long) 1); Review comment: Okay! ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org