BewareMyPower commented on code in PR #20884:
URL: https://github.com/apache/pulsar/pull/20884#discussion_r1425036846


##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiDynamicConfigurationsTest.java:
##########
@@ -69,4 +74,38 @@ public void TestDeleteInvalidDynamicConfiguration() {
             }
         }
     }
+
+    @Test
+    public void testRegisterCustomDynamicConfiguration() throws 
PulsarAdminException {
+        String key = "my-broker-config-key-1";
+        String invalidValue = "invalid-value";
+
+        // register
+        pulsar.getBrokerService().registerCustomDynamicConfiguration(key, 
value -> !value.equals(invalidValue));
+        assertThrows(IllegalArgumentException.class,
+                () -> 
pulsar.getBrokerService().registerCustomDynamicConfiguration(key, null));
+        Map<String, String> allDynamicConfigurations = 
admin.brokers().getAllDynamicConfigurations();
+        assertThat(allDynamicConfigurations).doesNotContainKey(key);
+
+        // update with listener
+        AtomicReference<String> changeValue = new AtomicReference<>(null);
+        Consumer<String> stringConsumer = changeValue::set;
+        pulsar.getBrokerService().registerConfigurationListener(key, 
stringConsumer);
+        String newValue = "my-broker-config-value-1";
+        admin.brokers().updateDynamicConfiguration(key, newValue);
+        Awaitility.await().untilAsserted(() -> {
+            Map<String, String> configurations = 
admin.brokers().getAllDynamicConfigurations();
+            
assertThat(configurations).containsKey(key).containsValue(newValue);

Review Comment:
   ```suggestion
               assertThat(configurations.get(key)).isEqualTo(newValue);
   ```
   
   The existing assertion might pass if `configurations` has "key -> another 
value" and "another key -> newValue", right?



-- 
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-unsubscr...@pulsar.apache.org

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

Reply via email to