-
Notifications
You must be signed in to change notification settings - Fork 4.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
make the seed for YamlSeedConfigPersistence configurable #6409
Conversation
.build(); | ||
} | ||
|
||
public static void initialize(final Class<?> seedDefinitionsResourceClass) { |
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 understand why you need to do that but this complex object lifecycle has some code smell.
Why is the YamlSeedConfigPersistence a singleton? Are we ever using it without injecting?
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.
Now that this class can be constructed differently, I think it should not be a singleton any more.
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.
cool. thanks. this was my intuition too.
@@ -56,6 +56,7 @@ | |||
|
|||
@BeforeAll | |||
public static void dbSetup() { | |||
YamlSeedConfigPersistence.initialize(YamlSeedConfigPersistence.DEFAULT_SEED_DEFINITION_RESOURCE_CLASS); |
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.
Can be we have some smiple helper method to construct this class, like YamlSeedConfigPersistence.getDefault()
, which automatically use the default resource class? Otherwise people won't remember which class to use.
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.
This initialize
method no longer exists. This line can be deleted. Otherwise code cannot compile.
YamlSeedConfigPersistence.initialize(YamlSeedConfigPersistence.DEFAULT_SEED_DEFINITION_RESOURCE_CLASS); |
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 think it's better to ditch the singleton pattern and combine the initialize
and get
method into the following methods:
public YamlSeedConfigPersistence(final Class<?> seedDefinitionsResourceClass) {
this.allSeedConfigs = ImmutableMap.<SeedType, Map<String, JsonNode>>builder()
.put(SeedType.STANDARD_SOURCE_DEFINITION, getConfigs(seedDefinitionsResourceClass, SeedType.STANDARD_SOURCE_DEFINITION))
.put(SeedType.STANDARD_DESTINATION_DEFINITION, getConfigs(seedDefinitionsResourceClass, SeedType.STANDARD_DESTINATION_DEFINITION))
.build();
}
public static YamlSeedConfigPersistence getDefault() {
return new YamlSeedConfigPersistence(DEFAULT_SEED_DEFINITION_RESOURCE_CLASS);
}
public static YamlSeedConfigPersistence get(final Class<?> seedDefinitionsResourceClass) {
return new YamlSeedConfigPersistence(seedDefinitionsResourceClass);
}
Static class variables should preferrably be final
.
@@ -100,23 +101,23 @@ public void testUpdateConfigsInNonEmptyDatabase() throws Exception { | |||
@DisplayName("When a connector is in use, its definition should not be updated") | |||
public void testNoUpdateForUsedConnector() throws Exception { | |||
// the seed has a newer version of s3 destination and github source | |||
StandardDestinationDefinition destinationS3V2 = YamlSeedConfigPersistence.get() | |||
final StandardDestinationDefinition destinationS3V2 = YamlSeedConfigPersistence.get() |
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.
This test shows a good example why the static class variable should not be modified. It is very confusing that we need to call initialize
in the setup
method first before calling the get
here. No one will remember to do this until they get the exception message.
thanks for the review. I agree with both of you. Updated PR to reflect it. @tuliren ready for another review when you are. |
@@ -56,6 +56,7 @@ | |||
|
|||
@BeforeAll | |||
public static void dbSetup() { | |||
YamlSeedConfigPersistence.initialize(YamlSeedConfigPersistence.DEFAULT_SEED_DEFINITION_RESOURCE_CLASS); |
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.
This initialize
method no longer exists. This line can be deleted. Otherwise code cannot compile.
YamlSeedConfigPersistence.initialize(YamlSeedConfigPersistence.DEFAULT_SEED_DEFINITION_RESOURCE_CLASS); |
Relates to #6334
What
Recommended reading order
YamlSeedConfigPersistence.java