You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Paul Wellner Bou <pa...@wellnerbou.de> on 2018/01/30 09:18:15 UTC

[configuration] Reloading properties does not work as expected

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.

Re: [configuration] Reloading properties does not work as expected

Posted by Paul Wellner Bou <pa...@wellnerbou.de>.
Hi,

Great, thanks to you!

Have a nice day,
Paul

On Tue, Feb 6, 2018 at 10:02 PM Oliver Heger <ol...@oliver-heger.de>
wrote:

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

Re: [configuration] Reloading properties does not work as expected

Posted by Oliver Heger <ol...@oliver-heger.de>.
Hi,

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

Oliver

Am 01.02.2018 um 10:26 schrieb 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
> 
>> 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?
>>
> 
> 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.
> 
>>
>>> 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?
>>
>> 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
>>
>>
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [configuration] Reloading properties does not work as expected

Posted by Paul Wellner Bou <pa...@wellnerbou.de>.
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

> 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?
>

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.

>
> > 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?
>
> 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
>
>

Re: [configuration] Reloading properties does not work as expected

Posted by Oliver Heger <ol...@oliver-heger.de>.
Hi,

Am 30.01.2018 um 10:18 schrieb 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?

> 
> 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?

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

> 
> Thank you and kind regards
> Paul.
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org