I wrote a custom sampler in JMeter that takes a sql query and returns the response. I currently have a the CSV Data Set Config setup that takes a CSV file of sample users that I want to query in my custom sampler.
Here is my sampler and tree of files on JMeter.
I configured my jmeter test like this post stated here.
In my Sampler code, I'm extracting the inputs of the text area like this:
DbSampler.java:
public class CosmosDBSampler extends AbstractSampler {
private static final Logger logger = LoggerFactory.getLogger(CosmosDBSampler.class);
private static final String COSMOS_QUERY = "Cosmos.cosmosQuerys";
public void setCosmosQuery(String query) {
setProperty(COSMOS_QUERY, query);
}
public String getCosmosQuery() {
return getPropertyAsString(COSMOS_QUERY, "");
}
@Override
public SampleResult sample(Entry entry) {
SampleResult result = new SampleResult();
boolean isOK = false;
result.setSampleLabel("Cosmos Sampler");
result.sampleStart();
try {
// Cosmos Service constructor for entering config and query
CosmosService cosmosService = new CosmosService( getCosmosQuery());
// Kick off Query
JsonNode response = cosmosService.ReadCosmos();
// set response
result.setSamplerData(response.toString());
result.setResponseData(response.toString(), null);
result.setDataType(SampleResult.TEXT);
result.setResponseCodeOK();
result.setResponseMessage("OK");
result.getRequestHeaders();
result.getResponseHeaders();
isOK = true;
} catch (Exception ex) {
logger.debug("", ex);
result.setResponseCode("500");
result.setResponseMessage(ex.toString());
}
result.sampleEnd();
result.setSuccessful(isOK);
return result;
}
When the ${variable} gets executed, the error response is due to the db not being able to read $
. It's not converting the variable to a string when executing the query.
Do I need to specify in the code that it should take a variable somewhere or is my configuration on JMeter need modifications? Let me know if I can give anymore information that would help. Thank you.