arvindsv / faketime

Java agent to enable changing time in a Java project, mainly for testing.
18 stars 12 forks source link

How to apply to a Java Application without changing any code #7

Open arnzel opened 5 years ago

arnzel commented 5 years ago

Hi, first i want to thank you for creating this agent. I tried it out to one of our webservices and it works perfectly.

The only problem is that we have to add an additional endpoint to our webservice to run "System.setProperty(..)". It would be nicer if we could apply this change without any Code changes at all. Because we also have about 15 other services and it will take a lot of time to apply this by code changes. Other problem is that our poject managers are not happy to change services for testing purpose.

Can you say how you use this agent in your application ? do you apply System.setProperties by adding some Endpoint, JMX Bean, SocketConnection,.. ? Would be interesting to know that.

arvindsv commented 5 years ago

@arnzel Have you tried running your program with -Dfaketime.offset.seconds?

Something like:

java -agentpath:/path/to/the/library/you/got/above \
  -XX:+UnlockDiagnosticVMOptions \
  -XX:DisableIntrinsic=_currentTimeMillis \
  -XX:CompileCommand=exclude,java/lang/System.currentTimeMillis \
  -Dfaketime.offset.seconds=86400 \
  org.test.Main
arnzel commented 5 years ago

Hi @arvindsv : yes that would be a possibility. For manual tetsing something this would be enough. But we have also automated tests where start services as docker container and want to change the timestamp depending on the use case we test at runtime.REstarting the container with other parameter valuewould be a little bit heavy.

arvindsv commented 5 years ago

I see. Yes, I can understand. Unfortunately, there is no other way. Of course, it's technically possible to change the code to make it read from a socket or even a file, but writing jvmti code is quite tricky and making the current code read from something else takes some effort (to get it correct and to not crash or leak memory), which I'm not able to find time for. :(

arnzel commented 5 years ago

Okay thanks for answer. I was just interested how you use this agent or others do. I can fully understand that you dont want to change it. Maybe i can try to add an additonal agent which does this in future. But i fear this will also takes time.

Qvazar commented 5 years ago

Pull request #9 introduces support for reading an offset from a file that could've been mounted in as a volume. The file contents can be changed at runtime by an external process.

arnzel commented 5 years ago

@Qvazar thanks for the notification. I looks exactly like the thing i need. I hope i can try it soon

arvindsv commented 5 years ago

I haven't had a chance to take a look yet. @arnzel Feel free to try it out (build the PR) and see if it works. It'll help with the verification.