Skip to content

Commit

Permalink
[controller] Ensure empty string from config doesn't result in an arr…
Browse files Browse the repository at this point in the history
…ay of an empty string (#1202)
  • Loading branch information
kvargha authored Sep 27, 2024
1 parent 04aeaeb commit c694d96
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ public List<String> getList(String key, List<String> defaultValue) {
}

String value = get(key);

String[] pieces = value.split("\\s*,\\s*");
return Arrays.asList(pieces);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,27 @@ public void testClusterResourceInstanceTag() {
}
}

@Test(timeOut = 60 * Time.MS_PER_SECOND)
public void testClusterResourceEmptyInstanceTag() {
try (VeniceClusterWrapper venice = ServiceFactory.getVeniceCluster(0, 0, 0, 1);
HelixAsAServiceWrapper helixAsAServiceWrapper = startAndWaitForHAASToBeAvailable(venice.getZk().getAddress())) {
String instanceTag = "";
String controllerClusterName = "venice-controllers";

Properties clusterProperties = (Properties) enableControllerAndStorageClusterHAASProperties.clone();
clusterProperties.put(ConfigKeys.CONTROLLER_RESOURCE_INSTANCE_GROUP_TAG, instanceTag);
clusterProperties.put(ConfigKeys.CONTROLLER_INSTANCE_TAG_LIST, instanceTag);

VeniceControllerWrapper controllerWrapper = venice.addVeniceController(clusterProperties);

HelixAdmin helixAdmin = controllerWrapper.getVeniceHelixAdmin().getHelixAdmin();
List<String> resources = helixAdmin.getResourcesInClusterWithTag(controllerClusterName, instanceTag);
assertEquals(resources.size(), 0);
List<String> instances = helixAdmin.getInstancesInClusterWithTag(controllerClusterName, instanceTag);
assertEquals(instances.size(), 0);
}
}

@Test(timeOut = 60 * Time.MS_PER_SECOND)
public void testStartHAASHelixControllerAsControllerClusterLeader() {
try (VeniceClusterWrapper venice = ServiceFactory.getVeniceCluster(0, 0, 0, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,13 @@ public VeniceControllerClusterConfig(VeniceProperties props) {
this.adminCheckReadMethodForKafka = props.getBoolean(ADMIN_CHECK_READ_METHOD_FOR_KAFKA, true);
this.controllerClusterName = props.getString(CONTROLLER_CLUSTER, "venice-controllers");
this.controllerResourceInstanceGroupTag = props.getString(CONTROLLER_RESOURCE_INSTANCE_GROUP_TAG, "");
this.controllerInstanceTagList = props.getList(CONTROLLER_INSTANCE_TAG_LIST, Collections.emptyList());

if (props.getString(CONTROLLER_INSTANCE_TAG_LIST, "").isEmpty()) {
this.controllerInstanceTagList = Collections.emptyList();
} else {
this.controllerInstanceTagList = props.getList(CONTROLLER_INSTANCE_TAG_LIST, Collections.emptyList());
}

this.controllerClusterReplica = props.getInt(CONTROLLER_CLUSTER_REPLICA, 3);
this.controllerClusterZkAddress = props.getString(CONTROLLER_CLUSTER_ZK_ADDRESSS, getZkAddress());
this.parent = props.getBoolean(CONTROLLER_PARENT_MODE, false);
Expand Down

0 comments on commit c694d96

Please sign in to comment.