|
@@ -19,6 +19,7 @@
|
|
|
package org.apache.zookeeper.server.util;
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
+import static org.junit.jupiter.api.Assertions.assertNull;
|
|
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
|
import org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException;
|
|
|
import org.junit.jupiter.api.Test;
|
|
@@ -74,4 +75,45 @@ public class ConfigUtilsTest {
|
|
|
assertEquals(nsa.length, 1);
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testGetPropertyBackwardCompatibleWay() throws ConfigException {
|
|
|
+ String newProp = "zookeeper.prop.x.y.z";
|
|
|
+ String oldProp = "prop.x.y.z";
|
|
|
+
|
|
|
+ // Null as both properties are not set
|
|
|
+ String result = ConfigUtils.getPropertyBackwardCompatibleWay(newProp);
|
|
|
+ assertNull(result);
|
|
|
+
|
|
|
+ // Return old property value when only old property is set
|
|
|
+ String oldPropValue = "oldPropertyValue";
|
|
|
+ System.setProperty(oldProp, oldPropValue);
|
|
|
+ result = ConfigUtils.getPropertyBackwardCompatibleWay(newProp);
|
|
|
+ assertEquals(oldPropValue, result);
|
|
|
+
|
|
|
+ // Return new property value when both properties are set
|
|
|
+ String newPropValue = "newPropertyValue";
|
|
|
+ System.setProperty(newProp, newPropValue);
|
|
|
+ result = ConfigUtils.getPropertyBackwardCompatibleWay(newProp);
|
|
|
+ assertEquals(newPropValue, result);
|
|
|
+
|
|
|
+ // cleanUp
|
|
|
+ clearProp(newProp, oldProp);
|
|
|
+
|
|
|
+ // Return trimmed value
|
|
|
+ System.setProperty(oldProp, oldPropValue + " ");
|
|
|
+ result = ConfigUtils.getPropertyBackwardCompatibleWay(newProp);
|
|
|
+ assertEquals(oldPropValue, result);
|
|
|
+
|
|
|
+ System.setProperty(newProp, " " + newPropValue);
|
|
|
+ result = ConfigUtils.getPropertyBackwardCompatibleWay(newProp);
|
|
|
+ assertEquals(newPropValue, result);
|
|
|
+
|
|
|
+ // cleanUp
|
|
|
+ clearProp(newProp, oldProp);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void clearProp(String newProp, String oldProp) {
|
|
|
+ System.clearProperty(newProp);
|
|
|
+ System.clearProperty(oldProp);
|
|
|
+ }
|
|
|
}
|