This is an automated email from the ASF dual-hosted git repository.

technoboy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new 2cb54f3d858 [fix][test] Detects whether an empty object is returned, 
prevent NPE exception (#21585)
2cb54f3d858 is described below

commit 2cb54f3d8585f5c27d20fb6ac958ce29a400c878
Author: PAN <[email protected]>
AuthorDate: Mon Nov 20 16:51:51 2023 +0800

    [fix][test] Detects whether an empty object is returned, prevent NPE 
exception (#21585)
---
 .../client/impl/PartitionedProducerImplTest.java   | 41 ++++++++++++++++++----
 1 file changed, 35 insertions(+), 6 deletions(-)

diff --git 
a/pulsar-client/src/test/java/org/apache/pulsar/client/impl/PartitionedProducerImplTest.java
 
b/pulsar-client/src/test/java/org/apache/pulsar/client/impl/PartitionedProducerImplTest.java
index b38b17a731b..b96f6a344a3 100644
--- 
a/pulsar-client/src/test/java/org/apache/pulsar/client/impl/PartitionedProducerImplTest.java
+++ 
b/pulsar-client/src/test/java/org/apache/pulsar/client/impl/PartitionedProducerImplTest.java
@@ -40,13 +40,10 @@ import java.util.Optional;
 import java.util.Set;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
+
 import lombok.Cleanup;
-import org.apache.pulsar.client.api.Message;
-import org.apache.pulsar.client.api.MessageRouter;
-import org.apache.pulsar.client.api.MessageRoutingMode;
-import org.apache.pulsar.client.api.Producer;
-import org.apache.pulsar.client.api.Schema;
-import org.apache.pulsar.client.api.TopicMetadata;
+import org.apache.pulsar.client.api.*;
 import org.apache.pulsar.client.impl.conf.ClientConfigurationData;
 import org.apache.pulsar.client.impl.conf.ProducerConfigurationData;
 import 
org.apache.pulsar.client.impl.customroute.PartialRoundRobinMessageRouterImpl;
@@ -273,4 +270,36 @@ public class PartitionedProducerImplTest {
         assertEquals(producerImpl.getNumOfPartitions(), 0);
     }
 
+
+    @Test
+    public void testOnTopicsExtended() throws Exception {
+        String topicName = "test-on-topics-extended";
+        ClientConfigurationData conf = new ClientConfigurationData();
+        conf.setServiceUrl("pulsar://localhost:6650");
+        conf.setStatsIntervalSeconds(100);
+        ThreadFactory threadFactory = new 
DefaultThreadFactory("client-test-stats", Thread.currentThread().isDaemon());
+        @Cleanup("shutdownGracefully")
+        EventLoopGroup eventLoopGroup = 
EventLoopUtil.newEventLoopGroup(conf.getNumIoThreads(), false, threadFactory);
+
+        @Cleanup
+        PulsarClientImpl clientImpl = new PulsarClientImpl(conf, 
eventLoopGroup);
+
+        ProducerConfigurationData producerConfData = new 
ProducerConfigurationData();
+        
producerConfData.setMessageRoutingMode(MessageRoutingMode.CustomPartition);
+        producerConfData.setCustomMessageRouter(new CustomMessageRouter());
+        producerConfData.setAutoUpdatePartitionsIntervalSeconds(1, 
TimeUnit.MILLISECONDS);
+
+        PartitionedProducerImpl impl = new PartitionedProducerImpl(
+                clientImpl, topicName, producerConfData, 1, null, null, null);
+
+        impl.setState(HandlerState.State.Ready);
+        Thread.sleep(1000);
+        CompletableFuture future = impl.getPartitionsAutoUpdateFuture();
+
+        // When null is returned in method thenCompose we will encounter an 
NPE exception.
+        // Because the returned value will be applied to the next stage.
+        // We use future instead of null as the return value.
+        assertNotNull(future);
+    }
+
 }

Reply via email to