You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2020/10/11 11:52:03 UTC

[GitHub] [pulsar] congbobo184 commented on a change in pull request #8161: Ack response implement

congbobo184 commented on a change in pull request #8161:
URL: https://github.com/apache/pulsar/pull/8161#discussion_r502905370



##########
File path: pulsar-broker/src/test/java/org/apache/pulsar/client/impl/ConsumerAckResponseTest.java
##########
@@ -0,0 +1,91 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.client.impl;
+
+import lombok.Cleanup;
+
+import org.apache.pulsar.client.api.Message;
+import org.apache.pulsar.client.api.MessageId;
+import org.apache.pulsar.client.api.Producer;
+import org.apache.pulsar.client.api.ProducerConsumerBase;
+import org.apache.pulsar.client.api.PulsarClientException;
+import org.apache.pulsar.client.api.Schema;
+import org.apache.pulsar.client.api.SubscriptionType;
+import org.apache.pulsar.client.impl.transaction.TransactionImpl;
+
+import org.apache.pulsar.transaction.common.exception.TransactionConflictException;
+import org.testng.Assert;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+
+import static org.mockito.Mockito.*;
+
+public class ConsumerAckResponseTest extends ProducerConsumerBase {
+
+    private final static TransactionImpl transaction = mock(TransactionImpl.class);
+
+    @BeforeClass
+    public void setup() throws Exception {
+        super.internalSetup();
+        super.producerBaseSetup();
+        doReturn(1L).when(transaction).getTxnIdLeastBits();
+        doReturn(1L).when(transaction).getTxnIdMostBits();
+        CompletableFuture<Void> completableFuture = new CompletableFuture<>();
+        doReturn(completableFuture).when(transaction).registerAckOp(any());
+        doNothing().when(transaction).registerAckedTopic(any(), any());
+
+        Thread.sleep(1000 * 3);
+    }
+
+    @AfterClass
+    public void cleanup() throws Exception {
+        super.internalCleanup();
+    }
+
+    @Test
+    public void testAckResponse() throws PulsarClientException, InterruptedException, ExecutionException {
+        String topic = "testAckResponse";
+        @Cleanup
+        Producer<Integer> producer = pulsarClient.newProducer(Schema.INT32)
+                .topic(topic)
+                .enableBatching(false)
+                .create();
+        @Cleanup
+        ConsumerImpl<Integer> consumer = (ConsumerImpl<Integer>) pulsarClient.newConsumer(Schema.INT32)
+                .topic(topic)
+                .subscriptionName("sub")
+                .subscriptionType(SubscriptionType.Shared)
+                .ackTimeout(1, TimeUnit.SECONDS)
+                .subscribe();
+        producer.send(1);
+        producer.send(2);
+        try {
+            consumer.acknowledgeAsync(new MessageIdImpl(1, 1, 1), transaction).get();
+        } catch (InterruptedException | ExecutionException e) {
+            Assert.assertTrue(e.getCause() instanceof TransactionConflictException);

Review comment:
       ledgerId start with 3.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org