Copilot commented on code in PR #24893:
URL: https://github.com/apache/pulsar/pull/24893#discussion_r2480398530


##########
pulsar-client-admin/src/test/java/org/apache/pulsar/client/admin/internal/PulsarAdminBuilderImplTest.java:
##########
@@ -188,6 +195,96 @@ public void testClientDescription() throws 
PulsarClientException {
                 
PulsarAdmin.builder().serviceHttpUrl("http://localhost:8080";).description("forked").build();
     }
 
+    @Test
+    public void testClientBuildWithSharedResources() throws 
PulsarClientException {
+        PulsarClientSharedResources sharedResources = 
PulsarClientSharedResources.builder()
+                .configureEventLoop(eventLoopGroupConfig -> {
+                    eventLoopGroupConfig
+                            .name("testEventLoop")
+                            .numberOfThreads(20);
+                })
+                .configureDnsResolver(dnsResolverConfig -> {
+                    dnsResolverConfig.localAddress(new InetSocketAddress(0));
+                })
+                .configureTimer(timerConfig -> {
+                    timerConfig.name("testTimer").tickDuration(100, 
TimeUnit.MILLISECONDS);
+                })
+                .build();
+        // create two adminClients and check if they share the same event loop 
group and netty timer
+        @Cleanup
+        PulsarAdminImpl pulsarAdminImpl1 =
+                (PulsarAdminImpl) PulsarAdmin.builder()
+                        .serviceHttpUrl("http://localhost:8080";)
+                        .sharedResources(sharedResources)
+                        .build();
+        @Cleanup
+        PulsarAdminImpl pulsarAdminImpl2 =
+                (PulsarAdminImpl) PulsarAdmin.builder()
+                        .serviceHttpUrl("http://localhost:8080";)
+                        .sharedResources(sharedResources)
+                        .build();
+
+        EventLoopGroup eventLoopGroup1 =
+                
pulsarAdminImpl1.getAsyncHttpConnector().getHttpClient().getConfig().getEventLoopGroup();
+        EventLoopGroup eventLoopGroup2 =
+                
pulsarAdminImpl2.getAsyncHttpConnector().getHttpClient().getConfig().getEventLoopGroup();
+        Timer nettyTimer1 = 
pulsarAdminImpl1.getAsyncHttpConnector().getHttpClient().getConfig().getNettyTimer();
+        Timer nettyTimer2 = 
pulsarAdminImpl2.getAsyncHttpConnector().getHttpClient().getConfig().getNettyTimer();
+        boolean b1 = eventLoopGroup1 == eventLoopGroup2;
+        boolean b2 = nettyTimer1 == nettyTimer2;
+        assertThat(b1 && b2).isTrue();

Review Comment:
   Intermediate boolean variables `b1` and `b2` are unnecessary. Simplify to 
`assertThat(eventLoopGroup1).isSameAs(eventLoopGroup2)` and 
`assertThat(nettyTimer1).isSameAs(nettyTimer2)` for better readability and 
clearer assertion messages on failure.
   ```suggestion
           assertThat(eventLoopGroup1).isSameAs(eventLoopGroup2);
           assertThat(nettyTimer1).isSameAs(nettyTimer2);
   ```



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

Reply via email to