eolivelli commented on code in PR #15184:
URL: https://github.com/apache/pulsar/pull/15184#discussion_r869091315


##########
managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerTest.java:
##########
@@ -291,6 +291,68 @@ public void acknowledge1() throws Exception {
         ledger.close();
     }
 
+    @Test
+    public void testDoCacheEviction() throws Throwable {
+        CompletableFuture<Boolean> result = new CompletableFuture<>();
+        ManagedLedgerConfig config = new ManagedLedgerConfig();
+        config.setCacheEvictionByMarkDeletedPosition(true);
+        factory.updateCacheEvictionTimeThreshold(TimeUnit.MILLISECONDS
+                .toNanos(30000));
+        factory.asyncOpen("my_test_ledger", config, new OpenLedgerCallback() {
+            @Override
+            public void openLedgerComplete(ManagedLedger ledger, Object ctx) {
+                ManagedLedgerImpl ledger1 = (ManagedLedgerImpl) ledger;
+                ledger.asyncOpenCursor("test-cursor", new OpenCursorCallback() 
{
+                    @Override
+                    public void openCursorComplete(ManagedCursor cursor, 
Object ctx) {
+                        ManagedLedger ledger = (ManagedLedger) ctx;
+                        String message1 = "test";
+                        ledger.asyncAddEntry(message1.getBytes(Encoding), new 
AddEntryCallback() {
+                            @Override
+                            public void addComplete(Position position, ByteBuf 
entryData, Object ctx) {
+                                @SuppressWarnings("unchecked")
+                                Pair<ManagedLedger, ManagedCursor> pair = 
(Pair<ManagedLedger, ManagedCursor>) ctx;
+                                ManagedLedger ledger = pair.getLeft();
+                                ManagedCursor cursor = pair.getRight();
+                                if (((ManagedLedgerImpl) 
ledger).getCacheSize() != message1.getBytes(Encoding).length) {
+                                    result.complete(false);
+                                    return;
+                                }
+
+                                
ledger1.getActiveCursors().removeCursor(cursor.getName());
+                                try {
+                                    ((ManagedLedgerImpl) 
ledger).doCacheEviction(

Review Comment:
   we are not testing that this method is actually doing anything useful, this 
test only verifies that there is no runtime error.
   
   can you please add some assertion that tells that the code works well even 
if `evictionPos` is null ?



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to