Discussion:
[configuration] Reloading properties does not work as expected
(too old to reply)
Paul Wellner Bou
2018-01-30 09:18:15 UTC
Permalink
Good morning,

i am trying to implement a reloadable property using commons-reloading2
(2.2), without success. I tried to follow the (outdated) examples on
https://commons.apache.org/proper/commons-configuration/userguide/howto_reloading.html#Reloading_File-based_Configurations
(both of them).

Now I created a unit test against this API which I would expect it to pass,
but it doesn't:
https://gist.github.com/paulwellnerbou/dfed371d67e2f19a699b248ebf5c62d7

Any idea what I am doing wrong?

Thank you and kind regards
Paul.
Oliver Heger
2018-01-31 21:11:45 UTC
Permalink
Hi,
Post by Paul Wellner Bou
Good morning,
i am trying to implement a reloadable property using commons-reloading2
(2.2), without success. I tried to follow the (outdated) examples on
https://commons.apache.org/proper/commons-configuration/userguide/howto_reloading.html#Reloading_File-based_Configurations
(both of them).
Could you be a bit more specific about what is outdated, so that we can
update the examples?
Post by Paul Wellner Bou
Now I created a unit test against this API which I would expect it to pass,
https://gist.github.com/paulwellnerbou/dfed371d67e2f19a699b248ebf5c62d7
Any idea what I am doing wrong?
I had a deeper look at the test and the implementation, and here is what
I found out:

The class for checking whether a reload of a file is required is
FileHandlerReloadingDetector. The class records the time of the last
check and has a refreshDelay property; it only checks again after the
time configured for the delay is elapsed. The default refreshDelay is 5
seconds. This is one reason why your test does not pass; you need to
decrease this delay or wait longer.

The other reason is that there is indeed a problem in the implementation
that causes the first call to getConfiguration() to get missed by the
reload checker. The CONFIGURATION_REQUEST event is already fired before
the file to be loaded is properly initialized, and therefore, the
checker cannot set its last check time. This is initialized only at the
second call to getConfiguration(). So the test would only be successful
if getConfiguration() was called another time (taking the refresh delay
into account).

This can be considered a bug, but is probably not very problematic in
practice when the configuration is accessed on a regular basis.

HTH
Oliver
Post by Paul Wellner Bou
Thank you and kind regards
Paul.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@commons.apache.org
For additional commands, e-mail: user-***@commons.apache.org
Paul Wellner Bou
2018-02-01 09:26:53 UTC
Permalink
Hi,

thank you very much.

Yes, this helps. This is more or less what I found out as well. That's why
I introduced the 6 seconds delay in my original example, to wait for this
5s timeout.
I tried to call getProperty more than once, too, because I noticed
debugging that the check time is only filled after the first call.

But somehow I wrote my test code in a way, that the reloading time was the
same as the time the file changed (which may happen in unit tests, its the
same millisecond). So the test failed again.

Now I reordered the statements a bit, and it works now. I just need to add
a call in the very beginning of the test. The timeouts I introduced in the
first approach are already enough.

So it works now. Thanks very much!
https://gist.github.com/paulwellnerbou/dfed371d67e2f19a699b248ebf5c62d7
Post by Paul Wellner Bou
i am trying to implement a reloadable property using commons-reloading2
Post by Paul Wellner Bou
(2.2), without success. I tried to follow the (outdated) examples on
https://commons.apache.org/proper/commons-configuration/userguide/howto_reloading.html#Reloading_File-based_Configurations
Post by Paul Wellner Bou
(both of them).
Could you be a bit more specific about what is outdated, so that we can
update the examples?
Sure:
https://gist.github.com/paulwellnerbou/3e309535a8a516477dc2bede478f79f2/revisions
Maybe you could add that commons-beanutils:1.9.3 is required to avoid the
NoClassDefFoundException (
https://stackoverflow.com/questions/16266047/very-simple-apache-commons-configuration-example-throws-noclassdeffounderror
).

Cheers,
Paul.
Post by Paul Wellner Bou
Post by Paul Wellner Bou
Now I created a unit test against this API which I would expect it to
pass,
Post by Paul Wellner Bou
https://gist.github.com/paulwellnerbou/dfed371d67e2f19a699b248ebf5c62d7
Any idea what I am doing wrong?
I had a deeper look at the test and the implementation, and here is what
The class for checking whether a reload of a file is required is
FileHandlerReloadingDetector. The class records the time of the last
check and has a refreshDelay property; it only checks again after the
time configured for the delay is elapsed. The default refreshDelay is 5
seconds. This is one reason why your test does not pass; you need to
decrease this delay or wait longer.
The other reason is that there is indeed a problem in the implementation
that causes the first call to getConfiguration() to get missed by the
reload checker. The CONFIGURATION_REQUEST event is already fired before
the file to be loaded is properly initialized, and therefore, the
checker cannot set its last check time. This is initialized only at the
second call to getConfiguration(). So the test would only be successful
if getConfiguration() was called another time (taking the refresh delay
into account).
This can be considered a bug, but is probably not very problematic in
practice when the configuration is accessed on a regular basis.
HTH
Oliver
Oliver Heger
2018-02-06 21:01:54 UTC
Permalink
Hi,

the reloading examples have been fixed, and the site was redeployed.
Thanks again.

Oliver
Post by Paul Wellner Bou
Hi,
thank you very much.
Yes, this helps. This is more or less what I found out as well. That's why
I introduced the 6 seconds delay in my original example, to wait for this
5s timeout.
I tried to call getProperty more than once, too, because I noticed
debugging that the check time is only filled after the first call.
But somehow I wrote my test code in a way, that the reloading time was the
same as the time the file changed (which may happen in unit tests, its the
same millisecond). So the test failed again.
Now I reordered the statements a bit, and it works now. I just need to add
a call in the very beginning of the test. The timeouts I introduced in the
first approach are already enough.
So it works now. Thanks very much!
https://gist.github.com/paulwellnerbou/dfed371d67e2f19a699b248ebf5c62d7
Post by Paul Wellner Bou
i am trying to implement a reloadable property using commons-reloading2
Post by Paul Wellner Bou
(2.2), without success. I tried to follow the (outdated) examples on
https://commons.apache.org/proper/commons-configuration/userguide/howto_reloading.html#Reloading_File-based_Configurations
Post by Paul Wellner Bou
(both of them).
Could you be a bit more specific about what is outdated, so that we can
update the examples?
https://gist.github.com/paulwellnerbou/3e309535a8a516477dc2bede478f79f2/revisions
Maybe you could add that commons-beanutils:1.9.3 is required to avoid the
NoClassDefFoundException (
https://stackoverflow.com/questions/16266047/very-simple-apache-commons-configuration-example-throws-noclassdeffounderror
).
Cheers,
Paul.
Post by Paul Wellner Bou
Post by Paul Wellner Bou
Now I created a unit test against this API which I would expect it to
pass,
Post by Paul Wellner Bou
https://gist.github.com/paulwellnerbou/dfed371d67e2f19a699b248ebf5c62d7
Any idea what I am doing wrong?
I had a deeper look at the test and the implementation, and here is what
The class for checking whether a reload of a file is required is
FileHandlerReloadingDetector. The class records the time of the last
check and has a refreshDelay property; it only checks again after the
time configured for the delay is elapsed. The default refreshDelay is 5
seconds. This is one reason why your test does not pass; you need to
decrease this delay or wait longer.
The other reason is that there is indeed a problem in the implementation
that causes the first call to getConfiguration() to get missed by the
reload checker. The CONFIGURATION_REQUEST event is already fired before
the file to be loaded is properly initialized, and therefore, the
checker cannot set its last check time. This is initialized only at the
second call to getConfiguration(). So the test would only be successful
if getConfiguration() was called another time (taking the refresh delay
into account).
This can be considered a bug, but is probably not very problematic in
practice when the configuration is accessed on a regular basis.
HTH
Oliver
---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@commons.apache.org
For additional commands, e-mail: user-***@commons.apache.org
Paul Wellner Bou
2018-02-07 09:03:23 UTC
Permalink
Hi,

Great, thanks to you!

Have a nice day,
Paul
Post by Oliver Heger
Hi,
the reloading examples have been fixed, and the site was redeployed.
Thanks again.
Oliver
Loading...