You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by bo...@apache.org on 2022/04/14 03:11:20 UTC

[pulsar] branch master updated: Fix clear transaction buffer snapshot flaky test (#14922)

This is an automated email from the ASF dual-hosted git repository.

bogong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new 4ad8b5b0bca Fix clear transaction buffer snapshot flaky test (#14922)
4ad8b5b0bca is described below

commit 4ad8b5b0bca4e18f0f92589545c3c81253656598
Author: Kai Wang <kw...@streamnative.io>
AuthorDate: Thu Apr 14 11:11:11 2022 +0800

    Fix clear transaction buffer snapshot flaky test (#14922)
    
    ### Motivation
    ```
    java.lang.AssertionError:
    Expected :true
    Actual   :false
    <Click to see difference>
            at org.testng.Assert.fail(Assert.java:99)
            at org.testng.Assert.failNotEquals(Assert.java:1037)
            at org.testng.Assert.assertTrue(Assert.java:45)
            at org.testng.Assert.assertTrue(Assert.java:55)
            at org.apache.pulsar.broker.transaction.TopicTransactionBufferRecoverTest.checkSnapshotCount(TopicTransactionBufferRecoverTest.java:452)
            at org.apache.pulsar.broker.transaction.TopicTransactionBufferRecoverTest.clearTransactionBufferSnapshotTest(TopicTransactionBufferRecoverTest.java:427)
            at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
            at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.base/java.lang.reflect.Method.invoke(Method.java:566)
            at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:132)
    // ...
    ```
    
    Currently, the clear transaction buffer snapshot is flaky, because we used `@Cleanup` annotation, the `@Cleanup` annotation will put the close producer method to the bottom of the test method, then the producer will close after deleting the topic.
    
    When we delete the topic, all relevant producers will receive a `CLOSE_PRODUCER` command, then the producer client will try to reconnect to the broker, so it will send the `PRODUCER` command again, then the transaction buffer snapshot will take a new snapshot, so the test will fail.
    
    ### Modifications
    
    Make the producer close before the topic deleting.
---
 .../pulsar/broker/transaction/TopicTransactionBufferRecoverTest.java    | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/transaction/TopicTransactionBufferRecoverTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/transaction/TopicTransactionBufferRecoverTest.java
index 2ea7104c8db..78259c23b8a 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/transaction/TopicTransactionBufferRecoverTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/transaction/TopicTransactionBufferRecoverTest.java
@@ -391,7 +391,6 @@ public class TopicTransactionBufferRecoverTest extends TransactionTestBase {
     public void clearTransactionBufferSnapshotTest() throws Exception {
         String topic = NAMESPACE1 + "/tb-snapshot-delete-" + RandomUtils.nextInt();
 
-        @Cleanup
         Producer<byte[]> producer = pulsarClient
                 .newProducer()
                 .topic(topic)
@@ -404,6 +403,7 @@ public class TopicTransactionBufferRecoverTest extends TransactionTestBase {
         producer.newMessage(txn).value("test".getBytes()).sendAsync();
         producer.newMessage(txn).value("test".getBytes()).sendAsync();
         txn.commit().get();
+        producer.close();
 
         // take snapshot
         PersistentTopic originalTopic = (PersistentTopic) getPulsarServiceList().get(0)