in a WSADMIN jacl Script how i can get wsadmin.properties values ?
for example the "com.ibm.ws.scripting.traceFile" ?
i already try with
puts $com.ibm.ws.scripting.traceFile
buts return
can't read "com.ibm.ws.scripting.traceFile": no such variable
while executing
"puts $com.ibm.ws.scripting.traceFile"
The values stored in wsadmin.properties are loaded into the JVM, and are stored as System Properties. You can obtain the values of these properties by working with Java's java.lang.System object, and then retrieving the specific property you want:
Here's the JACL code:
package require java
set sysprops [java::call System getProperties]
set traceFile [[$sysprops get com.ibm.ws.scripting.traceFile] toString]
puts "trace file: $traceFile"
For anyone interested, here's the Jython equivalent:
from java.lang import System as javasystem
sysprops = javasystem.getProperties()
traceFile = sysprops.get('com.ibm.ws.scripting.traceFile')
print "traceFile: " + traceFile
Related
I am running a JAVA Mainframe JAR. It is working successfully using the IBM JVMLDM fro z/OS. My next step was to integrate an in-house logging framework. I am required to pass several environment variables(user system properties) into the JVM using a STDENV DD statement in the JCL. I am using the environment variables provided by IBM (documentation) within a PARM file as follows:
IJO="$IJO -DCAR_PROP=6123548595"
EXPORT IBM_JAVA_OPTIONS="$IJO "
I am also using the following environment variable in a similar manner:
IJO="$IJO -DCAR_PROP=6123548595"
EXPORT JZOS_JVM_OPTIONS="$IJO "
Neither of these options are working as the property still fails to be captured by the JAR. Looking for some insight as to what might be the issue with the statement with which I may not be familiar.
DOCUMENTATION
https://www.ibm.com/support/knowledgecenter/SSLTBW_2.1.0/com.ibm.zos.v2r1.iean500/bcdbatch.htm
Does using lower-case export work? i.e.
IJO="$IJO -DCAR_PROP=6123548595"
export IBM_JAVA_OPTIONS="$IJO "
I'm using Jmeter to design a test that requires data to be randomly read from text files. To save memory, I have set up a "setUp Thread Group" with a BeanShell PreProcessor with the following:
//Imports
import org.apache.commons.io.FileUtils;
//Read data files
List items = FileUtils.readLines(new File(vars.get("DataFolder") + "/items.txt"));
//Store for future use
props.put("items", items);
I then attempt to read this in my other thread groups and am trying to access a random line in my text files with something like this:
(props.get("items")).get(new Random().nextInt((props.get("items")).size()))
However, this throws a "Typed variable declaration" error and I think it's because the get() method returns an object and I'm trying to invoke size() on it, since it's really a List. I'm not sure what to do here. My ultimate goal is to define some lists of data once to be used globally in my test so my tests don't have to store this data themselves.
Does anyone have any thoughts as to what might be wrong?
EDIT
I've also tried defining the variables in the setUp thread group as follows:
bsh.shared.items = items;
And then using them as this:
(bsh.shared.items).get(new Random().nextInt((bsh.shared.items).size()))
But that fails with the error "Method size() not found in class'bsh.Primitive'".
You were very close, just add casting to List so the interpreter will know what's the expected object:
log.info(((List)props.get("items")).get(new Random().nextInt((props.get("items")).size())));
Be aware that since JMeter 3.1 it is recommended to use Groovy for any form of scripting as:
Groovy performance is much better
Groovy supports more modern Java features while with Beanshell you're stuck at Java 5 level
Groovy has a plenty of JDK enhancements, i.e. File.readLines() function
So kindly find Groovy solution below:
In the first Thread Group:
props.put('items', new File(vars.get('DataFolder') + '/items.txt').readLines()
In the second Thread Group:
def items = props.get('items')
def randomLine = items.get(new Random().nextInt(items.size))
I want to use the name of the jmeter test script (.jmx) in a listener so as to generate the result file in a dynamic way. Can you please tell me what is the Jmeter variable for that purpose?
Used ${fileName} which didn't work
You can do it via Beanshell scripting like:
GUI mode
import org.apache.jmeter.gui.GuiPackage;
String scriptName = GuiPackage.getInstance().getTestPlanFile();
vars.put("scriptName", scriptName);
non-GUI mode
import org.apache.jmeter.services.FileServer;
String scriptName = FileServer.getFileServer().getScriptName();
vars.put("scriptName", scriptName);
Put the code snippet of your choice into any "Beanshell" test element (sampler, pre/post processor, or assertion), it will get .jmx test script name and store it into ${scriptName} variable.
To learn more about Beanshell scripting in JMeter check out How to use BeanShell: JMeter's favorite built-in component guide.
The variable that holds the test plan name is ${__TestPlanName}
Ref: http://jmeter.apache.org/usermanual/functions.html#__TestPlanName
Below would work irrespective of GUI / Non GUI mode:
import org.apache.jmeter.services.FileServer;
import java.io.File;
String testPlanFile = FileServer.getFileServer().getBaseDir() +
File.separator +
FileServer.getFileServer().getScriptName();
props.put("testPlanFile", testPlanFile);
Use this as ${__P(testPlanFile)} - Adding it as var would not work across all threads. From http://jmeter.apache.org/usermanual/functions.html -
Properties are not the same as variables. Variables are local to a
thread; properties are common to all threads, and need to be
referenced using the __P or __property function.
for some test I need to run a data driven test with a configuration that is generated (via reflection) in the ClassInitialize method (by using reflection). I tried out everything, but I just can not get the data source properly set up.
The test takes a list of classes in a csv file (one line per class) and then will test that the mappings to the database work out well (i.e. try to get one item from the database for every entity, which will throw an exception when the table structure does not match).
The testmethod is:
[DataSource(
"Microsoft.VisualStudio.TestTools.DataSource.CSV",
"|DataDirectory|\\EntityMappingsTests.Types.csv",
"EntityMappingsTests.Types#csv",
DataAccessMethod.Sequential)
]
[TestMethod()]
public void TestMappings () {
Obviously the file is EntityMappingsTests.Types.csv. It should be in the DataDirectory.
Now, in the Initialize method (marked with ClassInitialize) I put that together and then try to write it.
WHERE should I write it to? WHERE IS THE DataDirectory?
I tried:
File.WriteAllText(context.TestDeploymentDir + "\\EntityMappingsTests.Types.csv", types.ToString());
File.WriteAllText("EntityMappingsTests.Types.csv", types.ToString());
Both result in "the unit test adapter failed to connect to the data source or read the data". More exact:
Error details: The Microsoft Jet database engine could not find the
object 'EntityMappingsTests.Types.csv'. Make sure the object exists
and that you spell its name and the path name correctly.
So where should I put that file?
I also tried just writing it to the current directory and taking out the DataDirectory part - same result. Sadly, there is limited debugging support here.
Please use the ProcessMonitor tool from technet.microsoft.com/en-us/sysinternals/bb896645. Put a filter on MSTest.exe or the associate qtagent32.exe and find out what locations it is trying to load from and at what point in time in the test loading process. Then please provide an update on those details here .
After you add the CSV file to your VS project, you need to open the properties for it. Set the Property "Copy To Output Directory" to "Copy Always". The DataDirectory defaults to the location of the compiled executable, which runs from the output directory so it will find it there.
My group does a lot of test automation with JM. Typically we have a properties file which has a bunch of variables defined. These in turn are mapped to "User Defined Variables" of which we have a number of different sets.
These are in referenced throughout the rest of the jmx - I find it difficult as there are so many variables in so many different places to know what is what. Is there any way to have jmeter display what values its variables have - custom sampler is fine ? Ideally id love it if you could just hover a var and have its value displayed.
Any ideas ?
The newest versions of Jmeter have a fantastic sampler called "Debug Sampler" that will show you the values for: Jmeter Variables, Jmeter Properties or System properties.
You can insert them wherever you want in the script to get values at a given time. You'll want to have a "View Results Tree" enabled to view the sampler.
Given that Jmeter declares variables from a file on run, you won't be able to get your ideal solution.
I'm curious...would it be cleaner to employ "CSV Data Set Config" rather then populating "User Defined Variables" from a properties file?
Edit: Added explanation on variable declaration and asked CSV question.
Here is how I used to get Set of vars right through the code (variant with Java code in JSR223 PostProcessor):
Add "JSR223 PostProcessor" by right click wherever you need to check jMeter variables in your project;
Set Language (in my case - to java);
Add following code to Script window:
import java.util.Map;
String jMeterVars;
jMeterVars = "Quantity of variables: " + vars.entrySet().size() + ".\n\n";
jMeterVars += "[VARIABLE NAME] ==>> [VARIABLE VALUE]\n\n";
for (Map.Entry entry : vars.entrySet()) {
jMeterVars += entry.getKey() + " ==>> " + entry.getValue().toString() + "\n";
}
try {
FileWriter fw = new FileWriter("D:\\jMeterVarsForStackOverflow.txt",true);
fw.write(jMeterVars);
fw.close();
} catch(IOException ioe) {
System.err.println("IOException: " + ioe.getMessage());
}
Check that everything in the JSR223 PostProcessor looks like that:
Start your project in jMeter.
The code above will create jMeterVarsForStackOverflow.txt file at D: and put all variables there: