poorbarcode commented on code in PR #16727:
URL: https://github.com/apache/pulsar/pull/16727#discussion_r927246552


##########
pulsar-transaction/coordinator/src/test/java/org/apache/pulsar/transaction/coordinator/impl/TxnLogBufferedWriterTest.java:
##########
@@ -382,37 +398,49 @@ public Object answer(InvocationOnMock invocation) throws 
Throwable {
                 return null;
             }
         }).when(managedLedger).asyncAddEntry(Mockito.any(ByteBuf.class), 
Mockito.any(), Mockito.any());
-        // Test threshold: writeMaxDelayInMillis.
-        TxnLogBufferedWriter txnLogBufferedWriter1 = new 
TxnLogBufferedWriter<>(managedLedger, orderedExecutor,
-                scheduledExecutorService, dataSerializer, 32, 1024 * 4, 100, 
true);
         TxnLogBufferedWriter.AddDataCallback callback = 
Mockito.mock(TxnLogBufferedWriter.AddDataCallback.class);
-        txnLogBufferedWriter1.asyncAddData(100, callback, 100);
+
+        // Test threshold: writeMaxDelayInMillis (use scheduled service).
+        TxnLogBufferedWriter txnLogBufferedWriter0 = new 
TxnLogBufferedWriter<>(managedLedger, orderedExecutor,
+                scheduledExecutorService, dataSerializer, 32, 1024 * 4, 100, 
true);
+
+        txnLogBufferedWriter0.asyncAddData(100, callback, 100);
         Thread.sleep(90);
         // Verify does not refresh ahead of time.
         Assert.assertEquals(dataArrayFlushedToBookie.size(), 0);
         Awaitility.await().atMost(2, TimeUnit.SECONDS).until(() -> 
dataArrayFlushedToBookie.size() == 1);
         Assert.assertEquals(dataArrayFlushedToBookie.get(0).intValue(), 100);
+        txnLogBufferedWriter0.close();
+
+        // Test threshold: writeMaxDelayInMillis (use timer).
+        TxnLogBufferedWriter txnLogBufferedWriter1 = new 
TxnLogBufferedWriter<>(managedLedger, orderedExecutor,
+                transactionTimer, dataSerializer, 32, 1024 * 4, 100, true);
+        txnLogBufferedWriter1.asyncAddData(100, callback, 100);
+        Thread.sleep(70);

Review Comment:
   > Why is this not equal to writeMaxDelayInMillis?
   
   This is to verify that the task will not be executed prematurely, so less 
than `writeMaxDelayInMillis`.
   
   > And if we can not use the `Thread.sleep()`.
   
   Is there a recommended implementation ?



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