-
Notifications
You must be signed in to change notification settings - Fork 51
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
Add new method(overload) for CentralDogmaPropertySupplier#createPropertyFile/register #134
Add new method(overload) for CentralDogmaPropertySupplier#createPropertyFile/register #134
Conversation
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.
Thanks for working on this! Left a minor comment WRT interface, but overall looks good 👍
@@ -145,19 +149,43 @@ public static CentralDogmaPropertySupplier register(CentralDogma centralDogma, S | |||
return new CentralDogmaPropertySupplier(centralDogma, project, repository, filename); | |||
} | |||
|
|||
public static CentralDogmaPropertySupplier register(CentralDogma centralDogma, String project, | |||
String repository, String filename, | |||
StaticPropertySupplier supplier) { |
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 in most cases people would use StaticPropertySupplier
anyway, but we don't necessarily restrict this to be it, and just PropertySupplier
(interface) is fine and more flexible?
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.
3efe319
I agree with you, and changed the argument type of supplier
from StaticPropertySupplier
to PropertySupplier
.
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.
Thanks for your PR! Left some comments.
@@ -145,19 +148,43 @@ public static CentralDogmaPropertySupplier register(CentralDogma centralDogma, S | |||
return new CentralDogmaPropertySupplier(centralDogma, project, repository, filename); | |||
} | |||
|
|||
public static CentralDogmaPropertySupplier register(CentralDogma centralDogma, String project, |
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.
As its a public interface, please give it a javadoc like another overload of register
.
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 added a javadoc for the new added register
method: e8c311b
PropertySupplier supplier) { | ||
List<Property<?>> properties = defaultProperties().stream().map(defaultProperty -> { | ||
if (supplier.getProperty(defaultProperty.definition()).isPresent()) { | ||
return supplier.getProperty(defaultProperty.definition()).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.
As a call of getProperty
may involves I/O with external systems (like centraldogma), it is better to keep count of calling it as minimum as possible.
so let's do it like:
prop = supplier.getProperty(...);
if (prop.ifPresent()) {
return prop.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.
I changed the code to use a temporary variable for keeping the value in external systems. 8d38efe
createPropertyFile(centralDogma, project, repository, filename, properties); | ||
return new CentralDogmaPropertySupplier(centralDogma, project, repository, filename); | ||
} | ||
|
||
private static void createPropertyFile(CentralDogma centralDogma, String project, |
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 this overload no longer meaningful. Let's just use the below signature and pass default properties directly.
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 deleted this original method createPropertyFile
(no longer used), since a new method which has more arguments was added. 6b49b94
} | ||
|
||
// visible for testing | ||
static List<Property<?>> defaultProperties() { |
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 this functionality can be required by various supplier implementations? Maybe it's worth putting this method in ProcessorProperties
rather than here privately.
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 moved this method defaultProperties
, which returns List<Property<?>>
, to ProcessorProperties
. 03ef312
.forEach(definition -> properties.set(definition.name(), | ||
objectMapper.valueToTree(definition.defaultValue())) | ||
); | ||
.forEach(definition -> properties.add(new DynamicProperty(definition))); |
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.
There's no point to use DynamicProperty
here. It's for modifiable property instance, so let's use Property.ofStatic()
instead.
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.
); | ||
when(centralDogma.push( | ||
PROJECT_NAME, REPOSITORY_NAME, Revision.HEAD, | ||
String.format("[CentralDogmaPropertySupplier] Property file created: %s", |
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 don't think we need to match this argument and it will just make shit test fragile for tiny change on commit message which is mostly pointless. So let's use type matcher here, like any(String.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 changed the code to use mockito any(String.class)
, since a central dogma's commit message is not target of test for this PR's functionality.
f2ee11d
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.
Hmm, looks like this part and one in below hasn't changed yet?
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.
|
||
CentralDogmaPropertySupplier.register(centralDogma, PROJECT_NAME, REPOSITORY_NAME, FILENAME); | ||
|
||
verify(centralDogma, times(1)).normalizeRevision(PROJECT_NAME, REPOSITORY_NAME, Revision.HEAD); |
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 what we wanna test here is, if calling register()
actually tries to create an expected file with expected content, so the only check against push()
is meaningful to be testing subject?
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 deleted the verifying lines: 61cea29
|
||
when(centralDogma.push( | ||
PROJECT_NAME, REPOSITORY_NAME, Revision.HEAD, | ||
String.format("[CentralDogmaPropertySupplier] Property file created: %s", FILENAME), |
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.
here too.
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.
verify(centralDogma, times(1)).listFiles(PROJECT_NAME, REPOSITORY_NAME, Revision.HEAD, FILENAME); | ||
verify(centralDogma, times(1)) | ||
.push(PROJECT_NAME, REPOSITORY_NAME, Revision.HEAD, | ||
String.format("[CentralDogmaPropertySupplier] Property file created: %s", FILENAME), |
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.
here too.
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.
|
||
@Test | ||
public void testRegisterWithCustomizedSettings() { | ||
final Integer settingForPartitionConcurrency = 188; |
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 stick with primitive types when there's no point to use a boxed type. int
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 changed the variable type to int
from Integer
. 382f706
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.
Thanks for follow-up. Just few more things.
* @param project the project name where the properties are placed. | ||
* @param repository the repository name where the properties are placed. | ||
* @param filename the name of the file containing properties as top-level fields. | ||
* @param supplier user-customized settings for kafka-consumer. |
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.
These properties are of decaton, not kafka-consumer. So let's reword it like: a {@link PropertySupplier} which provides set of properties that wants to have a custom initial value
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 reworded the javadoc for supplier:
a {@link PropertySupplier} which provides a set of properties with customized initial values
2e70198
@@ -218,4 +219,10 @@ | |||
public ProcessorProperties(Map<PropertyDefinition<?>, Property<?>> properties) { | |||
super(properties); | |||
} | |||
|
|||
public static List<Property<?>> defaultProperties() { |
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.
Please give it even a short javadoc since its also a public interface.
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 added a short description for this method: f82bae3
); | ||
when(centralDogma.push( | ||
PROJECT_NAME, REPOSITORY_NAME, Revision.HEAD, | ||
String.format("[CentralDogmaPropertySupplier] Property file created: %s", |
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.
Hmm, looks like this part and one in below hasn't changed yet?
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.
LGTM, thanks!
test is failing. |
…mizedSettings in CentralDogmaPropertySupplierTest
…-value-arg-for-register
final int settingForMaxPendingRecords = 121212; | ||
final int whenCentralDogmaPushed = 111111; | ||
|
||
List<Property<?>> properties = ProcessorProperties |
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 don't see why we need full list of proeprties here, not only custom ones but also these with defaults?
Since the spec of newly added register
API is such that "Creates a node with default properties, but you can specify some prop's initial value optionally", the realistic usage will look like:
CentralDogmaPropertySupplier.register(..., StaticPropertySupplier.of(
Property.ofStatic(...)
));
so what we should test here is passing just partial list of properties that we want to customize? such as:
@Test
public void testRegisterWithCustomizedSettings() {
final int settingForPartitionConcurrency = 188;
final int settingForMaxPendingRecords = 121212;
final int whenCentralDogmaPushed = 111111;
final PropertySupplier supplier = StaticPropertySupplier.of(
Property.ofStatic(ProcessorProperties.CONFIG_PARTITION_CONCURRENCY,
settingForPartitionConcurrency),
Property.ofStatic(ProcessorProperties.CONFIG_MAX_PENDING_RECORDS,
settingForMaxPendingRecords)
);
final List<Property<?>> listProperties = ProcessorProperties
.defaultProperties()
.stream()
.map(defaultProperty -> {
Optional<? extends Property<?>> prop = supplier.getProperty(defaultProperty.definition());
if (prop.isPresent()) {
return prop.get();
} else {
return defaultProperty;
}
}).collect(Collectors.toList());
...
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.
…n public class CentralDogmaPropertySupplierTest
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.
LGTM, once again :)
Relevant Issue
#22
Motivation
CentralDogmaPropertySupplier#register
is used to create a property file with default settings.The existing implementation of the function does not accept user-customized arguments.
If you know the appropriate values at the beginning and want to customize your settings, you need to take extra steps.
CentralDogmaPropertySupplier#register
.This extra step is a bit annoying, so we want to let the function accept user-customized settings.
Summary of Changes
CentralDogmaPropertySupplier
register
acceptsStaticPropertySupplier supplier
register
convertssupplier
toList<Property<?>>
for providing values to the next function:createPropertyFile
.createPropertyFile
acceptsList<Property<?>> properties
.Usage Example