Skip to content
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

Merged
merged 22 commits into from
Dec 14, 2021
Merged

Add new method(overload) for CentralDogmaPropertySupplier#createPropertyFile/register #134

merged 22 commits into from
Dec 14, 2021

Conversation

lazmond3
Copy link
Contributor

@lazmond3 lazmond3 commented Dec 2, 2021

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.

  1. First, create a property file with CentralDogmaPropertySupplier#register.
  2. Next, modify the values on CentralDogma.

This extra step is a bit annoying, so we want to let the function accept user-customized settings.

Summary of Changes

  • overload two new methods in CentralDogmaPropertySupplier
    1. register accepts StaticPropertySupplier supplier
      1. register converts supplier to List<Property<?>> for providing values to the next function: createPropertyFile.
    2. createPropertyFile accepts List<Property<?>> properties.

Usage Example

CentralDogmaPropertySupplier.register(
    dogma,
    "sample-project",
    "app-using-decaton",
    "/decaton/settings.json",
    StaticPropertySupplier.of(
        Property.ofStatic(
            ProcessorProperties.CONFIG_PARTITION_CONCURRENCY,
            100
        ),
        Property.ofStatic(
            ProcessorProperties.CONFIG_MAX_PENDING_RECORDS,
            10000
        )
    )
)

@CLAassistant
Copy link

CLAassistant commented Dec 2, 2021

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@kawamuray kawamuray left a 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) {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@lazmond3
Copy link
Contributor Author

Difference from the last time

  • c17b3c7 Changed the return type of CentralDogmaPropertySupplier#defaultProperties() from JsonNode to List<Property<?>>.
  • df825c9 Added tests for CentralDogmaPropertySupplier#register().

@lazmond3 lazmond3 requested a review from kawamuray December 10, 2021 02:36
Copy link
Contributor

@kawamuray kawamuray left a 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,
Copy link
Contributor

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.

Copy link
Contributor Author

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();
Copy link
Contributor

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();
}
...

Copy link
Contributor Author

@lazmond3 lazmond3 Dec 13, 2021

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,
Copy link
Contributor

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.

Copy link
Contributor Author

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() {
Copy link
Contributor

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.

Copy link
Contributor Author

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)));
Copy link
Contributor

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.

Copy link
Contributor Author

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",
Copy link
Contributor

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)

Copy link
Contributor Author

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

Copy link
Contributor

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?

Copy link
Contributor Author

@lazmond3 lazmond3 Dec 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, I failed to update the code exhaustively.
I changed the when parts to use any: 0f2db81 , e852943


CentralDogmaPropertySupplier.register(centralDogma, PROJECT_NAME, REPOSITORY_NAME, FILENAME);

verify(centralDogma, times(1)).normalizeRevision(PROJECT_NAME, REPOSITORY_NAME, Revision.HEAD);
Copy link
Contributor

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?

Copy link
Contributor Author

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),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here too.

Copy link
Contributor Author

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),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here too.

Copy link
Contributor Author

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;
Copy link
Contributor

@kawamuray kawamuray Dec 10, 2021

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

Copy link
Contributor Author

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

@lazmond3 lazmond3 marked this pull request as ready for review December 13, 2021 05:46
@lazmond3 lazmond3 requested a review from kawamuray December 13, 2021 05:46
Copy link
Contributor

@kawamuray kawamuray left a 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.
Copy link
Contributor

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

Copy link
Contributor Author

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() {
Copy link
Contributor

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.

Copy link
Contributor Author

@lazmond3 lazmond3 Dec 13, 2021

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",
Copy link
Contributor

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?

@kawamuray kawamuray added the new feature Add a new feature label Dec 13, 2021
@lazmond3 lazmond3 requested a review from kawamuray December 13, 2021 06:43
Copy link
Contributor

@kawamuray kawamuray left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@kawamuray
Copy link
Contributor

test is failing.

final int settingForMaxPendingRecords = 121212;
final int whenCentralDogmaPushed = 111111;

List<Property<?>> properties = ProcessorProperties
Copy link
Contributor

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());

...

Copy link
Contributor Author

@lazmond3 lazmond3 Dec 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you. I don't need to provide all of the properties if I don't change the value of it.

Changed: providing only customized properties
e6ae753 , bea0861

@lazmond3 lazmond3 requested a review from kawamuray December 14, 2021 04:34
Copy link
Contributor

@kawamuray kawamuray left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, once again :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature Add a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants