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 2022/06/20 10:43:32 UTC

[GitHub] [pulsar] Demogorgon314 commented on a diff in pull request #16142: [fix][txn] Fix NPE when ack message with transaction at cnx = null

Demogorgon314 commented on code in PR #16142:
URL: https://github.com/apache/pulsar/pull/16142#discussion_r901523556


##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/transaction/TransactionTest.java:
##########
@@ -997,6 +1000,48 @@ public void testConsistencyOfTransactionStatsAtEndTxn() throws Exception {
         transaction.commit().get();
     }
 
+    @Test
+    public void testGetConnectExceptionForAckMsgWhenCnxIsNull() throws Exception {
+        String topic = NAMESPACE1 + "/testGetConnectExceptionForAckMsgWhenCnxIsNull";
+        @Cleanup
+        Producer<byte[]> producer = pulsarClient
+                .newProducer(Schema.BYTES)
+                .topic(topic)
+                .sendTimeout(0, TimeUnit.SECONDS)
+                .create();
+
+        @Cleanup
+        Consumer<byte[]> consumer = pulsarClient
+                .newConsumer()
+                .topic(topic)
+                .subscriptionName("sub")
+                .subscribe();
+
+        for (int i = 0; i < 10; i++) {
+            producer.newMessage().value(Bytes.toBytes(i)).send();
+        }
+        Method method = ConsumerImpl.class.getDeclaredMethod("cnx");
+        method.setAccessible(true);
+        ClientCnx cnx = (ClientCnx) method.invoke(consumer);
+        Method method1 = ConsumerImpl.class.getDeclaredMethod("connectionClosed", ClientCnx.class);
+        method1.setAccessible(true);
+        method1.invoke(consumer, cnx);

Review Comment:
   ```suggestion
           ClientCnx cnx = Whitebox.invokeMethod(consumer, "cnx");
           Whitebox.invokeMethod(consumer, "connectionClosed", cnx);
   ```
   We can use `Whitebox` to simplify the reflect operation.



-- 
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: commits-unsubscribe@pulsar.apache.org

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