Skip to content

Commit

Permalink
fix parentChildEmptyNullConfig
Browse files Browse the repository at this point in the history
fix

add test

fix
  • Loading branch information
Yingjian Wu committed Oct 30, 2024
1 parent 1aada77 commit a9d99d4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,9 @@ public ParentChildRelationshipProperties(@Nullable final Environment env) {
* @param configStr configString
*/
public void setMaxAllowPerTablePerRelType(@Nullable final String configStr) {
if (configStr == null || configStr.isEmpty()) {
return;
}
try {
this.maxAllowPerTablePerRelType = parseNestedConfigString(configStr);
this.maxAllowPerTablePerRelType = configStr == null || configStr.isEmpty()
? new HashMap<>() : parseNestedConfigString(configStr);
} catch (Exception e) {
log.error("Fail to apply configStr = {} for maxAllowPerTablePerRelType", configStr, e);
}
Expand All @@ -74,11 +72,9 @@ public void setMaxAllowPerTablePerRelType(@Nullable final String configStr) {
* @param configStr configString
*/
public void setMaxAllowPerDBPerRelType(@Nullable final String configStr) {
if (configStr == null || configStr.isEmpty()) {
return;
}
try {
this.maxAllowPerDBPerRelType = parseNestedConfigString(configStr);
this.maxAllowPerDBPerRelType = configStr == null || configStr.isEmpty()
? new HashMap<>() : parseNestedConfigString(configStr);
} catch (Exception e) {
log.error("Fail to apply configStr = {} for maxCloneAllowPerDBPerRelType", configStr);
}
Expand All @@ -89,12 +85,10 @@ public void setMaxAllowPerDBPerRelType(@Nullable final String configStr) {
* @param configStr configString
*/
public void setDefaultMaxAllowPerRelType(@Nullable final String configStr) {
if (configStr == null || configStr.isEmpty()) {
return;
}
try {
this.defaultMaxAllowPerRelType =
Arrays.stream(configStr.split(";"))
this.defaultMaxAllowPerRelType = configStr == null || configStr.isEmpty()
? new HashMap<>()
: Arrays.stream(configStr.split(";"))
.map(entry -> entry.split(","))
.collect(Collectors.toMap(
parts -> parts[0],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -618,4 +618,38 @@ class ParentChildRelMetadataServiceSpec extends Specification{
1 | "CLONE,5" | "CLONE,test,3;OTHER,other,2"| "CLONE,testhive/test/parent,2" | 2
1 | "CLONE,5;Other,3" | "CLONE,test,3;CLONE,other,2"| "CLONE,testhive/test/parent,2;CLONE,testhive/test/other,2" | 2
}

def "test empty/null input string for config"() {
given:
def parentChildProps = new ParentChildRelationshipProperties(null)

when: "Setting properties to non empty string"
parentChildProps.setDefaultMaxAllowPerRelType("CLONE,5;Other,3")
parentChildProps.setMaxAllowPerDBPerRelType("CLONE,test,3;CLONE,other,2")
parentChildProps.setMaxAllowPerTablePerRelType("CLONE,testhive/test/parent,2;CLONE,testhive/test/other,2")

then:
assert parentChildProps.getDefaultMaxAllowPerRelType().size() == 2
assert parentChildProps.getMaxAllowPerDBPerRelType().size() == 2
assert parentChildProps.getMaxAllowPerTablePerRelType().size() == 2

when: "Setting properties to empty or null based on the isEmpty flag"
if (isEmpty) {
parentChildProps.setDefaultMaxAllowPerRelType("")
parentChildProps.setMaxAllowPerDBPerRelType("")
parentChildProps.setMaxAllowPerTablePerRelType("")
} else {
parentChildProps.setDefaultMaxAllowPerRelType(null)
parentChildProps.setMaxAllowPerDBPerRelType(null)
parentChildProps.setMaxAllowPerTablePerRelType(null)
}

then: "The properties should be empty"
assert parentChildProps.getDefaultMaxAllowPerRelType().isEmpty()
assert parentChildProps.getMaxAllowPerDBPerRelType().isEmpty()
assert parentChildProps.getMaxAllowPerTablePerRelType().isEmpty()

where:
isEmpty << [true, false]
}
}

0 comments on commit a9d99d4

Please sign in to comment.