JMeter Sampler with SLF4J - jmeter

I have a JMeter Java Sampler that extends AbstractJavaSamplerClient.
I'd like to use SLF4J & LogBack as my logger rather than:
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;
Ideally I'd like the sampler logs to also go to the jmeter.log file.
Any have any success with this and where do you configure logback.xml?

I Found I just needed to do the following before calling jmeter.bat
set JVM_ARGS=-Dlogback.debug=true -Dlogback.configurationFile=logback.xml

Related

JUnit class is not displayed in JMeter

I have created a Java project with 1 class containing 2 simple tests, exported as jar and added the jar in my JMeter JUnit folder, now after restarting the JMeter i don't see my class in JMeter even after selecting Annotation 4 option.
This is my class:
package print;
import org.junit.Test;
public class PrintClass {
#Test public void test() {
System.out.println("Hello World..!");
}
}
Consider the following checklist:
Your JUnit test class should have either empty constructor or constructor taking a single string as an argument. Other options are not supported
You should place your .jar file(s) under "lib/junit" folder of your JMeter installation
If there are any dependencies you need to put them somewhere in JMeter classpath as well
JMeter restart will be required to pick the .jars up
In case of any problems first of all check jmeter.log file (normally it lives under "bin" folder of your JMeter installation and contains enough troubleshooting information)
See How to Use JUnit With JMeter article for more details.
Even I faced same kind of issue then I added the dependency jars to the lib file.
Make sure you copy these files at this location -> apache-jmeter-5.1.1\lib
1.Selenium webdriver jar file (selenium-server-standalone)
2. Junit4 Jar file (junit4)
Make sure you add Jar file from eclipse or any IDE to this location -> apache-jmeter-5.1.1\lib\junit
1. Jar file which contains the automation selenium code (Using Junit)
Restart Jmeter and continue which the normal process of adding thread group and adding Junit sampler etc...
This resolved my issue and I was able to run my scripts on Jmeter.
In eclipse make sure that you create a JUnit class, not just the class and add junit annotations to this, even i was facing the same issue, it got resolved when i was created a JUnit class and then uploaded my project in JMeter
Did you put the jar in :
/lib/junit
Check you jar by running below command to see if it is ok:
jar -tvf <your jar>
And its dependencies as described in:
JUnit test classes not showing up in JMeter
See this for more details:
http://jmeter.apache.org/usermanual/junitsampler_tutorial.html

Error invoking bsh method: eval Could not initialize class

I'm new to jmeter, and I'm getting this error:
jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval Could not initialize class stpl.lib.enc.tea.TEALib
I have added the jar file of the java class in the lib/ext of the jmeter. I'm trying to import the java class in the beanshell preprocessor. The package name is stpl.lib.enc.tea and the class name is TEALib so used the syntax:
import stpl.lib.enc.tea.TEALib;
TEALib t = new TEALib();
String x = "ABCD";
vars.put("p2",x);
Also I have added a dll file in the java class which is also named as TEALib. So sometimes I also get the error saying no TEALib found in class.library.path.
The jmeter throws the two errors above.
For .jar file - copy it to JMeter's /lib folder. JMeter restart is required to pick the .jar up
For .dll file - make sure it lives under one of the following locations:
somewhere in java.library.path
somewhere under system PATH
You may add folder where .dll file lives to java.library.path using one of the following approaches:
add the next line to system.properties file (located under /bin folder of your JMeter installation)
java.library.path=/path/to/folder/where/dll/lives
Again, JMeter restart is required to apply the property.
set it via -D command line argument as:
jmeter -Djava.library.path=/path/to/folder/where/dll/lives/ -t /your/testplan.jmx
See Apache JMeter Properties Customization Guide for more information on JMeter properties and ways of working with them.

Running Spring Batch jobs from the command line

I don't know how to call a Job defined in Spring Batch using CommandLineJobRunner, documentation details are not enough for me.
I've followed the Spring Batch official guide to write Jobs in Spring Batch using Java annotations e.g. #EnableBatchProcessing because I wanted to avoid XML configuration files for the description of the job, the steps, etc.
So far I have:
a configuration class (com.package.bla.bla.ClassContainingTheBatchConfiguration see below) where I've put all the stuff defining ItemReader, ItemProcessor, ItemWriter, Job, and Step (with return jobs.get("nameOfTheJob") see below) using a #Bean annotaion.
a class with a main method with SpringApplication.run(...) and and annotation with #ImportResource("classpath:META-INF/spring/applicationContext.xml") to import some beans I need when processing the data in the Job.
On the Maven side I am currently using some plugins:
maven-jar-plugin specifying <addClasspath>true</addClasspath> and the class containing the main method in the tag <mainClass>
maven-assembly-plugin because I would like a unique executable jar containing all the stuff in the dependencies, I am using <phase>package</package> to be able to build the jar in the package phase, I am also using <goal>single</goal> to be able to properly build the jar using the assembly
maven-compiler-plugin specifying I am using Java 1.7
I think I've configured all the things I need to configure, however after having a Maven BUILD SUCCESS I am not able to run the job from the command line:
java -cp ./target/JAR_FILE_NAME.jar org.springframework.batch.core.launch.support.CommandLineJobRunner com.package.bla.bla.ClassContainingTheBatchConfiguration nameOfTheJob
Is throwing IOException due to the java.io.FileNotFoundException regarding com.package.bla.bla.ClassContainingTheBatchConfiguration. How should I specify the parameters in the command line in order to get the Job executed?
If you are already using SpringApplication from Spring Boot, why not finish the job and use #EnableAutoConfiguration as well, and also the Maven plugin (see for example this guide)? That way you will get something working pretty quickly and you can always add your own features later.
If the first argument to the CommandLineJobRunner is your #Configuration FQCN instead of a resource path, the ClassPathXmlApplicationContext constructor that's called from the CommandLineJobRunner's start() method will break.
int start(String jobPath, String jobIdentifier, String[] parameters, Set<String> opts) {
ConfigurableApplicationContext context = null;
try {
context = new ClassPathXmlApplicationContext(jobPath);
If you've already written a class with a main(), that replaces the CLJR, you shouldn't be passing CLJR as the class name in the command line. Pass that instead.
dont use spring.batch.job.enabled=false
then run using java -jar [jar-files] --spring.batch.job.names=[job-name]

Grails plugin class FilterPaneService doesn't show debug log

I use filterpane plugin for grails and need to debug it's flow. In Config.groovy i put in log4j clause debug 'org.grails.plugin.filterpane'. It started logging to console from FilterPaneUtils but not from FilterPaneService, even thought both classes are from org.grails.plugin.filterpane package. I debugged code in FilterPaneService and it run through log.debug line but nothing appears on console.
What should I do to start logging from class FilterPaneService?
using Grails 2.1.1
and filterpane plugin 2.2.2
Try with
debug grails.app.services.org.grails.plugin.filterpane.FilterPaneService
I added
private static final Log log = LogFactory.getLog(this)
to the FilterPaneService class and it started logging. I'm not sure why the author of this plugin didn't put this declaration but without it it's not working.

JVM-based scripting language with Maven dependency resolution

I am looking for a simple way write short shell scripts that call into jar files.
Having to keep track of (and installing) all those jar files for the runtime classpath partly defeats the purpose using a script (as opposed to building a runnable jar file in Eclipse). I'd like Maven (or something equivalent) to manage this.
Image:
#!/usr/bin/the-cool-shell
use org.apache.commons/lang/3.0.0
use org.json/json
import org.json.*;
new JSONObject("{}");
And this should get the required artifacts from Maven automatically (at basically zero overhead after downloading it for the first time).
What are my options?
If you were using Groovy and Groovy Shell you could be using the Grape infrastructure.
#!/usr/bin/env groovy
#Grab( 'log4j:log4j:1.2.14' )
import org.apache.log4j.Level
import org.apache.log4j.Logger
def logger = Logger.getLogger(GroovyShell.class)
Logger.rootLogger.level = Level.INFO
logger.info 'I am using the Log4j library by using Grape'
As for your exact example this would work:
#!/usr/bin/env groovy
#Grapes([
#Grab('org.apache.commons:commons-lang3:3.0'),
#Grab('org.json:json:20090211')
])
import org.json.*
new JSONObject('{}')
In this case I was using the Groovy syntax but ordinary Java syntax is also fine.
Taken from the Javadoc of #Grapes annotation:
Sometimes we will need more than one grab per class, but we can only add
one annotation type per annotatable node. This class allows for multiple
grabs to be added.
You could try Gradle, it's a build management tool, but it uses Groovy for its build scripts, and it uses the Maven dependency model. So your script could be a Gradle 'build' script, that just did something different than building software.

Resources