1 2 Previous Next 15 Replies Latest reply: Mar 18, 2011 4:48 AM by 766878

# Examples of Java-code scripts in Openscript/OLT

Hi,

Does anybody know of any examples of (non-HTTP) Java-code scripts for OLT? (I read about the SQL-test using a Java-Code script in aamats blog, so we figured it should work with any free-text protocol)

And does this cause any problems in OLT (e.g. the HTTP scenario/script-settings will be invalid)?

Any tips are most welcome!

Regards,
Axel
• ###### 1. Re: Examples of Java-code scripts in Openscript/OLT
Axel,

So far I've been able to run just about any java package through Openscript. I haven't pushed them all through Load Testing.

Everything that I have read shows that it should definitely be possible do this. You should also be able to run similar things directly from Test Manager as far as I can tell, if you need to have some reporting from load, but want to be doing something a little more functional outside of your database. Maybe for portals or some such thing?

I'm sure you have already looked at them -- but these go over how you can access things from Openscript. "Things" being any application you can basically call to from java. There is a "basic" java script template in openscript, as said above, its worked for me.

Cheers.

--tiff
• ###### 2. Re: Examples of Java-code scripts in Openscript/OLT
Hi,

Basically, it seems to be working. The VUs are doing what they should. But how do I time the step groups?

Example Java-code:

beginStep("[2] Search", 0);
{
long time1 = System.currentTimeMillis();
... (java code)...

long time2 = System.currentTimeMillis();
}
endStep();

long duration = time2 - time1;

I want that duration logged for the step/iteration. How do I do that?

Edited by: ao on 2011-mar-01 15:00
• ###### 3. Re: Examples of Java-code scripts in Openscript/OLT
Axel,

This is not so difficult.

For each step, you can see that there is a begin step and an end step. The whole step time is already reported as part of the result, so you could just extract it out of the results (its already reported for each step and substep). If you want to have this information and use it for something else -- you can simply put a variable to capture the System.currentTimeMillis() at the beginning of the step (or substep) and one at the end. Everything inside the brackets will happen sequentially, so you don't have to worry about those. Here is an example to snag the time and write it to a file, please note that the actual step stuff are just place holders for the actual java that Openscript creates:

Filewriter times = new Filewriter("<your filepath\\times.txt>", true) /* here the true sets it to append text in the file, instead of overwrite */

long start = 0;
long stop = 0;

begin step stuff {
start = (System.currentTimeMillis());

stop = (System.currentTimeMillis());
long steptime1 = (stop - start);
times.write("Time for Step 1: " + steptime1);
}
end step stuff {}

Using the above would grab the current time at the beginning and the end, then figure the difference between them and report to the text file times.txt a single line that would read: Time for Step 1: <time in milliseconds>.

I hope this is helpful. I'm currently using similar java with both my OFT and OLT tests, via OTM and just running them in OLT and OFT. So I know it works.

--tiff
• ###### 4. Re: Examples of Java-code scripts in Openscript/OLT
Hi,

It all works, basically... But not the OLT reporting.

In my OLT report I have all zeroes, but in my times.txt-file I have [47, 47, 47, 63, ...].

"
Performance by Profile and Timer
Name Value Min Max Avg Pass Fail
JavaTCPTest 0 0 0 0 10 0
Initialize: JavaTCPTest 0 0 0 0 1 0
Run: JavaTCPTest 0 0 0 0 10 0
[0] Open 0 0 0 0 10 0
[1] Send 0 0 0 0 10 0
[2] Wait 0 0 0 0 10 0
[3] Receive 0 0 0 0 10 0
[4] Close 0 0 0 0 10 0
Finish: JavaTCPTest 0 0 0 0 1 0
"

Also, the graphs are all empty. There seems to be something missig. Maybe the reporting to the controller?

Edited by: ao on 2011-mar-02 13:53
• ###### 5. Java-code scripts in Openscript and OLT reporting.
Is there anybody who has any suggestions on this?

We tried for example:

getCounters().report("", "MetricX", null, "CounterY", Counters.AggType.Average , duration/1000);

But nothing shows up in OLT reporting UI, as it should according to the API Reference documentation.

Edited by: ao on 2011-mar-08 10:23
• ###### 6. Re: Java-code scripts in Openscript and OLT reporting.
Have you tried the Step Results Add Message method? This will directly add a message to the step results message. I am seeing that this is stored with the rest of the results for the test run. However, unless you have it to always record this information then it won't show up (I usually set it to only show when it errors.) but you can still see it if you access the database files directly, so the information is still available.

Also -- if you are wanting the "Server Response Tests" you can see those in the messages as well for each step, but you have to record always and not just on error or never. Then the information will be displayed in the results page for each individual session that you are running in OLT.

I hope this helps.

--tiff
• ###### 7. Re: Java-code scripts in Openscript and OLT reporting.
I can't see any addMessage method in the API-reference (version 9.2 of oats). Could you post a code-example?

Yes, we just want the default session graphs in OLT (server times, KB/sec, etc... ) + performance per step-group in each profile/script. All reporting functionality is obviously already in there. We just can't figure out the right class/method that does the job.

//Ax
• ###### 8. Re: Java-code scripts in Openscript and OLT reporting.
Can you share your script or at least dummy version of that ?? If not, please share some info on the package you are using to create scripts. Easier to test it out.

Thanks
Raj
• ###### 9. Re: Java-code scripts in Openscript and OLT reporting.
Here is a very basic dummy script that I created, just as a Proof-Of-Concept. (simple HTTP post to google, we want to replace that with a fixed-length protocol later)

Example: We want the "duration" (=server time), pages/sec, KB/sec etc in the OLT report. How do I do that, on a session level and on a step-level?

- - -

public class script extends IteratingVUserScript {
@ScriptService oracle.oats.scripting.modules.utilities.api.UtilitiesService utilities;

public String smessage1;
public String smessage2;
public String smessage3;
public Socket socket;
public OutputStream out;
public InputStream in;
public int idata;
double time1, time2, duration;

public void initialize() throws Exception {
int data;
smessage1 = "GET / HTTP/1.1\r\nAccept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, */*\r\nAccept-Language: sv\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0E)\r\nHost: www.google.com\r\nConnection: Keep-Alive\r\n\r\n";
smessage2 = "";
smessage3 = "";

}

public void run() throws Exception {

beginStep("[0] Open", 0);
{
socket = new Socket("209.85.135.99", 80);
out = socket.getOutputStream();
in = socket.getInputStream();
}
endStep();

beginStep("[1] Send", 0);
{
out.write(smessage1.getBytes());
out.flush();
}
endStep();

beginStep("[2] Wait", 0);
{
time1 = System.currentTimeMillis();
time2 = System.currentTimeMillis();
duration = time2-time1;
}
endStep();

// Throw away.
{
int i = 0;
while (idata != -1 && i < 100) {
i++;
}
}
endStep();

beginStep("[4] Close", 0);
{
out.close();
in.close();
socket.close();
}
endStep();
}

public void finish() throws Exception {

}
}
• ###### 10. Re: Java-code scripts in Openscript and OLT reporting.
     Totals
Transactions      10
Transactions with Errors      0
Pages      50
Hits      0
Kilobytes      0

Performance by Profile and Timer *
Name      Min      Max      Avg      Pass      Fail      Std Dev      90th %
cusprot      0.014      0.053      0.038      10      0      0.018      0.053
Initialize: cusprot      0      0.007      0.002      10      0      0.004      0.007
Run: cusprot      0.013      0.053      0.038      10      0      0.019      0.053
[0] Open      0.006      0.026      0.018      10      0      0.01      0.026
[1] Send      0      0      0      10      0      0      0
[2] Wait      0.003      0.026      0.017      10      0      0.011      0.026
[3] Receive      0      0.001      0.001      10      0      0      0.001
[4] Close      0      0.002      0.001      10      0      0.001      0.002
Finish: cusprot      0      0.001      0      10      0      0      0.001 
I did not have problem running the script in OLT. For, KB/sec and pages/sec - you have to include custom code to output this at the end of the test. Page count in the OLT report is based on the step count in the script and total vusers in OLT. I ran for 10 vusers and because the script has 5 steps, it assumed each step as 1 page.

Raj
• ###### 11. Re: Java-code scripts in Openscript and OLT reporting.
When I set "Show Server Times Only", it shows only zeros. Setting "Show End-to-End Times (includes Think Times)" shows some values. But this is strange, since I don't have any think-times.
For, KB/sec and pages/sec - you have to include custom code to output this at the end of the test
Could you please post an example?

- - -

"
Performance by Profile and Timer
Name Value Min Max Avg Pass Fail
JavaTCPTest 0 0 0 0 100 0
Initialize: JavaTCPTest 0 0 0 0 10 0
Run: JavaTCPTest 0 0 0 0 100 0
[0] Open 0 0 0 0 100 0
[1] Send 0 0 0 0 100 0
[2] Wait 0 0 0 0 100 0
[3] Receive 0 0 0 0 100 0
[4] Close 0 0 0 0 100 0
Finish: JavaTCPTest 0 0 0 0 10 0
"

"
Performance by Profile and Timer *
Name Value Min Max Avg Pass Fail
JavaTCPTest 0.078 0.078 0.081 0.079 100 0
Initialize: JavaTCPTest 0 0 0.008 0.001 10 0
Run: JavaTCPTest 0.078 0.078 0.08 0.079 100 0
[0] Open 0.031 0.031 0.033 0.032 100 0
[1] Send 0 0 0 0 100 0
[2] Wait 0.047 0.046 0.047 0.047 100 0
[3] Receive 0 0 0.001 0 100 0
[4] Close 0 0 0 0 100 0
Finish: JavaTCPTest 0 0 0 0 10 0
* Profile timers include think times
"

//A

Edited by: ao on 2011-mar-16 10:39
• ###### 12. Re: Java-code scripts in Openscript and OLT reporting.
You are correct. I think, it is an exercise in futile. Tool does not suit for this kind of testing. There should be some other tools meant for load testing at TCP level.

Raj
• ###### 13. Re: Java-code scripts in Openscript and OLT reporting.
Hi,

That's what we were thinking. Basically it works, iterating the java-agents, generating load.

The reporting part seems to be missing out though. Perhaps in later versions?

//A
• ###### 14. Re: Java-code scripts in Openscript and OLT reporting.
I very much doubt if this feature figures in the priority list. I can raise an ER though.

Cheers
Raj
1 2 Previous Next