Find all method name in one flow of code - java

I just want to know if there is any API or any thing which tells me all the method name which have been executed during one execution of application.
For ex. Lets say I have application with 10000 methods and based on some condition different methods get executed. So during one execution lets say if 100 method getting executed then I would like to know name of all these 100 methods in order of their execution.
is it possible?

There are few options you can use to track your method calls.
1. JProfiler http://www.ej-technologies.com/products/jprofiler/overview.html
2. Your kit. http://www.yourkit.com/
3. In addition you can write an application that logs to file when enters to methods and exit using Aspects with Log4j or SL4j

Related

Can a Jmeter Java Request can have Summary Report?

Is it possible for a Java request to have a summary report to it. I tried attaching
TPS listener, results tree, results table but could not see the report populated after running in jmeter.
It is not explicitly mentioned jmeter docs, but i assume, It should be supported.But i am not able to see it even after successful run of the test as seen from logs (runTest() method gets called successfully)
It is
The runTest() function is supposed to return a SampleResult and it's your job to call the necessary functions like:
create a new instance
call sampleStart() function when you want to start the measurement
call sampleEnd() function when you want to stop the measurement
call setSuccessful() function to mark the sampler as passed or failed
call setResponsecode() and setResponseData() functions to set response code/response body if needed
See JavaTest and SleepTest example implementations for reference.
You may also find JSR223 Sampler with Groovy easier to use (Java syntax should work in the majority of cases)

When to use Mono.never()?

I have read through the Javadocs for the reactor.core.publisher.Mono class From project reactor However I still don't understand what's the point of having the Mono.never() method.
What are some example use cases where one would use Mono.never()?
It is very often used in tests (typically to assert timeout behavior), but can also have production usage: some operators take a control Publisher as parameter in various situations where they need an asynchronous external signal to tell them to trigger some behavior. If in some cases you don't want said behavior to trigger, user never().
For instance, windowWhen takes such parameter both for opening and closing windows (the later generated by a Function). Conditionally returning a Mono.never() you could have a window that never closes.

How to achieve more granularity with running TestNG test cases?

At present, I have two types of execution choices in my project:
testSuite.xml: where I am able to include methods and classes of my choice to each suite
Added a runtime argument in maven goals in jenkins job. -Dsomeproperty=propetyValue: reading that through system properties as any VM arg, which is giving me choice inside the test methods to execute a certain condition. For example, if I do a transaction and the application allows negative balance in the account, then I can write the argument as -DallowNegativeBalance=true and read that inside the test method, when true, it will not fail the validation due to negative balance. Just an example.
Now I want to add more granularity to have more controls, for example,
Control the conditions within the test method.
Control the entire test method.
Control the entire test class.
Control the entire test suite.
And all this not inside program only, ideally one should be able to control that depending upon the user stage of deployment (means one stage can have a specific flow of deployment, for example, with allow negative balance true as above), so the CI FT job should be in such a way that above mentioned controls are possible. Like, within the testSuite also, some methods dont get executed, or even some classes which are not relevant to that negative balance flow are not executed. How can I achieve that?
I am a Java dev with little exp in TestNG limited to the suites and the maven arg mentioned in the beginning. Help is appreciated.

Method's execution time in java

I want to print the execution time for a method in java. Currently am using the following code,
long startTime = System.currentTimeMillis();
// method body
long runTime= System.currentTimeMillis() - startTime;
System.out.println(" XYZ Method execution time: " + runTime);
There are so many methods for which I would like to find the runtime in the project, is there any way to prevent writing this piece of code in every method?
The project uses Spring 2.5, Struts 2.
Edit:I do not want to add the logic to every method, I would like to, say, write the logic once and use some kind of configuration where I can specify the methods for which I need to print the execution time. So whenever the method is executed, automatically the run time should get printed to the console. One way is as said by me is to add the code to prologue and epilogue, but I do not want to edit the method as that would be time consuming and writing the same code wont be a good practice.
I recommend you take a look at the Metrics package from Codahale. This package collects various metrics (including timing) which is then reported via JMX or other mechanisms.
Why don't you just use a profiler, like YourKit or JVisualVM. JVisualVM comes with the JDK. If you really want to do this yourself, use java.lang.instrument and ASM to write your own agent. It's simple to add logic to the prologue and epilogue of a Java method using this approach.
Here's a link to get you started.
Option 1 :: Use AOP
Option 2 :: If you are logging at the right places (before & after), and are throwing in the time stamp in your logs, you could just use any analytics tools (logrythm, splunk's open source version, etc.) to just crunch your logs and figure out the times. However keep in mind logging is generally an expensive operation (well, so is AOP to some extent).
Whichever approach you take, make sure to count for the performance impact you are going to put on your application just to measure performance itself :-).
Take a look at the Spring AOP, you can use around advice to calculate method execution time
Spring 2.5
Spring 3.0 x

Drools Flow dynamic Ruleflowgroup parameter

I have a process in drools with a process variable that gets set. I would like to be able to dynamically change what ruleflowgroup gets called based on the variable.
I have tried setting the ruleflowgroup to #{ruleFlowGroupName} but the rules never activate.
I have a script task right before the ruleflow group that prints out the value of the variable and it is correct.
I have done this before with a reconfigurable subprocess where the process id is a process variable and the process dynamically gets replaced when the main process runs.
I was hoping to be able to do this with specifying the ruleflowgroup too.
any ideas?
What is the business objective of doing that? if you have two different set of rules that evaluate different data depending on what you are inserting inside the drools engine, there is no need to have two different rule flow groups. Only the relevant rules will be activated.
Cheers
It is indeed true that a dynamic ruleflowgroup name is currently not supported. I've created a JIRA for this so we can track this and you can keep updated on any progress.
https://issues.jboss.org/browse/JBPM-3552
It would indeed be useful to describe the situation where you think this might be useful, as there may be alternatives / workarounds already.

Categories

Resources