liangyepianzhou commented on code in PR #21274:
URL: https://github.com/apache/pulsar/pull/21274#discussion_r1379528634
##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/transaction/pendingack/PendingAckPersistentTest.java:
##########
@@ -99,6 +104,52 @@ protected void cleanup() {
super.internalCleanup();
}
+ @Test
+ public void testUnloadSubscriptionWhenFailedInitPendingAck() throws
Exception {
+ String topic = NAMESPACE1 +
"/testUnloadSubscriptionWhenFailedInitPendingAck";
+ Consumer<byte[]> consumer1 = pulsarClient.newConsumer()
+ .subscriptionName("subName1")
+ .topic(topic)
+ .subscribe();
+ // Fail at transactionPendingAckStoreProvider::checkInitializedBefore.
+ Field transactionPendingAckStoreProviderField = PulsarService.class
+ .getDeclaredField("transactionPendingAckStoreProvider");
+ transactionPendingAckStoreProviderField.setAccessible(true);
+ TransactionPendingAckStoreProvider pendingAckStoreProvider =
+ (TransactionPendingAckStoreProvider)
transactionPendingAckStoreProviderField
+ .get(pulsarServiceList.get(0));
+ TransactionPendingAckStoreProvider mockProvider =
mock(pendingAckStoreProvider.getClass());
+ // Test retryable exception.
+ when(mockProvider.checkInitializedBefore(any()))
+ .thenReturn(FutureUtil.failedFuture(new
ManagedLedgerException("mock fail")))
+ .thenReturn(CompletableFuture.completedFuture(false));
+ transactionPendingAckStoreProviderField.set(pulsarServiceList.get(0),
mockProvider);
+ Awaitility.await().until(() -> {
+ pulsarClient.newConsumer()
+ .subscriptionName("subName2")
+ .topic(topic)
+ .subscribe();
+ return true;
+ });
Review Comment:
Only the first attempt will throw a retryable exception.
```
// Test retryable exception.
when(mockProvider.checkInitializedBefore(any()))
.thenReturn(FutureUtil.failedFuture(new
ManagedLedgerException("mock fail")))
.thenReturn(CompletableFuture.completedFuture(false));
```
##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/transaction/pendingack/PendingAckPersistentTest.java:
##########
@@ -99,6 +104,52 @@ protected void cleanup() {
super.internalCleanup();
}
+ @Test
+ public void testUnloadSubscriptionWhenFailedInitPendingAck() throws
Exception {
+ String topic = NAMESPACE1 +
"/testUnloadSubscriptionWhenFailedInitPendingAck";
+ Consumer<byte[]> consumer1 = pulsarClient.newConsumer()
+ .subscriptionName("subName1")
+ .topic(topic)
+ .subscribe();
+ // Fail at transactionPendingAckStoreProvider::checkInitializedBefore.
+ Field transactionPendingAckStoreProviderField = PulsarService.class
+ .getDeclaredField("transactionPendingAckStoreProvider");
+ transactionPendingAckStoreProviderField.setAccessible(true);
+ TransactionPendingAckStoreProvider pendingAckStoreProvider =
+ (TransactionPendingAckStoreProvider)
transactionPendingAckStoreProviderField
+ .get(pulsarServiceList.get(0));
+ TransactionPendingAckStoreProvider mockProvider =
mock(pendingAckStoreProvider.getClass());
+ // Test retryable exception.
+ when(mockProvider.checkInitializedBefore(any()))
+ .thenReturn(FutureUtil.failedFuture(new
ManagedLedgerException("mock fail")))
+ .thenReturn(CompletableFuture.completedFuture(false));
+ transactionPendingAckStoreProviderField.set(pulsarServiceList.get(0),
mockProvider);
+ Awaitility.await().until(() -> {
+ pulsarClient.newConsumer()
+ .subscriptionName("subName2")
+ .topic(topic)
+ .subscribe();
+ return true;
+ });
Review Comment:
Only the first attempt will throw a retryable exception.
```
// Test retryable exception.
when(mockProvider.checkInitializedBefore(any()))
.thenReturn(FutureUtil.failedFuture(new
ManagedLedgerException("mock fail")))
.thenReturn(CompletableFuture.completedFuture(false));
```
--
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]