-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrating to apache commons configuration 1.10 for parsing ETL jobs c… #851
Conversation
gradle/scripts/dependency.gradle
Outdated
@@ -19,6 +19,8 @@ ext.externalDependency = [ | |||
"jsoup" : "org.jsoup:jsoup:1.8.3", | |||
"commons_io" : "commons-io:commons-io:2.5", | |||
"commons_lang3" : "org.apache.commons:commons-lang3:3.6", | |||
"commons_codec" : "commons-codec:commons-codec:1.10", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed now, used it earlier just in case if i had to encode the reader object.
.add(Pattern.compile("\\$(.+)")) // $ENV_VAR | ||
.add(Pattern.compile("\\$\\{(.+)\\}")) // ${ENV_VAR} | ||
.build(); | ||
private static final List<Pattern> ENV_VAR_PATTERNS = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be able to drop this now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes removed it along with method and test
Properties props = new Properties(); | ||
Path path = createPropertiesFile(propertyStr); | ||
|
||
for (File file : new File(dir).listFiles()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? Don't you already have the path from the previous line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated it now.
81df270
to
c758088
Compare
public void testMultipleLinesSameProperties() throws IOException, ConfigurationException { | ||
String dir = "/tmp/"; | ||
String propertyStr = | ||
"var1=foo\n" + "var1=foo\n" + "var1=foo\n" + "var2=foo\n" + "var2=foo\n" + "var3=foo\n" + "var1=foo\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a few variations to the values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added few tests and enhanced this test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I meant is not to use "foo" for all values
|
||
Assert.assertNotEquals(props, null); | ||
Assert.assertEquals(props.getProperty("var1", ""), "foo,foo,foo,foo"); | ||
Assert.assertTrue(props.getProperty("var2").length() > 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's do simple literal value comparison for var2, var3, & var4.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did literal value comparison now.
@@ -30,23 +31,7 @@ | |||
public class JobsUtilTest { | |||
|
|||
@Test | |||
public void testEnvVarResolution() throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May still want to verify that env vars are resolved properly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point , i have added back earlier code which used to resolve environment variable. In my next PR, i'm going to modify resolving environmental variables using apache commons configuration.
c758088
to
b8e4cab
Compare
5d84d37
to
e00edef
Compare
String propertyStr = | ||
"var1=foo\n" + "var1=foo\n" + "var1=foo\n" + "var2=foo\n" + "var2=foo\n" + "var3=foo\n" + "var1=foo\n" | ||
+ "var4=foo\n"; | ||
String propertyStr1 = "var5=foo,bar,test,test1\n" + "var5=test2\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just append this to propertyStr directly instead of creating another variable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
Assert.assertNotEquals(props, null); | ||
Assert.assertEquals(props.getProperty("var1", ""), "foo,foo,foo,foo"); | ||
Assert.assertEquals(props.getProperty("var2"), "foo,foo"); | ||
Assert.assertEquals(props.getProperty("var3"), props.getProperty("var4")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ssert.assertEquals(props.getProperty("var3"), "foo")
ssert.assertEquals(props.getProperty("var4"), "foo")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it , verified all the literal values now.
public void testMultipleLinesSameProperties() throws IOException, ConfigurationException { | ||
String dir = "/tmp/"; | ||
String propertyStr = | ||
"var1=foo\n" + "var1=foo\n" + "var1=foo\n" + "var2=foo\n" + "var2=foo\n" + "var3=foo\n" + "var1=foo\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I meant is not to use "foo" for all values
e00edef
to
4b9ea10
Compare
Migrating to apache commons configuration 1.10 for Parsing ETL jobs congifuration , It will increase the readability aspect of job configs and also wherehows can leverage apache common configuration features. Below is one of the usage
ex: mysql_db = db1,db2,db3
with this change we can define it as
mysql_db = db1
mysql_db=db2
mysql_db=db3