faketime icon indicating copy to clipboard operation
faketime copied to clipboard

How to apply to a Java Application without changing any code

Open arnzel opened this issue 6 years ago • 7 comments

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.

arnzel avatar Mar 01 '19 10:03 arnzel

@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

arvindsv avatar Mar 01 '19 10:03 arvindsv

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.

arnzel avatar Mar 01 '19 10:03 arnzel

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. :(

arvindsv avatar Mar 01 '19 10:03 arvindsv

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.

arnzel avatar Mar 01 '19 12:03 arnzel

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.

Qvazar avatar May 01 '19 08:05 Qvazar

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

arnzel avatar May 02 '19 07:05 arnzel

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.

arvindsv avatar May 02 '19 14:05 arvindsv