What does -Dauto means - java

I saw the fallowing command for starting Selenium:
java -Xmx256m -Dauto=1 -jar selenium-server-standalone-2.25.0.jar -log /home/test/selenium.log -trustAllSSLCertificates
I googled to find what -Dauto=1 means but failed.

I'm pretty sure auto is no valid parameter in a current version of Selenium server. It might have been in the past or it was just used by some custom implementation.
java -jar selenium-server-standalone-2.25.0.jar -h
will list you all available parameters for Selenium, which you can set by adding
-D<variable>=<value>
to your start command.

-D is an important switch that allows you to set environment properties.
-Dproperty=value
Set a system property value. If value is a string that contains spaces, you must enclose the string in double quotes:
java -D<propertyName>=<propertyValue>
You can call the following from anywhere in the code to read it.
String value = System.getProperty("propertyName");
or
String value = System.getProperty("propertyName", "defaultValue");

Related

How to execute bash script using karate and fail if script fails

I'm trying to execute bash script using karate. I'm able to execute the script from karate-config.js and also from .feature file. I'm also able to pass the arguments to the script.
The problem is, that if the script fails (exits with something else than 0) the test execution continues and finishes as succesfull.
I found out that when the script echo-es something then i can access it as a result of the script so I could possibly echo the exit value and do assertion on it (in some re-usable feature), but this seems like a workaround rather than a valid clean solution. Is there some clean way of accessing the exit code without echo-ing it? Am I missing on something?
script
#!/bin/bash
#possible solution
#echo 3
exit 3;
karate-config.js
var result = karate.exec('script.sh arg1')
feture file
def result = karate.exec('script.sh arg1')
Great timing. We very recently did some work for CLI testing which I am sure you can use effectively. Here is a thread on Twitter: https://twitter.com/maxandersen/status/1276431309276151814
And we have just released version 0.9.6.RC4 and new we have a new karate.fork() option that returns an instance of Command on which you can call exitCode
Here's an example:
* def proc = karate.fork('script.sh arg1')
* proc.waitSync()
* match proc.exitCode == 0
You can get more ideas here: https://github.com/intuit/karate/issues/1191#issuecomment-650087023
Note that the argument to karate.fork() can take multiple forms. If you are using karate.exec() (which will block until the process completes) the same arguments work.
string - full command line as seen above
string array - e.g. ['script.sh', 'arg1']
json where the keys can be
line - string (OR)
args - string array
env - optional environment properties (as JSON)
redirectErrorStream - boolean, true by default which means Sys.err appears in Sys.out
workingDir - working directory
useShell - default false, auto-prepend cmd /c or sh -c depending on OS
And since karate.fork() is async, you need to call waitSync() if needed as in the example above.
Do provide feedback and we can tweak further if needed.
EDIT: here's a very advanced example that shows how to listen to the process output / log, collect the log, and conditionally exit: fork-listener.feature
Another answer which can be a useful reference: Conditional match based on OS
And here's how to use cURL for advanced HTTP tests ! https://stackoverflow.com/a/73230200/143475
In case you need to do a lot of local file manipulation, you can use the karate.toJavaFile() utility so you can convert a relative path or a "prefixed" path to an absolute path.
* def file = karate.toJavaFile('classpath:some/file.txt')
* def path = file.getPath()

problem running several command over SSH with JSch [duplicate]

I am slowly trying to make a python script to SSH then FTP to do some manual file getting I have to do all the time. I am using Paramiko and the session seems to command, and prints the directory but my change directory command doesn't seem to work, it prints the directory I start in: /01/home/.
import paramiko
hostname = ''
port = 22
username = ''
password = ''
#selecting PROD instance, changing to data directory, checking directory
command = {
1:'ORACLE_SID=PROD',2:'cd /01/application/dataload',3:'pwd'
}
ssh=paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname,port,username,password)
for key,value in command.items():
stdin,stdout,stderr=ssh.exec_command(value)
outlines=stdout.readlines()
result=''.join(outlines)
print (result)
ssh.close()
When you run exec_command multiple times, each command is executed in its own "shell". So the previous commands have no effect on an environment of the following commands.
If you need the previous commands to affect the following commands, just use an appropriate syntax of your server shell. Most *nix shells use a semicolon or an double-ampersand (with different semantics) to specify a list of commands. In your case, the ampersand is more appropriate, as it executes following commands, only if previous commands succeed:
command = "ORACLE_SID=PROD && cd /01/application/dataload && pwd"
stdin,stdout,stderr = ssh.exec_command(command)
In many cases, you do not even need to use multiple commands.
For example, instead of this sequence, that you might do when using shell interactively:
cd /path
ls
You can do:
ls /path
See also:
How to get each dependent command execution output using Paramiko exec_command
Obligatory warning: Do not use AutoAddPolicy on its own – You are losing a protection against MITM attacks by doing so. For a correct solution, see Paramiko "Unknown Server".
Well by accidentally trying something I managed to figure this out I believe. You need to do all the commands at one time and do not need to do them in a loop. for for my instance it would be
import paramiko
hostname = ''
port = 22
username = ''
password = ''
#selecting PROD instance, changing to data directory, checking directory
command = 'ORACLE_SID=PROD;cd /01/application/dataload;pwd'
ssh=paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname,port,username,password)
stdin,stdout,stderr=ssh.exec_command(value)
outlines=stdout.readlines()
result=''.join(outlines)
print (result)
ssh.close()

A literal string containing escape slashes on groovy

My groovy script calls other commands via vagrant. One of those commands is to echo some quotes on a file within docker.
The goal is, so that within the container, i want to have BB_GENERATE_MIRROR_TARBALLS = "1". Now to do this on a bash script, i would need something like this:
BB_GENERATE_MIRROR_TARBALLS = \"1\"
The issue manifests itself when i have to escape double quotations on the groovy as well.
If i call vagrant("echo BB_GENERATE_MIRROR_TARBALLS = \\\"1\\\" >> ${yoctoDir}/build/conf/local.conf" on my groovy file, the outcome on the local.conf will be BB_GENERATE_MIRROR_TARBALLS=1 (without quotes).
The correct way to do this would be to include an extra backslash on both sides (3 for the groovy, 1 for the bash script), however when i do that, groovy doesnt run and gives me syntax errors.
What would be the correct way to insert this literal string(BB_GENERATE_MIRROR_TARBALLS=\"1\") on the groovy?
In groovy you can do the following:
def my_var = /BB_GENERATE_MIRROR_TARBALLS = "1"/
echo my_var >> ${yoctoDir}/build/conf/local.conf

Dropwizard Enviornment Variable Substitution Type Check Error

I'm a Dropwizard newbie and am using an existing Dropwizard service, where I am attempting to create YML values that are overridable depending on the environment that my service is deployed to (i.e. Dev, QA, Prod). I tried Googling my error message, but really didn't find a whole lot for this specific error, so I thought that I would post a new question for this.
When I run my script that starts the service, I get the following error:
my-host:my-service jthoms$ ./start.sh 3.0.0
Starting my-service...
src/main/resources/configuration.yml has an error:
* Incorrect type of value at: downstream_service.loggingEnabled; is of type: String, expected: boolean
Note that I have already created a MyServiceConfiguration class which extends Dropwizard's main Configuration class and delegates to a DownstreamServiceConfiguration class that has a boolean field for the loggingEnabled property. I did this in accordance with the Dropwizard Core doc.
My start.sh script is as follows:
#!/bin/sh
if [ "$#" -ne 1 ]; then
echo "Please pass jar version! Usage: ./start.sh <jar_version>"
exit 1
fi
echo "Starting my-service with version '$1'"
java $DEBUG_ARGS -Xmx128m -jar target/my-service-$1.jar server src/main/resources/configuration.yml
My configuration.yml is as follows:
server:
...
downstream_service:
loggingEnabled: ${DW_DOWNSTREAM_SERVICE_LOGGING_ENABLED}
...
logging:
...
I don't understand what's causing this type safety error. How can I import my environment variables to Dropwizard as a non-string type?
After some Googling around, I found the solution(s) to my issue, and thought that I would share my answer here for others with the same error message I was getting.
The problem wasn't that my boolean DW_DOWNSTREAM_SERVICE_LOGGING_ENABLED environment was being treated as a string, the problem was the boolean YML property just wasn't being wired up correctly, so the string value it was finding wasn't the string literal, true. Rather, it was the string literal ${DW_DOWNSTREAM_SERVICE_LOGGING_ENABLED}. Basically, Dropwizard just wasn't substituting ${DW_DOWNSTREAM_SERVICE_LOGGING_ENABLED} for true in the first place.
The solution involved two things:
Call the script that actually creates the environment variables from my start.sh script. I had actually forgotten to do this. Doh!
Configure the application's bootstrap to use an EnvironmentVariableSubstitutor as per this answer. Note that you don't need to set the EnvironmentVariableSubstitutor to use non-strict checking, the shell variables aren't being unconditionally interpreted as strings by Dropwizard. The following code needs to be added to your main Application class.
#Override
public void initialize(Bootstrap<MyServiceConfiguration> bootstrap) {
bootstrap.setConfigurationSourceProvider(
new SubstitutingSourceProvider(bootstrap.getConfigurationSourceProvider(),
new EnvironmentVariableSubstitutor()));
}
Those two things combined solved the problem.

Check programatically (without string-matching) whether using IPV6 or IPV4 for JVM

I want to check whether JVM options for a particular application (in this case, Matlab) have been set to prefer IPV4 or if they still use IPV6.
I know how to set the JVM to prefer IPV4. In my case, it can be done by adding the line
-Djava.net.preferIPv4Stack=true
to the java.opts file within $MATLABROOT/bin/maci64/.
I can also check whether this line has already been added to java.opts via string-matching. I've pasted my current solution (a Matlab script that checks for string-match, and adds the line if it does not exist) at the bottom of this question.
I don't know how, though, to check whether IPV4 or IPV6 is preferred without string-matching. Obviously this seems preferred.
Does anybody know how to check IPV4 vs. IPV6 in the JVM without string-matching?
Here's my current solution, that depends on string-matching:
% OSX platform-specific: revert to IPv4
if (computer('arch') == 'maci64')
javaoptspath = fileread([matlabroot '/bin/' computer('arch') '/java.opts']);
k = strfind(javaoptspath, '-Djava.net.preferIPv4Stack=true');
if isempty(k)
setenv('DRAKE_IPV4_SET_MATLABROOT', matlabroot)
setenv('DRAKE_IPV4_SET_ARCH', computer('arch'))
display('Since you are on Mac, we will need to set your JVM to prefer IPV4 instead of IPV6 for MATLAB')
display('Please enter your sudo password below')
! (echo "" | echo "-Djava.net.preferIPv4Stack=true") | sudo tee -a $DRAKE_IPV4_SET_MATLABROOT/bin/$DRAKE_IPV4_SET_ARCH/java.opts
end
end
You can access the underlying java system properties without parsing the options string by using the java.lang.System class directly from Matlab.
For example:
ipv4_preferred = java.lang.System.getProperty('java.net.preferIPv4Stack')
The result of getProperty will be empty if the user has not set -Djava.net.preferIPv4Stack=..., so a more complete solution might be:
ipv4_preferred = java.lang.System.getProperty('java.net.preferIPv4Stack');
if isempty(ipv4_preferred)
ipv4_preferred = false;
end

Categories

Resources