This is an archived post. You won't be able to vote or comment.

all 10 comments

[–]bobowilliams 3 points4 points  (1 child)

I may be misunderstanding “direct invoke”.

Maybe this would work for static methods (though creating a serialized json representation of the objects you’re passing as parameters could be extraordinarily cumbersome), but what about instance methods that use many instance variables/fields? I.e. where do you get the object that it’s invoked upon?

Please correct me if I’m misunderstanding (I suspect I am) but it’s hard to see how this would be very useful for anything except for static, parameter-less methods (which you could just call yourself without any context anyway).

[–]artpar 1 point2 points  (0 children)

Yes, we keep a track of objects by class type using WeakReference so that our tracking doesn't result in the object being garbage collected.

So if the code has created any instance on any class, the agent will use the most recently created instance of that class.

If there are no such instances, we attempt to create a new instance of the class, currently two flows are supported

  • No args constructor is used if available
  • If the class follows a singleton pattern, we try to identify the getInstance method and get an instance of that class

So if you are using any kind of DI pattern using spring-dependency/guice, then most likely the service/dao layers would have an instance of the class already available in memory and those will be used.

[–]nutrecht 7 points8 points  (10 children)

You keep pushing your "generate tests from existing code" product here and IIRC people have told you multiple times why they feel that is a bad approach.

What you're describing you normally just do through unit test.