Jmeter - JUnit Sampler - junit

I am stuck at this point. I have used JUnit Sampler before successfully many times. But this time I get following error while trying to run simple program.
I have tried different version of jemeter.
I copied the selenium server file to jemeter/lib
I copied the jar file to lib/junit
I tried their test class and I tried my class
2014/11/05 16:27:23 INFO - jmeter.protocol.java.sampler.JUnitSampler: Trying to find constructor with one String parameter returned error: test.BeforeAnnotatedTest.<init>(java.lang.String)**
whole stack trace:
2014/11/05 16:27:23 INFO - jmeter.engine.StandardJMeterEngine: Running the test!
2014/11/05 16:27:23 INFO - jmeter.samplers.SampleEvent: List of sample_variables: []
2014/11/05 16:27:23 INFO - jmeter.gui.util.JMeterMenuBar: setRunning(true,*local*)
2014/11/05 16:27:23 INFO - jmeter.engine.StandardJMeterEngine: Starting ThreadGroup: 1 : Thread Group
2014/11/05 16:27:23 INFO - jmeter.engine.StandardJMeterEngine: Starting 1 threads for group Thread Group.
2014/11/05 16:27:23 INFO - jmeter.engine.StandardJMeterEngine: Thread will stop on error
2014/11/05 16:27:23 INFO - jmeter.threads.ThreadGroup: Starting thread group number 1 threads 1 ramp-up 1 perThread 1000.0 delayedStart=false
2014/11/05 16:27:23 INFO - jmeter.threads.ThreadGroup: Started thread group number 1
2014/11/05 16:27:23 INFO - jmeter.engine.StandardJMeterEngine: All thread groups have been started
2014/11/05 16:27:23 INFO - jmeter.threads.JMeterThread: Thread started: Thread Group 1-1
**2014/11/05 16:27:23 INFO - jmeter.protocol.java.sampler.JUnitSampler: Trying to find constructor with one String parameter returned error: test.BeforeAnnotatedTest.<init>(java.lang.String)**
2014/11/05 16:27:23 INFO - jmeter.threads.JMeterThread: Stop Thread detected by thread: Thread Group 1-1
2014/11/05 16:27:23 INFO - jmeter.threads.JMeterThread: Thread finished: Thread Group 1-1
2014/11/05 16:27:23 INFO - jmeter.engine.StandardJMeterEngine: Notifying test listeners of end of test
2014/11/05 16:27:23 INFO - jmeter.gui.util.JMeterMenuBar: setRunning(false,*local*)
Here is my class:
package jmeter;
import java.io.File;
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.apache.log4j.Logger;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class ShoppingCartTest {
public WebDriver driver=null;
//Initializes/loads the driver based on type of browser defined in config file
#Before
public void initDriver(){
driver =new FirefoxDriver();
driver.manage().timeouts().pageLoadTimeout(120, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
#Test
public void verifyAnItemToWishList() throws InterruptedException{
driver.get("http://www.google.com")
System.out.println("done");
}
}

Your code looks good and there are no issues there. Make sure that following conditions are met:
Your class is packaged into .jar file and dropped into /lib/junit folder of your JMeter installation (or alternatively under location specified by user.classpath property)
Looking into your #Before and #Test annotations - you're using JUnit4. In that case you need to tick Search for JUnit4 annotations box in your JUnit Request Sampler as below:
See How to Use JUnit With JMeter guide for comprehensive walkthrough on all aspects of using JUnit in JMeter.
P.S. It may be easier to consider WebDriver Sampler available via JMeter Plugins instead?

I had similar issue. It got resolved on Downloading fresh instance of Jmeter, installing Selenium/WebDriver Support plugin and Selenium Server Standalone jar. So this error might be just because of not having required Jar in Jmeter Lib folder.

I was facing the same issue, it got resolved with added System.setProperty and i dint add any other constructors (default constructor and any parameter constructor, i had tried with even these 2 constructor even then it was not working, then i added System.setProperty it worked),
For firefox,
System.setProperty("webdriver.gecko.driver", "D:\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
this resolved my issue.

Related

openjdk 8: error - No public or protected classes found to document

I'm on Debian, and have already installed OpenJDK 8 along with the packages openjdk-8-doc and default-jdk-doc; However I can't view any documentation for the classes of JDK 8 API, whenever I specify the class or package name to the javadoc utility, which fails to show the doc throwing the following errors:
ArrayList case:
kais#debian:~$ javadoc ArrayList
Loading source files for package ArrayList...
javadoc: warning - No source files for package ArrayList
Constructing Javadoc information...
javadoc: warning - No source files for package ArrayList
javadoc: error - No public or protected classes found to document.
1 error
2 warnings
kais#debian:~$ javadoc java.lang.ArrayList
Loading source files for package java.lang.ArrayList...
javadoc: warning - No source files for package java.lang.ArrayList
Constructing Javadoc information...
javadoc: warning - No source files for package java.lang.ArrayList
javadoc: error - No public or protected classes found to document.
1 error
2 warnings
JPanel case:
kais#debian:~$ javadoc JPanel
Loading source files for package JPanel...
javadoc: warning - No source files for package JPanel
Constructing Javadoc information...
javadoc: warning - No source files for package JPanel
javadoc: error - No public or protected classes found to document.
1 error
2 warnings
kais#debian:~$ javadoc javax.swing.JPanel
Loading source files for package javax.swing.JPanel...
javadoc: warning - No source files for package javax.swing.JPanel
Constructing Javadoc information...
javadoc: warning - No source files for package javax.swing.JPanel
javadoc: error - No public or protected classes found to document.
1 error
2 warnings
kais#debian:~$ javadoc javax.swing
Loading source files for package javax.swing...
javadoc: warning - No source files for package javax.swing
Constructing Javadoc information...
javadoc: warning - No source files for package javax.swing
javadoc: error - No public or protected classes found to document.
1 error
2 warnings
This seems to me weird, as the installed package openjdk-8-doc is supposed to contain the doc required by the javadoc ..
Any thoughts?
The Javadoc tool is supposed to create Javadoc out of Java source. It's not a tool to show the javadoc of a particular class. The Javadocs of the classes in the JVM is available for download at Oracle or can be browsed online.
As you said in your question, you "installed" the docs for your corresponding JDK, so instead of downloading it again or browsing it online, you can change to the "installation directory" of the doc-package and open the index-html file that should be there at its root.

Spark Read.json cant find file

Hey I all I have 1 Master and 1 Slave Node Standalone Spark Cluster on AWS. I have a folder my home directory called ~/Notebooks. This is were I launch jupyter notebooks and connect jupyter in my browser. I also have a file in there called people.json (simple json file).
I try running this code
from pyspark import SparkContext, SparkConf
from pyspark.sql import SQLContext
conf = SparkConf().setAppName('Practice').setMaster('spark://ip-172-31-2-186:7077')
sc = SparkContext(conf=conf)
sqlContext = SQLContext(sc)
df = sqlContext.read.json("people.json")
I get this error when i run that last line. I don't get it the file is right there... Any Ideas?-
Py4JJavaError: An error occurred while calling o238.json.
: org.apache.spark.SparkException: Job aborted due to stage failure: Task 1 in stage 4.0 failed 4 times, most recent failure: Lost task 1.3 in stage 4.0 (TID 37, ip-172-31-7-160.us-west-2.compute.internal): java.io.FileNotFoundException: File file:/home/ubuntu/Notebooks/people.json does not exist
Make sure the file is available on the worker nodes. Best way is to use a shared files system (NFS, HDFS). Read External Datasets documentation

Spring Boot: Getting error "Cannot determine embedded database driver class for database type NONE" when running JUnit test from eclipse

I'm having a little problems running JUnit tests from Eclipse directly (using the "Run As JUnit test" on the JUnit test file I want to run) on a simple Spring Boot application.
I'm using Gradle as a build tool. Now, when running the test as a Gradle task it works just fine, but when running it as an Eclipse JUnit task it fails with the follwoing error
java.lang.IllegalStateException: Failed to load ApplicationContext
...
Caused by: org.springframework.beans.factory.BeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath.
My application.properties files does define a local MySQL database and that seems to work fine with gradle:
spring.datasource.url: jdbc:mysql://localhost:3306/test
spring.datasource.username=user
spring.datasource.password=pass
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.jpa.hibernate.ddl-auto=update
My Application Class:
#SpringBootApplication
public class Application {
My Application test:
#RunWith(SpringJUnit4ClassRunner.class)
#SpringApplicationConfiguration(classes = Application.class)
#WebAppConfiguration
public class ApplicationTests {
Any ideas?

The web application [] appears to have started a thread named [Abandoned connection cleanup thread] com.mysql.jdbc.AbandonedConnectionCleanupThread

In the middle of my web-development I just close my web-app in my eclipse IDE, about a minute, I just saw a WARNING in my eclipse console.
WARNING: The web application [/Spring.MVC] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Sep 06, 2014 8:31:55 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
WARNING: The web application [/Spring.MVC] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.lang.Object.wait(Native Method)
java.lang.ref.ReferenceQueue.remove(Unknown Source)
com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:40)
Sep 06, 2014 8:32:00 PM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Sep 06, 2014 8:32:00 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Sep 06, 2014 8:32:03 PM org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation
INFO: HHH000204: Processing PersistenceUnitInfo [
name: personPU
...]
It did not caused any memory leak so far, I checked my VisualVM, everything is working as usual, but as I search more about this thing I realize that this warning is caused by the MySQL driver not releasing resources or not being closed properly(I dont know how to say it exactly) and I ended up in this post at SO related issue
and the OP is right the answer of "don't worry about it" won't be sufficient. This warning bothers me because it may give me some future persistence problems and that worries me a lot, I tried the code the OP has written but I'm having a problem what Libraries should I use to make this code work. This is what I got sor far..
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Enumeration;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import org.hibernate.annotations.common.util.impl.LoggerFactory;
import com.mysql.jdbc.AbandonedConnectionCleanupThread;
#WebListener
public class ContextFinalizer implements ServletContextListener {
private static final Logger LOGGER = LoggerFactory.getLogger(ContextFinalizer.class);
public void contextInitialized(ServletContextEvent sce) {
}
public void contextDestroyed(ServletContextEvent sce) {
Enumeration<Driver> drivers = DriverManager.getDrivers();
Driver d = null;
while (drivers.hasMoreElements()) {
try {
d = drivers.nextElement();
DriverManager.deregisterDriver(d);
LOGGER.warn(String.format("Driver %s deregistered", d));
}
catch (SQLException ex) {
LOGGER.warn(String.format("Error deregistering driver %s", d), ex);
}
}
try {
AbandonedConnectionCleanupThread.shutdown();
}
catch (InterruptedException e) {
logger.warn("SEVERE problem cleaning up: " + e.getMessage());
e.printStackTrace();
}
}
}
I just want to know what Libraries do I need or If I'm using the right libraries to implement this properly, I do not even know what Logger should I use, thank you for any help,
See this answer. It seems that MySQL driver should be in {$TOMCAT]/lib shared between applications. Check that you are not including it with each application. At least it worked for me and I have been able to remove the warning.
If you are using Maven mark the dependency as provided.
UPDATE:
root cause is that Tomcat have problems to garbage collect the driver because it is registered in a singleton common to several applications. Closing one application does not allow Tomcat to release the driver. See this answer.
For me i stop mysql (service mysql start) and then i stop tomcat (./shutdown.sh) in bin folder and the problem was fixed.
This works for me.
Issue was with elastic search in my case.
Send a DELETE request from postman to below endpoint and restart your application .
http://localhost:9200/*

How do I get log4J to work - I'm getting "package org.apache.log4j does not exist"

i know this may be a newbie qestion, but I'm having issues with setting up Log4J:
I want to run a log4j demo, and here's my code:
import org.apache.log4j.Logger;
import org.apache.log4j.BasicConfigurator;
public class HelloLOG4j {
private static final Logger logger = Logger.getLogger(Hello.class);
public static void main(String argv[]) {
BasicConfigurator.configure();
logger.debug("Hello world.");
logger.info("What a beatiful day.");
}
}
I set my Classpath:
C:\Users\Adel\Downloads\apache-log4j-1.2.17\log4j-1.2.17.jar
in both System and User var's
But when I run my program I still get
errors found:
File: C:\Users\Adel\Desktop\various_topics\JavaProjects\HelloLOG4j.java [line: 2]
Error: package org.apache.log4j does not exist
I know that I set classpath right - if I run cmd line:
C:\Program Files\Java\jdk1.6.0_20>print %LOG4J_HOME%
C:\Users\Adel\Downloads\apache-log4j-1.2.17\log4j-1.2.17.jar is currently bein
g printed
You need to add log4j home to the classpath as the JVM needs the path to the log4j classes
if on windows, you can use
set classpath=%classpath%;%LOG4J_HOME%
On linux/ ubuntu (much better than windows for development & servers)
export classpath=$classpath:$LOG4J_HOME
then run your app after adding other paths to classpath
like
set classpath=%classpath%;c:\users\adel\....
You do not need to add log4JHOME again - as %classpath%; will add to the current classpath.
LOG4J_HOME is not known to Java. It is just used by log4j in case of auto config/default config.
On a side note try using the new log4j2 !
Can you show how you are trying to compile the code?
And also, try adding the log4j.jar to 'lib' directory and compile with the classpath referencing this jar
Just want to remind that don't capitalized Log4j keyword , unlike Logger:
import org.apache.Log4j.Logger; //typo
import org.apache.log4j.Logger; //correct
/usr/share/java/log4j-1.2-api-2.8.2.jar path can be located by issue dpkg -L liblog4j2-java(debian-based) command, then do:
$ sudo javac -cp .:xxx.jar:/usr/share/java/log4j-1.2-api-2.8.2.jar xxx.java