Time shifted testing

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Time shifted testing

nishantha pradeep
Hi All

I am working on an enterprise application running in JBOSS application server. The application records product subscriptions and creates transactions once a month.

I want to develop an automated test case in which it makes a subscription, shifts the date by 10 months and creates transactions(10 transactions need to be created now).

We were trying to use a solution described in http://virgo47.wordpress.com/2012/06/22/changing-system-time-in-java/ link but the problem is it changes the time of whole JVM. 

Then we decided refactor the code and get all the time related functions to a one EJB service. Inside the service Java provided time related functions are used. Again the problem here is there can be 3rd party libraries those have used the Java provided time functions directly. Therefore this solution is also not going to work.

There are placed where they have mentioned that Joda-time can be used for this matter (stackoverflow). But I was not able to figure out how.

So I would be very thankful if someone could provide me guideline to over come my problem.

Thanks

Nishantha


------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and
their applications. This 200-page book is written by three acclaimed
leaders in the field. The early access version is available now.
Download your free book today! http://p.sf.net/sfu/neotech_d2d_may
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Time shifted testing

jodastephen
Joda-Time allows you to change the clock used by Joda-Time code, but
not to change System.currentTimeMillis(). So I don't think Joda-Time
will overly help you.
Stephen

On 9 May 2013 05:43, nishantha pradeep <[hidden email]> wrote:

> Hi All
>
> I am working on an enterprise application running in JBOSS application
> server. The application records product subscriptions and creates
> transactions once a month.
>
> I want to develop an automated test case in which it makes a subscription,
> shifts the date by 10 months and creates transactions(10 transactions need
> to be created now).
>
> We were trying to use a solution described in
> http://virgo47.wordpress.com/2012/06/22/changing-system-time-in-java/ link
> but the problem is it changes the time of whole JVM.
>
> Then we decided refactor the code and get all the time related functions to
> a one EJB service. Inside the service Java provided time related functions
> are used. Again the problem here is there can be 3rd party libraries those
> have used the Java provided time functions directly. Therefore this solution
> is also not going to work.
>
> There are placed where they have mentioned that Joda-time can be used for
> this matter (stackoverflow). But I was not able to figure out how.
>
> So I would be very thankful if someone could provide me guideline to over
> come my problem.
>
> Thanks
>
> Nishantha
>
>
> ------------------------------------------------------------------------------
> Learn Graph Databases - Download FREE O'Reilly Book
> "Graph Databases" is the definitive new guide to graph databases and
> their applications. This 200-page book is written by three acclaimed
> leaders in the field. The early access version is available now.
> Download your free book today! http://p.sf.net/sfu/neotech_d2d_may
> _______________________________________________
> Joda-interest mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/joda-interest
>

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and
their applications. This 200-page book is written by three acclaimed
leaders in the field. The early access version is available now.
Download your free book today! http://p.sf.net/sfu/neotech_d2d_may
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Time shifted testing

Fabrizio Giudici
On Thu, 09 May 2013 11:10:14 +0200, Stephen Colebourne  
<[hidden email]> wrote:

> Joda-Time allows you to change the clock used by Joda-Time code, but
> not to change System.currentTimeMillis(). So I don't think Joda-Time
> will overly help you.
> Stephen

My personal take on this is that mocking System.currentTimeMillis() is  
partially possible, as described in the linked blog post, but it's too  
cumbersome and doesn't give me a feeling of stable enough tests. Thus my  
approach is to have a TimeFactory (aka DateFactory) as in the post, or use  
the feature cited by Stephen. As the blog post says, there are still  
troubles if you use third party libraries that do call  
System.currentTimeMillis(). My approach is just to avoid them, or avoid  
the parts that use it such as @Past - so far I've been able to, but I  
understand it's a very context-dependent situation.


--
Fabrizio Giudici - Java Architect @ Tidalwave s.a.s.
"We make Java work. Everywhere."
http://tidalwave.it/fabrizio/blog - [hidden email]

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and
their applications. This 200-page book is written by three acclaimed
leaders in the field. The early access version is available now.
Download your free book today! http://p.sf.net/sfu/neotech_d2d_may
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Time shifted testing

nishantha pradeep
In reply to this post by jodastephen
Hi Stephen
 Once the time is shifted using  DateTimeUtils.setCurrentMillisOffset(millis);
Will that changed time be reflected in all the APIs provided by Joda time ?

Thanks
Nishantha


On Thu, May 9, 2013 at 2:40 PM, Stephen Colebourne <[hidden email]> wrote:
Joda-Time allows you to change the clock used by Joda-Time code, but
not to change System.currentTimeMillis(). So I don't think Joda-Time
will overly help you.
Stephen

On 9 May 2013 05:43, nishantha pradeep <[hidden email]> wrote:
> Hi All
>
> I am working on an enterprise application running in JBOSS application
> server. The application records product subscriptions and creates
> transactions once a month.
>
> I want to develop an automated test case in which it makes a subscription,
> shifts the date by 10 months and creates transactions(10 transactions need
> to be created now).
>
> We were trying to use a solution described in
> http://virgo47.wordpress.com/2012/06/22/changing-system-time-in-java/ link
> but the problem is it changes the time of whole JVM.
>
> Then we decided refactor the code and get all the time related functions to
> a one EJB service. Inside the service Java provided time related functions
> are used. Again the problem here is there can be 3rd party libraries those
> have used the Java provided time functions directly. Therefore this solution
> is also not going to work.
>
> There are placed where they have mentioned that Joda-time can be used for
> this matter (stackoverflow). But I was not able to figure out how.
>
> So I would be very thankful if someone could provide me guideline to over
> come my problem.
>
> Thanks
>
> Nishantha
>
>
> ------------------------------------------------------------------------------
> Learn Graph Databases - Download FREE O'Reilly Book
> "Graph Databases" is the definitive new guide to graph databases and
> their applications. This 200-page book is written by three acclaimed
> leaders in the field. The early access version is available now.
> Download your free book today! http://p.sf.net/sfu/neotech_d2d_may
> _______________________________________________
> Joda-interest mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/joda-interest
>

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and
their applications. This 200-page book is written by three acclaimed
leaders in the field. The early access version is available now.
Download your free book today! http://p.sf.net/sfu/neotech_d2d_may
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest


------------------------------------------------------------------------------
AlienVault Unified Security Management (USM) platform delivers complete
security visibility with the essential security capabilities. Easily and
efficiently configure, manage, and operate all of your security controls
from a single console and one unified framework. Download a free trial.
http://p.sf.net/sfu/alienvault_d2d
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Time shifted testing

jodastephen
On 14 May 2013 08:21, nishantha pradeep <[hidden email]> wrote:
> Hi Stephen
>  Once the time is shifted using
> DateTimeUtils.setCurrentMillisOffset(millis);
> Will that changed time be reflected in all the APIs provided by Joda time ?

Yes.
Stephen

------------------------------------------------------------------------------
AlienVault Unified Security Management (USM) platform delivers complete
security visibility with the essential security capabilities. Easily and
efficiently configure, manage, and operate all of your security controls
from a single console and one unified framework. Download a free trial.
http://p.sf.net/sfu/alienvault_d2d
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Loading...