gnodet-bot commented on code in PR #30983:
URL: https://github.com/apache/camel/pull/30983#discussion_r4720612366


##########
components/camel-azure/camel-azure-iothub/src/test/java/org/apache/camel/component/azure/iothub/client/DeviceClientPoolTest.java:
##########
@@ -168,6 +168,26 @@ void testRemoveClosesClient() throws Exception {
         verify(client, times(1)).close();
     }
 
+    @Test
+    void testHttpsClientIsKeptApartAndRemovedByDeviceId() throws Exception {
+        DeviceClient https = mock(DeviceClient.class);
+        DeviceClient mqtt = mock(DeviceClient.class);
+        DeviceClientPool pool = new DeviceClientPool(Duration.ofMinutes(5), 
Duration.ofSeconds(30));
+        pool.setDeviceClientFactory((cs, protocol) -> protocol == 
IotHubClientProtocol.HTTPS ? https : mqtt);
+
+        assertSame(https, pool.getOrCreate("d", CS, 
IotHubClientProtocol.HTTPS));
+        assertSame(mqtt, pool.getOrCreate("d", CS, IotHubClientProtocol.MQTT));
+        assertSame(mqtt, pool.getOrCreate("d", CS, 
IotHubClientProtocol.AMQPS));
+        assertEquals(2, pool.getActiveClientCount());
+
+        pool.remove("d");
+        pool.remove("d");

Review Comment:
   `remove(String deviceId)` has an early `return` on the first matching entry 
it finds (line 347 in the loop body), so a device with both an HTTPS and an 
MQTT client needs two calls to remove both — hence the two `pool.remove("d")` 
calls here.
   
   The production path (`remove(deviceId, connectionString)`) correctly removes 
both keys in one shot via `removePoolEntry(poolKey)` + `removePoolEntry(poolKey 
+ HTTPS_KEY_SUFFIX)`, so this is not a production bug. But if a third key 
variant is ever added, callers of this test-only overload will need to know the 
internal count.
   
   Consider dropping the `return` from the loop in `remove(String deviceId)` so 
it removes all matching entries in one pass, which would let this test call 
`pool.remove("d")` once.



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