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

[#70] Implement a helper Map implementation for ConfigSources to use #72

Merged
merged 1 commit into from
Dec 18, 2018

Conversation

dmlloyd
Copy link
Contributor

@dmlloyd dmlloyd commented Dec 15, 2018

No description provided.

@dmlloyd
Copy link
Contributor Author

dmlloyd commented Dec 15, 2018

Added tests.

@@ -69,6 +69,50 @@
<forkMode>once</forkMode>
</configuration>
</plugin>
<plugin>
Copy link
Contributor

Choose a reason for hiding this comment

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

Should something like this be moved into smallrye-parent so all projects could use it?

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'd be okay with that I guess.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But that means there'd have to be a release and so forth.

Copy link
Contributor

Choose a reason for hiding this comment

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

True, but pulling the trigger is pretty easy.

Other than needing a release of parent, any reason not to?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, sounds fine. Is that something you can do?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure

Copy link
Contributor

@jmesnil jmesnil left a comment

Choose a reason for hiding this comment

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

I like this feature and it is genuinely useful.
However, I have some concern with the mutability of the underlying Map leaking to the config source.

@dmlloyd Do your use cases require to modify the properties collections or would it be enough to provide an Unmodifiable Map implementation?

* The implementation attempts to make no assumptions about the efficiency of the backing implementation and
* prefers the most direct access possible.
* <p>
* Some mutate operations are supported (specifically removals), where they can be performed on the backing key set, if
Copy link
Contributor

Choose a reason for hiding this comment

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

that's not specified in the spec (although it should be) but my interpretation of getPropertyNames() is that it should return an immutable set of names.
In general, ConfigSource should not be used to modify/update configuration. If some of these methods provide ambiguity about it, it should be properly specified in the spec or in the API.

I'll open issues in microprofile-config to clarify these use cases

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

there is also eclipse/microprofile-config#333 where it is discussed

public String remove(final Object key) {
final String value = get(key);
//noinspection SuspiciousMethodCalls - it's OK in this case
return delegate.getPropertyNames().remove(key) ? value : null;
Copy link
Contributor

Choose a reason for hiding this comment

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

remove could throw a UnsupportedOperationException if the list is unmodifiable

@dmlloyd
Copy link
Contributor Author

dmlloyd commented Dec 17, 2018

The idea was to "punt" on mutability. If the underlying config source is mutable then the map is; if it isn't, then the map isn't. This way it doesn't impose any policy one way or the other.

I can make it assume full immutability though if you want me to.

@jmesnil
Copy link
Contributor

jmesnil commented Dec 17, 2018

@dmlloyd I would prefer full immutability (the goal being then to propose this improvement to microprofile-config to update its API wrt getProperties()/getPropertyNames() ).

I don't like that the application could change the config sources.
First, the app does not "own" the config source, it may not be the only one that uses the config sources (eg config maps, DBs).
Then the config source itself may not be the same one that provides the properties depending on the stage (e.g. on dev, the prop would come from embedded property files, on prod, from a config map).

Having mutability raise expectation that the application knows the config source that always provides the property which is the opposite of the design behind the Config interface.

The whole microprofile-config API is really only about viewing the configuration. The update/modification of the configuraiton is out of scope of the specification.
However, this is not clearly enough stated in the spec and the use of mutable interface such as Properties leaves open the possibility to have mutable ConfigSources.

@dmlloyd
Copy link
Contributor Author

dmlloyd commented Dec 17, 2018

OK I'll push an immutable version.

@dmlloyd dmlloyd force-pushed the map branch 2 times, most recently from 284d707 to ab2a7f9 Compare December 17, 2018 15:22
@dmlloyd
Copy link
Contributor Author

dmlloyd commented Dec 17, 2018

OK pushed (also remembered to update the tests ;) )

@dmlloyd
Copy link
Contributor Author

dmlloyd commented Dec 17, 2018

I think CI might have been confused by my rapid pushes. Can we trigger a retest?

@dmlloyd
Copy link
Contributor Author

dmlloyd commented Dec 17, 2018

I guess I'll just re-amend and push a new commit ID

@dmlloyd
Copy link
Contributor Author

dmlloyd commented Dec 17, 2018

Hmm

@dmlloyd
Copy link
Contributor Author

dmlloyd commented Dec 17, 2018

Ah it's the JavaDoc issue. We need Ken's parent update.

@kenfinnigan
Copy link
Contributor

v2 has been pushed to Sonatype, basically waiting for percolation to Central.

@kenfinnigan
Copy link
Contributor

2 is now in Central

@dmlloyd
Copy link
Contributor Author

dmlloyd commented Dec 17, 2018

Thanks Ken, I'll update the PR.

jmesnil
jmesnil previously approved these changes Dec 18, 2018
@jmesnil
Copy link
Contributor

jmesnil commented Dec 18, 2018

@dmlloyd could you please rebase and I'll merge it?

@dmlloyd
Copy link
Contributor Author

dmlloyd commented Dec 18, 2018

Done.

@jmesnil jmesnil merged commit 0ed86a1 into smallrye:master Dec 18, 2018
@dmlloyd dmlloyd deleted the map branch December 18, 2018 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants