|
18 | 18 | */
|
19 | 19 | package org.apache.bookkeeper.mledger.impl;
|
20 | 20 |
|
21 |
| -import static org.apache.bookkeeper.mledger.impl.cache.RangeEntryCacheImpl.BOOKKEEPER_READ_OVERHEAD_PER_ENTRY; |
22 | 21 | import static org.mockito.ArgumentMatchers.anyInt;
|
23 | 22 | import static org.mockito.Mockito.any;
|
24 | 23 | import static org.mockito.Mockito.doAnswer;
|
@@ -682,15 +681,13 @@ void testAsyncReadWithMaxSizeByte() throws Exception {
|
682 | 681 | ManagedCursor cursor = ledger.openCursor("c1");
|
683 | 682 |
|
684 | 683 | for (int i = 0; i < 100; i++) {
|
685 |
| - ledger.addEntry(new byte[(int) (1024)]); |
| 684 | + ledger.addEntry(new byte[1024]); |
686 | 685 | }
|
687 | 686 |
|
688 |
| - // Since https://github.com/apache/pulsar/pull/23931 improved the performance of delivery, the consumer |
689 |
| - // will get more messages than before(it only receives 1 messages at the first delivery), |
690 |
| - int avg = (int) (BOOKKEEPER_READ_OVERHEAD_PER_ENTRY + 1024); |
691 |
| - readAndCheck(cursor, 10, 3 * avg, 3); |
| 687 | + // First time, since we don't have info, we'll get 1 single entry |
| 688 | + readAndCheck(cursor, 10, 3 * 1024, 1); |
692 | 689 | // We should only return 3 entries, based on the max size
|
693 |
| - readAndCheck(cursor, 20, 3 * avg, 3); |
| 690 | + readAndCheck(cursor, 20, 3 * 1024, 3); |
694 | 691 | // If maxSize is < avg, we should get 1 entry
|
695 | 692 | readAndCheck(cursor, 10, 500, 1);
|
696 | 693 | }
|
@@ -3888,15 +3885,13 @@ public void testReadEntriesOrWaitWithMaxSize() throws Exception {
|
3888 | 3885 | ledger.addEntry(new byte[1024]);
|
3889 | 3886 | }
|
3890 | 3887 |
|
3891 |
| - // Since https://github.com/apache/pulsar/pull/23931 improved the performance of delivery, the consumer |
3892 |
| - // will get more messages than before(it only receives 1 messages at the first delivery), |
3893 |
| - int avg = (int) (1024 + BOOKKEEPER_READ_OVERHEAD_PER_ENTRY); |
3894 |
| - List<Entry> entries = c.readEntriesOrWait(10, 3 * avg); |
3895 |
| - assertEquals(entries.size(), 3); |
| 3888 | + // First time, since we don't have info, we'll get 1 single entry |
| 3889 | + List<Entry> entries = c.readEntriesOrWait(10, 3 * 1024); |
| 3890 | + assertEquals(entries.size(), 1); |
3896 | 3891 | entries.forEach(Entry::release);
|
3897 | 3892 |
|
3898 | 3893 | // We should only return 3 entries, based on the max size
|
3899 |
| - entries = c.readEntriesOrWait(10, 3 * avg); |
| 3894 | + entries = c.readEntriesOrWait(10, 3 * 1024); |
3900 | 3895 | assertEquals(entries.size(), 3);
|
3901 | 3896 | entries.forEach(Entry::release);
|
3902 | 3897 |
|
@@ -4803,82 +4798,5 @@ public void operationFailed(ManagedLedgerException exception) {
|
4803 | 4798 | assertEquals(cursor.getReadPosition(), markDeletedPosition.getNext());
|
4804 | 4799 | }
|
4805 | 4800 |
|
4806 |
| - @Test |
4807 |
| - public void testEstimateEntryCountBySize() throws Exception { |
4808 |
| - final String mlName = "ml-" + UUID.randomUUID().toString().replaceAll("-", ""); |
4809 |
| - ManagedLedgerImpl ml = (ManagedLedgerImpl) factory.open(mlName); |
4810 |
| - long entryCount0 = |
4811 |
| - ManagedCursorImpl.estimateEntryCountBySize(16, PositionImpl.get(ml.getCurrentLedger().getId(), 0), ml); |
4812 |
| - assertEquals(entryCount0, 1); |
4813 |
| - // Avoid trimming ledgers. |
4814 |
| - ml.openCursor("c1"); |
4815 |
| - |
4816 |
| - // Build data. |
4817 |
| - for (int i = 0; i < 100; i++) { |
4818 |
| - ml.addEntry(new byte[]{1}); |
4819 |
| - } |
4820 |
| - long ledger1 = ml.getCurrentLedger().getId(); |
4821 |
| - ml.getCurrentLedger().close(); |
4822 |
| - ml.ledgerClosed(ml.getCurrentLedger()); |
4823 |
| - for (int i = 0; i < 100; i++) { |
4824 |
| - ml.addEntry(new byte[]{1, 2}); |
4825 |
| - } |
4826 |
| - long ledger2 = ml.getCurrentLedger().getId(); |
4827 |
| - ml.getCurrentLedger().close(); |
4828 |
| - ml.ledgerClosed(ml.getCurrentLedger()); |
4829 |
| - for (int i = 0; i < 100; i++) { |
4830 |
| - ml.addEntry(new byte[]{1, 2, 3, 4}); |
4831 |
| - } |
4832 |
| - long ledger3 = ml.getCurrentLedger().getId(); |
4833 |
| - MLDataFormats.ManagedLedgerInfo.LedgerInfo ledgerInfo1 = ml.getLedgersInfo().get(ledger1); |
4834 |
| - MLDataFormats.ManagedLedgerInfo.LedgerInfo ledgerInfo2 = ml.getLedgersInfo().get(ledger2); |
4835 |
| - long average1 = ledgerInfo1.getSize() / ledgerInfo1.getEntries() + BOOKKEEPER_READ_OVERHEAD_PER_ENTRY; |
4836 |
| - long average2 = ledgerInfo2.getSize() / ledgerInfo2.getEntries() + BOOKKEEPER_READ_OVERHEAD_PER_ENTRY; |
4837 |
| - long average3 = ml.getCurrentLedgerSize() / ml.getCurrentLedgerEntries() + BOOKKEEPER_READ_OVERHEAD_PER_ENTRY; |
4838 |
| - assertEquals(average1, 1 + BOOKKEEPER_READ_OVERHEAD_PER_ENTRY); |
4839 |
| - assertEquals(average2, 2 + BOOKKEEPER_READ_OVERHEAD_PER_ENTRY); |
4840 |
| - assertEquals(average3, 4 + BOOKKEEPER_READ_OVERHEAD_PER_ENTRY); |
4841 |
| - |
4842 |
| - // Test: the individual ledgers. |
4843 |
| - long entryCount1 = |
4844 |
| - ManagedCursorImpl.estimateEntryCountBySize(average1 * 16, PositionImpl.get(ledger1, 0), ml); |
4845 |
| - assertEquals(entryCount1, 16); |
4846 |
| - long entryCount2 = |
4847 |
| - ManagedCursorImpl.estimateEntryCountBySize(average2 * 8, PositionImpl.get(ledger2, 0), ml); |
4848 |
| - assertEquals(entryCount2, 8); |
4849 |
| - long entryCount3 = |
4850 |
| - ManagedCursorImpl.estimateEntryCountBySize(average3 * 4, PositionImpl.get(ledger3, 0), ml); |
4851 |
| - assertEquals(entryCount3, 4); |
4852 |
| - |
4853 |
| - // Test: across ledgers. |
4854 |
| - long entryCount4 = |
4855 |
| - ManagedCursorImpl.estimateEntryCountBySize((average1 * 100) + (average2 * 8), PositionImpl.get(ledger1, 0), ml); |
4856 |
| - assertEquals(entryCount4, 108); |
4857 |
| - long entryCount5 = |
4858 |
| - ManagedCursorImpl.estimateEntryCountBySize((average2 * 100) + (average3 * 4), PositionImpl.get(ledger2, 0), ml); |
4859 |
| - assertEquals(entryCount5, 104); |
4860 |
| - long entryCount6 = |
4861 |
| - ManagedCursorImpl.estimateEntryCountBySize((average1 * 100) + (average2 * 100) + (average3 * 4), PositionImpl.get(ledger1, 0), ml); |
4862 |
| - assertEquals(entryCount6, 204); |
4863 |
| - |
4864 |
| - long entryCount7 = |
4865 |
| - ManagedCursorImpl.estimateEntryCountBySize((average1 * 20) + (average2 * 8), PositionImpl.get(ledger1, 80), ml); |
4866 |
| - assertEquals(entryCount7, 28); |
4867 |
| - long entryCount8 = |
4868 |
| - ManagedCursorImpl.estimateEntryCountBySize((average2 * 20) + (average3 * 4), PositionImpl.get(ledger2, 80), ml); |
4869 |
| - assertEquals(entryCount8, 24); |
4870 |
| - long entryCount9 = |
4871 |
| - ManagedCursorImpl.estimateEntryCountBySize((average1 * 20) + (average2 * 100) + (average3 * 4), PositionImpl.get(ledger1, 80), ml); |
4872 |
| - assertEquals(entryCount9, 124); |
4873 |
| - |
4874 |
| - // Test: read more than entries written. |
4875 |
| - long entryCount10 = |
4876 |
| - ManagedCursorImpl.estimateEntryCountBySize((average1 * 100) + (average2 * 100) + (average3 * 100) + (average3 * 4) , PositionImpl.get(ledger1, 0), ml); |
4877 |
| - assertEquals(entryCount10, 304); |
4878 |
| - |
4879 |
| - // cleanup. |
4880 |
| - ml.delete(); |
4881 |
| - } |
4882 |
| - |
4883 | 4801 | private static final Logger log = LoggerFactory.getLogger(ManagedCursorTest.class);
|
4884 | 4802 | }
|
0 commit comments