Skip to content

Commit

Permalink
Fix clear transaction buffer snapshot flaky test (apache#14922)
Browse files Browse the repository at this point in the history
### 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.

(cherry picked from commit 4ad8b5b)
  • Loading branch information
Demogorgon314 authored and nicoloboschi committed May 9, 2022
1 parent 6865638 commit 6baaa15
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,6 @@ private void testTopicTransactionBufferDeleteAbort() throws Exception {
public void clearTransactionBufferSnapshotTest() throws Exception {
String topic = NAMESPACE1 + "/tb-snapshot-delete-" + RandomUtils.nextInt();

@Cleanup
Producer<byte[]> producer = pulsarClient
.newProducer()
.topic(topic)
Expand All @@ -404,6 +403,7 @@ public void clearTransactionBufferSnapshotTest() throws Exception {
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)
Expand Down

0 comments on commit 6baaa15

Please sign in to comment.