congbobo184 commented on code in PR #20055:
URL: https://github.com/apache/pulsar/pull/20055#discussion_r1170345584
##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/transaction/TransactionImpl.java:
##########
@@ -186,13 +187,15 @@ public void registerAckOp(CompletableFuture<Void>
newAckFuture) {
@Override
public CompletableFuture<Void> commit() {
timeout.cancel();
- return checkIfOpenOrCommitting().thenCompose((value) -> {
+ return checkState(State.OPEN, State.COMMITTING).thenCompose((value) ->
{
CompletableFuture<Void> commitFuture = new CompletableFuture<>();
this.state = State.COMMITTING;
opFuture.whenComplete((v, e) -> {
if (hasOpsFailed) {
- abort().whenComplete((vx, ex) ->
commitFuture.completeExceptionally(new PulsarClientException
- .TransactionHasOperationFailedException()));
+ timeout.cancel();
Review Comment:
line-189 has `timeout.cancel();`
##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/transaction/TransactionProduceTest.java:
##########
@@ -369,5 +373,24 @@ private int getPendingAckCount(String topic, String
subscriptionName) throws Exc
return pendingAckCount;
}
-
+ @Test
+ public void testCommitFailure() throws Exception {
+ Transaction txn = pulsarClient.newTransaction().build().get();
+ final String topic = NAMESPACE1 + "/test-commit-failure";
+ @Cleanup
+ final Producer<byte[]> producer =
pulsarClient.newProducer().topic(topic).create();
+ producer.newMessage(txn).value(new byte[1024 * 1024 * 10]).sendAsync();
+ try {
+ txn.commit().get();
+ } catch (ExecutionException e) {
+ Assert.assertTrue(e.getCause() instanceof
PulsarClientException.TransactionHasOperationFailedException);
+ Assert.assertEquals(txn.getState(), Transaction.State.ABORTED);
+ }
+ try {
+
getPulsarServiceList().get(0).getTransactionMetadataStoreService().getTxnMeta(txn.getTxnID())
+ .getNow(null);
+ } catch (CompletionException e) {
Review Comment:
```suggestion
getPulsarServiceList().get(0).getTransactionMetadataStoreService().getTxnMeta(txn.getTxnID())
.getNow(null);
fail();
} catch (CompletionException e) {
```
##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/transaction/TransactionProduceTest.java:
##########
@@ -369,5 +373,24 @@ private int getPendingAckCount(String topic, String
subscriptionName) throws Exc
return pendingAckCount;
}
-
+ @Test
+ public void testCommitFailure() throws Exception {
+ Transaction txn = pulsarClient.newTransaction().build().get();
+ final String topic = NAMESPACE1 + "/test-commit-failure";
+ @Cleanup
+ final Producer<byte[]> producer =
pulsarClient.newProducer().topic(topic).create();
+ producer.newMessage(txn).value(new byte[1024 * 1024 * 10]).sendAsync();
+ try {
+ txn.commit().get();
+ } catch (ExecutionException e) {
Review Comment:
```suggestion
try {
txn.commit().get();
fail();
} catch (ExecutionException e) {
```
--
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]