Skip to content

Commit

Permalink
[fix][test] fix test testSyncNormalPositionWhenTBRecover (#22120)
Browse files Browse the repository at this point in the history
### Motivation
1. Change to None state before invoking the recovery.
2. Improve the method `checkTopicTransactionBufferState` to see the test result easier. 
```
org.awaitility.core.ConditionTimeoutException: Condition with org.apache.pulsar.broker.transaction.buffer.TransactionStablePositionTest was not fulfilled within 10 seconds.

	at org.awaitility.core.ConditionAwaiter.await(ConditionAwaiter.java:167)
	at org.awaitility.core.CallableCondition.await(CallableCondition.java:78)
	at org.awaitility.core.CallableCondition.await(CallableCondition.java:26)
	at org.awaitility.core.ConditionFactory.until(ConditionFactory.java:985)
	at org.awaitility.core.ConditionFactory.until(ConditionFactory.java:954)
	at org.apache.pulsar.broker.transaction.buffer.TransactionStablePositionTest.checkTopicTransactionBufferState(TransactionStablePositionTest.java:239)
	at org.apache.pulsar.broker.transaction.buffer.TransactionStablePositionTest.testSyncNormalPositionWhenTBRecover(TransactionStablePositionTest.java:229)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:139)
	at org.testng.internal.invokers.TestInvoker.invokeMethod(TestInvoker.java:677)
	at org.testng.internal.invokers.TestInvoker.invokeTestMethod(TestInvoker.java:221)
	at org.testng.internal.invokers.MethodRunner.runInSequence(MethodRunner.java:50)
	at org.testng.internal.invokers.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:969)
	at org.testng.internal.invokers.TestInvoker.invokeTestMethods(TestInvoker.java:194)
	at org.testng.internal.invokers.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:148)
	at org.testng.internal.invokers.TestMethodWorker.run(TestMethodWorker.java:128)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at org.testng.TestRunner.privateRun(TestRunner.java:829)
	at org.testng.TestRunner.run(TestRunner.java:602)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:437)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:431)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:391)
	at org.testng.SuiteRunner.run(SuiteRunner.java:330)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:95)
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1256)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1176)
	at org.testng.TestNG.runSuites(TestNG.java:1099)
	at org.testng.TestNG.run(TestNG.java:1067)
	at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:65)
	at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:105)

```
### Modifications
1. Change to None state before invoking the recovery.
2. Improve the method `checkTopicTransactionBufferState` to see the test result easier.
  • Loading branch information
liangyepianzhou authored and Technoboy- committed Feb 29, 2024
1 parent a74c059 commit b41e0df
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,14 @@ public void testSyncNormalPositionWhenTBRecover(boolean clientEnableTransaction,
position = topicTransactionBuffer.getMaxReadPosition();
assertEquals(position, PositionImpl.EARLIEST);

// change to None state can recover
field.set(topicTransactionBuffer, TopicTransactionBufferState.State.None);

// invoke recover
Method method = TopicTransactionBuffer.class.getDeclaredMethod("recover");
method.setAccessible(true);
method.invoke(topicTransactionBuffer);

// change to None state can recover
field.set(topicTransactionBuffer, TopicTransactionBufferState.State.None);

// recover success again
checkTopicTransactionBufferState(clientEnableTransaction, topicTransactionBuffer);

Expand All @@ -236,13 +236,15 @@ public void testSyncNormalPositionWhenTBRecover(boolean clientEnableTransaction,
private void checkTopicTransactionBufferState(boolean clientEnableTransaction,
TopicTransactionBuffer topicTransactionBuffer) {
// recover success
Awaitility.await().until(() -> {
Awaitility.await().untilAsserted(() -> {
if (clientEnableTransaction) {
// recover success, client enable transaction will change to Ready State
return topicTransactionBuffer.getStats(false, false).state.equals(Ready.name());
assertEquals(topicTransactionBuffer.getStats(false, false).state,
Ready.name());
} else {
// recover success, client disable transaction will change to NoSnapshot State
return topicTransactionBuffer.getStats(false, false).state.equals(NoSnapshot.name());
assertEquals(topicTransactionBuffer.getStats(false, false).state,
NoSnapshot.name());
}
});
}
Expand Down

0 comments on commit b41e0df

Please sign in to comment.