![]() |
Scenario:-
How to display results from Beanshell sampler to response?
Solution :-
Simple code example:-
String display=”HelloWorld”;
//Taking results and displaying in response
SampleResult.setResponseData( display);
SampleResult.setDataType( org.apache.jmeter.samplers.SampleResult.TEXT );
Scenario:- Not able to understand the error message thrown by jmeter in beanshell sampler or beanshell assertions?
Solution :-
Use try-catch
try{
int expectedMsgs = ${noOfMessages} * ${messageThreads};
int actualCount =Integer.parseInt(SampleResult.getResponseDataAsString());
//System.out.print(actualCount);
if (expectedMsgs!=actualCount) {
Failure = true;
FailureMessage ="Expected Messages Sent"+expectedMsgs+"!="+actualCount+"ActualMessages in cassandra";
print("Expected Messages Sent"+expectedMsgs+"!="+actualCount+"ActualMessages in cassandra");
}
}
catch(Exception e){
log.error("Failed check the erro"+e);
}
Scenario:-
Connect to remote mySql instance (say ubuntu box) using JMeter?
Solution :-
Before doing this we need to provide privileges to the remote user to access the database using
1.SSH into remote machine
ssh username@ip address > enter password
2.Login to mysql using root user
mysql -u root -pPassword
3.Grant permission as below
GRANT ALL PRIVILEGES ON *.* TO remote@’10.0.110.***’ IDENTIFIED BY ‘pwd’ WITH GRANT OPTION;
4.Make sure to comment the following line in Mysql configuration file,
/etc/mysql/mysql.conf.d/mysqld.cnf
comment bind-address = 127.0.0.1 using the # symbol
5.Now we can replace the localhost, username and password in our connection settings for mysql.
Note:-
Incase you are getting the below error
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
Solution is run the command uninstall plugin validate_password;
Practical Examples