Jmeter - How to loop data based on the 'jar' file - loops

I want to create scenario where i want use data from jar file into Jmeter Loop logic.
My jar looks like:
public String Australia()
{
String a = "{"
+ "\"location\": {"
+ "\"lat\": -33.8669710,"
+ "\"lng\": 151.1958750"
+ "},"
+ "\"accuracy\": 50,"
+ "\"name\": \"Google Shoes!\","
+ "\"phone_number\": \"(02) 9374 4000\","
+ "\"address\": \"48 Pirrama Road, Pyrmont, NSW 2009, Australia\","
+ "\"types\": [\"shoe_store\"],"
+ "\"website\": \"http://www.google.com.au/\","
+ "\"language\": \"en-AU\""
+
"}";
return a;
}
public String canada()
{
String c = "{"
+ "\"location\": {"
+ "\"lat\": -33.8669710,"
+ "\"lng\": 151.1958750"
+ "},"
+ "\"accuracy\": 50,"
+ "\"name\": \"Google Shoes!\","
+ "\"phone_number\": \"(02) 9374 4000\","
+ "\"address\": \"48 Pirrama Road, Pyrmont, NSW 2009, Canada\","
+ "\"types\": [\"shoe_store\"],"
+ "\"website\": \"http://www.google.com.ca/\","
+ "\"language\": \"en-CA\""
+
"}";
return c;
}
1) with above data i want to 'feed' Jmeter call as described on the bellow picture
2) every time i add new country at the jar file, loop be increased accordingly.
Some thought how this could be done, what should i use as variable and how i can tell the loop to increase?

Add JSR223 PreProcessor as a child of the 002_2_send payment request
Put the following code into "Script" area:
def testData = new com.example.TestData()
def methods = testData.class.getDeclaredMethods()
def payload = org.apache.commons.lang.reflect.MethodUtils.invokeExactMethod(testData, methods[vars.get('__jm__Loop Controller__idx') as int].getName())
sampler.addNonEncodedArgument('',payload,'')
sampler.setPostBodyRaw(true)
Define "Loop Count" in the Loop Controller using __groovy() function like:
${__groovy(com.example.TestData.getDeclaredMethods().size(),)}
Change com.example to your own package name and TestData to your class name
Once you drop the new version of .jar to JMeter Classpath you will need to restart JMeter to pick up the changes
That's it, each iteration of the Loop Controller the JSR223 PreProcessor will execute the next function in your class and update the request body with the returned data:
References:
Java Reflection API
Apache Groovy - Why and How You Should Use It

Related

Apache Camel: How to download multiple files from SFTP with Premove, Move and MoveFailed options?

I have two file names in following format:
Gontagrator_1.xml
Gontagrator_2.xml
As of now i am picking just Gontagrater_1.xml and rename it to processing and failed once done.
+ "&fileName=" + sftpFileName
+ "&preMove="+sftpFileName+".$simple{date:now:yyyy-MM-dd'T'hh-mm-ss}.processing"
+ "&move="+sftpFileName+".$simple{date:now:yyyy-MM-dd'T'hh-mm-ss}"
+ "&moveFailed="+sftpFileName+".$simple{date:now:yyyy-MM-dd'T'hh-mm-ss}.failed"
Now Gontagrator_2 comes into picture. It is suggested to create separate routes for both.
Can we download both in one route and rename accordingly? If yes, what values i need to pass?
Update1: There are multiple files with different names but i need to use both above file names only
update 2: Whole from component is:
"{{m.protocol}}://{{m.hostname}}{{t.directory}}"
+ "?username={{m.username}}"
+ "&password={{m.password}}"
+ "&download=true"
+ "&useList=false"
+ "&stepwise=false"
+ "&disconnect=true"
+ "&passiveMode=true"
+ "&reconnectDelay=10000"
+ "&bridgeErrorHandler=true"
+ "&delay=30000"
//+ "&fileName=" + sftpFileName
+ "&include="+ sftpFileName
+ "&preMove=$simple{file:onlyname}.$simple{date:now:yyyy-MM-dd'T'hh-mm-ss}.processing"
+ "&move=$simple{file:onlyname}.$simple{date:now:yyyy-MM-dd'T'hh-mm-ss}"
+ "&moveFailed=$simple{file:onlyname}.$simple{date:now:yyyy-MM-dd'T'hh-mm-ss}.failed"
+ "&readLock=idempotent-changed"
+ "&idempotentRepository=#infinispan"
+ "&readLockRemoveOnCommit=true")
.onException(GenericFileOperationFailedException.class)
.onWhen(exchange -> {
Throwable cause = exchange.getException(GenericFileOperationFailedException.class).getCause();
return (cause != null && cause.toString().equalsIgnoreCase("2: No such file"));
}).handled(true)
.logExhausted(true)
.logExhaustedMessageHistory(true)
.log("Could not find file")
.end()
.log("Downloading xml file")
//.to(archiveReceivedFile(sftpFileName))
.split(body().tokenizeXML("ERequest", "ERequests")).streaming()
.inOnly(E_QUEUE)
Yes, you can download all files in one route.
You need to
Remove fileName option (such that the route will pick all file)
Use file expression language (file:onlyname) to refer to filename currently handled by Camel SFTP component
+ "&preMove=$simple{file:onlyname}.$simple{date:now:yyyy-MM-dd'T'hh-mm-ss}.processing"
+ "&move=$simple{file:onlyname}.$simple{date:now:yyyy-MM-dd'T'hh-mm-ss}"
+ "&moveFailed=$simple{file:onlyname}.$simple{date:now:yyyy-MM-dd'T'hh-mm-ss}.failed"
Use include option to control file to be picked up (REGEX to match file name pattern)
+ "&include=Gontagrator_(1|2)\.xml"

Apache Camel consumer template to copy file, cannot copy one file twice

Hi I am using apache camel 2.15.2. I have got a consumer template so that I can copy file with dynamic file names:
if (fileInfo != null) {
filename = fileInfo.getFileName();
String camelUri = "file://" + fileInfo.getCopyFilePath() + "/?fileName=RAW("
+ filename + ")&noop=false&idempotent=false&readLock=changed";
System.out.println("Camel uri: " + camelUri);
logger.info("Camel uri: " + camelUri);
Exchange ex = consumerTemplate.receive(camelUri);
....
As you can see, I have set noop, and idempotent explicitly to achieve copying same file more than once. But, it does not do that. It hangs on receive method for subsequent tries to copy a file with same name. It can copy that, only if we restart the application. Any suggestions would be much appreciated. It might be something similar to this issue, but I do not have access to that solution. Thanks in advance.
When I debugged through Camel code, it seems, it is calling EventDrivenPollingConsumer's receive method, and hangs when calls queue.take() (line 110, EventDrivenPollingConsumer). And, even inside that, 'count' variable is zero in ArrayBlockingQueue:
while (count == 0)
notEmpty.await();
Added this, just in case it helps anyone having a clue.
Ok, If I call 'consumerTemplate.doneUoW(ex)', it does copy multiple times. But, at the same time it was deleting (actually moving to .camel folder) the source file, which I did not want to! Then, had to set noop=true:
if (fileInfo != null) {
filename = fileInfo.getFileName();
String camelUri = "file://" + fileInfo.getCopyFilePath() + "/?fileName=RAW("
+ filename + ")&noop=true&idempotent=false&readLock=none";
System.out.println("Camel uri: " + camelUri);
logger.info("Camel uri: " + camelUri);
Exchange ex = consumerTemplate.receive(camelUri);
// consumerTemplate.r
logger.info("File received: " + fileInfo.getFileName());
exchange.getOut().setBody(ex.getIn().getBody());
consumerTemplate.doneUoW(ex);
}
Now, it works as expected.

I have custom code that I need to bold for output. What google sheets script can I use?

I have created a customized work order submission form in Forms & Sheets that auto emails a confirmation from each submission (job request form) to create a data trail of vendor activity. Fairly integrated and totally cobbled together by a lot of reading in these forums coupled with a gazillion frustrating moments of trial & error. Novice moving towards "capable" but Im stuck on a piece of code for a triggered confirmation email with random work order generator and email confirmations and toggle based management built in. The code below that I actually need help with is for that triggered confirmation email that sends a confirmation of service, work order #, and also shows everything they originally submitted. The problem is that the code I have is providing the data exactly how and I want it and placement is great, but I need to create visual distinction between the column titles and the variable submission data. Can someone please help me add a bold code to the column titles in line 16 to help create that visual differentiation between columnar "category and submission data?
// This constant is written in column C for rows for which an email
// has been sent successfully.
var EMAIL_SENT = "EMAIL_SENT";
function sendEmails2() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2; // First row of data to process
var numRows = 1000; // Number of rows to process
// Fetch the range of cells A2:B3
var dataRange = sheet.getRange(startRow, 1, numRows, 27)
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var emailAddress = row[19];
var message = row[16] + "\n\n" + "Submitted By: " + row[19] + "\n\n" + "Date Submitted: " + row[0] + "\n\n" + row[21] + "\n\n" + "IMPORTANT NOTES FROM CDS: " + row[20] + "\n\n" + "Full Show Services: " + row[3] + "\n\n" + "Event Start Date: " + row[4] + "\n\n" + "Event End Date: " + row[5] + "\n\n" + "Warehouse Locations: " + row[6] + "\n\n" + "Individual Services Requested: " + row[7] + "\n\n" + "Individual Services - Warehouse(s) & Date(s) Requested: " + row[8] + "\n\n" + "Partial Hourly Staffing Details Requested: " + row[9] + "\n\n" + "Requestors Instructions / Comments: " + row[10] + "\n\n" + "Files: " + row[11] + row[12] + "\n\n" + "Thank you for your request. We appreciate your business. CDS Special Events Team ";// Second columnn
var emailSent = row[18];
var subject = row[16];// Third columnvar ss = SpreadsheetApp.getActiveSpreadsheet();
if (emailSent != EMAIL_SENT) { // Prevents sending duplicates
MailApp.sendEmail(emailAddress, subject, message);
sheet.getRange(startRow + i, 19).setValue(EMAIL_SENT);
// Make sure the cell is updated right away in case the script is interrupted
SpreadsheetApp.flush();
}
}
}

Not able to access MSSQL analysis services cubes

I am using the following code to access mssql analysis services cubes from java using OLAP4j 1.1.0
Class.forName("org.olap4j.driver.xmla.XmlaOlap4jDriver");
OlapConnection con = (OlapConnection)
DriverManager.getConnection("jdbc:xmla:Server=http://mssql.com/mssql/msmdpump.dll;"+
"Cache=org.olap4j.driver.xmla.cache.XmlaOlap4jNamedMemoryCache;"+
"Cache.Name=MyNiftyConnection;Cache.Mode=LFU;Cache.Timeout=600;Cache.Size=100",
"username", "password");
OlapWrapper wrapper = (OlapWrapper) con;
OlapConnection olapConnection = wrapper.unwrap(OlapConnection.class);
OlapStatement stmt = olapConnection.createStatement();
CellSet cellSet = stmt.executeOlapQuery("SELECT {" +
" [Measures].[LoginTime_Format]," +
"[Measures].[EngageTime_Format]," +
"[Measures].[ChatTime_Format]," +
"[Measures].[AverageHandleTime_Format]," +
"[Measures].[MultipleChatTime_Format]," +
"[Measures].[NonEngagedTime_Format]," +
"[Measures].[TimeAvailable_Format]," +
"[Measures].[TimeAvailableNotChatting_Format]," +
"[Measures].[TimeNotAvailable_Format]," +
"[Measures].[TimeNotAvailableChatting_Format]," +
"[Measures].[AcdTimeouts]," +
"[Measures].[AvgConcurrency]," +
"[Measures].[OperatorUtilization]} ON 0," +
" NON EMPTY ([DimTime].[CalenderDayHour].[CalenderDayHour], [DimAgent].[Agent]."+
"[Agent],[DimAgent].[Agent Name].[Agent Name]) ON 1" +
" FROM (SELECT [DimClient].[Client].&[4] ON 0 FROM" +
" (SELECT [DimTime].[CalenderDayHour].[CalenderDayHour].&[2013010100]:"+
"[DimTime].[CalenderDayHour].[CalenderDayHour].&[2013121216] ON 0 FROM [247OLAP]))");
When I run this code I get the following exception at executeOlapQuery line-
Exception in thread "main" java.lang.RuntimeException: [FATAL]:1:1: Content is not allowed in prolog.
at org.olap4j.driver.xmla.XmlaOlap4jUtil.checkForParseError(XmlaOlap4jUtil.java:134)
at org.olap4j.driver.xmla.XmlaOlap4jUtil.parse(XmlaOlap4jUtil.java:83)
at org.olap4j.driver.xmla.XmlaOlap4jConnection.executeMetadataRequest(XmlaOlap4jConnection.java:884)
at org.olap4j.driver.xmla.XmlaOlap4jDatabaseMetaData.getMetadata(XmlaOlap4jDatabaseMetaData.java:137)
at org.olap4j.driver.xmla.XmlaOlap4jDatabaseMetaData.getMetadata(XmlaOlap4jDatabaseMetaData.java:67)
at org.olap4j.driver.xmla.XmlaOlap4jDatabaseMetaData.getDatabaseProperties(XmlaOlap4jDatabaseMetaData.java:1044)
at org.olap4j.driver.xmla.XmlaOlap4jConnection.makeConnectionPropertyList(XmlaOlap4jConnection.java:324)
at org.olap4j.driver.xmla.XmlaOlap4jConnection.generateRequest(XmlaOlap4jConnection.java:1037)
at org.olap4j.driver.xmla.XmlaOlap4jConnection.populateList(XmlaOlap4jConnection.java:849)
at org.olap4j.driver.xmla.DeferredNamedListImpl.populateList(DeferredNamedListImpl.java:136)
at org.olap4j.driver.xmla.DeferredNamedListImpl.getList(DeferredNamedListImpl.java:90)
at org.olap4j.driver.xmla.DeferredNamedListImpl.size(DeferredNamedListImpl.java:116)
at org.olap4j.driver.xmla.XmlaOlap4jConnection.getOlapDatabase(XmlaOlap4jConnection.java:451)
at org.olap4j.driver.xmla.XmlaOlap4jConnection.getOlapCatalog(XmlaOlap4jConnection.java:501)
at org.olap4j.driver.xmla.XmlaOlap4jConnection.getCatalog(XmlaOlap4jConnection.java:496)
at org.olap4j.driver.xmla.XmlaOlap4jStatement.executeOlapQuery(XmlaOlap4jStatement.java:291)
at com.tfsc.ilabs.olap4j.POC.main(POC.java:28)
Caused by: org.xml.sax.SAXParseException: Content is not allowed in prolog.
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.olap4j.driver.xmla.XmlaOlap4jUtil.parse(XmlaOlap4jUtil.java:80)
Any help will be much appreciated.
You should check what's being sent back by the server, using WireShark or something similar. This kind of error happens when the XML parser tries to parse the response it got. The server is probably not sending XML content back.

Help with SSIS Package

Hi all i've got a complex SSIS package, however i'm hitting my head against a brick wall with a particular part. I've got a maintenance part that will delete files that are older than 3 months old (from today's date). The files all have the date in the filename, for example AA-CDR-20110606030000-2-001A648E6F74-026874.xml
So i've written a task that will loop over all the files in a particular folder using a Foreach loop, then i have a script that will load in the filename using a variable set using the foreach loop. Then delete the file using the script below. This works fine when running in debug mode. However when trying to execute this on the server i get a failure with a "System.FormatException: String was not recognized as a valid DateTime.". I really dont understand why, any ideas?
DateTime deleteDate = DateTime.Today.AddMonths(-3);
String file = Dts.Variables["FileName"].Value.ToString();
String fileDateString = file.Substring(42, 8);
String fileDateYear = fileDateString.Substring(0, 4);
String fileDateMonth = fileDateString.Substring(4, 2);
String fileDateDay = fileDateString.Substring(6, 2);
DateTime fileDateTime = Convert.ToDateTime(fileDateDay + "-" + fileDateMonth + "-" + fileDateYear);
if (fileDateTime < deleteDate)
{
System.IO.File.Delete(file);
}
It seems that there is a file on the production server that does not follow the pattern and the date cannot be extracted from its name.
Try to use something like this:
try
{
DateTime fileDateTime = Convert.ToDateTime(fileDateDay + "-" + fileDateMonth + "-" + fileDateYear);
if (fileDateTime < deleteDate)
{
System.IO.File.Delete(file);
}
}
catch (System.FormatException)
{
// log the Dts.Variables["FileName"] value here to see why it could not be parsed
}

Resources