How to analyze ant build output for further decision making? - java

I'm writing an ant build script to run regression tests for an application. I need to run the test cases sequentially and only if the previous test run was successful. Is there a way I can look a the output of the build to decide if the next target can be called?
[exec] [revBuild] RC = 1
[exec] -------------------------------------------------
[exec] Result: 1
BUILD SUCCESSFUL
Total time: 3 minutes 23 seconds
In the above output, the called application has failed. Is there a way I can search for the application return code in the build output, based on which the next ant target(to run the next test case) can be called?

You probably just want to set the failonerror attribute of the exec task to true. If you do this and the executable's return status code is anything other than 0, then the buildwill fail.
Youi could also store this status code in a property using the resultproperty attribute, and execute some task only if this property is set (or is not set).

Related

Gradle not building java application consistently

I am trying to understand gradle.
I followed the gradle tutorial here: https://docs.gradle.org/current/samples/sample_building_java_applications.html#what_youll_build
In short:
I created a folder: mkdir demo
cd demo
gradle init (so far so good)
Now, I tried to run my application like this: gradlew run.
The first run of the application was successful. However, the subsequent runs kept failing and I got a very non descript error.
> Task :app:run FAILED
Error: Could not find or load main class demo.App
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:run'.
> Process 'command 'C:\Program Files\Java\jdk1.8.0_211\bin\java.exe'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 3s
2 actionable tasks: 1 executed, 1 up-to-date
Then, I deleted the files inside "Z:\Projects\demo\ .gradle\6.7.1\executionHistory" and I was able to run the application again.
This was happening again and again. Please see attached screenshot:
What am I doing wrong -- how do I fix this so that all calls to 'gradlew run' give me a successful build?
Edit:
I tried it on C: and was able to do 'gradlew run' consistently and get
the 'Hello World' output without any issues. My Z drive is actually an
encrypted VeraCrypt file which has been loaded with letter 'Z'. Not
sure if that is causing problems.
Thanks!
Hello I was facing the issue too, spend a lot of time and now I am sure, that the issue is the file system. I believe that your encrypted partition is using exFAT. Gradle is not able to process this file system properly.

Robot - how to check if the execution of a jar is finished

I would like to run a jar file using a robot framework test suite, because this test-case is to be included among other test cases.
When the jar is run from the cmd, it produces the expected output, which can take 10 minutes, and then it ends.
My issue is that I'm not capable to detect when the execution of the jar is finished. I tried several keywords combination, in the last attempt I used the keyword Process Should Be Stopped, as shown below, and the result is that the process is always running.
One of my doubts is: which process is running, java? or the execution of the jar?
*** Settings ***
Library Process
Library OperatingSystem
Suite Setup log running on ${properties.hostname}
Suite Teardown Terminate All Processes kill=True
Variables C:/Users/theUser/Desktop/CheckOutRegression/Regression/RegressionScripts/config/properties.py
*** Test Cases ***
Check jar execution
${data}= Start Process java -jar da-1.0-SNAPSHOT.jar importFile1.json importFile2.zip cwd=${properties.pathToScripts} alias=myProc
${wait}= Wait Until Keyword Succeeds 10x 60s Process Should Be Stopped myProc
Log ${wait}
${result}= Get Process Result myProc
Log ${data.stdout}
Do you know how I can check that the execution of the jar file is finished?

Gradle Task Not Running After Test

I have integration tests setup in my build.gradle file as such:
task integrationSetup(dependsOn: jar, type: Exec) {
workingDir "$projectDir/resources/integration"
commandLine 'sh', './start_service.sh'
}
task testIntegration(dependsOn: integrationSetup, type: Test) {
testClassesDirs = sourceSets.testIntegration.output.classesDirs
classpath = sourceSets.testIntegration.runtimeClasspath
ignoreFailures = true
}
task integrationTearDown(dependsOn: testIntegration, type: Exec) {
workingDir "$projectDir/resources/integration"
commandLine 'sh', './stop_service.sh'
}
testIntegration.mustRunAfter integrationSetup
testIntegration.finalizedBy integrationTearDown
integrationTearDown.mustRunAfter testIntegration
However since upgrading the Gradle Wrapper to version 4+ the tasks no longer execute correctly. The final tear down never runs and the service continues. What has changed between version 3 and 4 to change this behaviour. Pretty upsetting Gradle did this without warning or deprecation notices.
One dumb option is to downgrade the Gradle wrapper version (can confirm this setup still works on 3.1). But that shouldn't be necessary IMO.
UPDATE: Made some changes per user #Opal. However still have issue where if any errors occur during integration tests the final tear down does not run.
> Task :compileTestIntegrationJava
Putting task artifact state for task ':compileTestIntegrationJava' into context took 0.0 secs.
file or directory '/home/project/cleaner/src/testIntegration/java', not found
file or directory '/home/project/cleaner/src/testIntegration/java', not found
Executing task ':compileTestIntegrationJava' (up-to-date check took 0.072 secs) due to:
Output property 'destinationDir' file /home/project/cleaner/build/classes/java/testIntegration has changed.
Output property 'destinationDir' file /home/project/cleaner/build/classes/java/testIntegration/com has been removed.
Output property 'destinationDir' file /home/project/cleaner/build/classes/java/testIntegration/com/project has been removed.
All input files are considered out-of-date for incremental task ':compileTestIntegrationJava'.
file or directory '/home/project/cleaner/src/testIntegration/java', not found
Compiling with JDK Java compiler API.
/home/project/cleaner/src/integration/java/com/project/cleaner/CleansRequestsTests.java:415: error: reached end of file while parsing
}
^
1 error
:compileTestIntegrationJava (Thread[Daemon worker Thread 8,5,main]) completed. Took 0.162 secs.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileTestIntegrationJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.
BUILD FAILED in 8s
8 actionable tasks: 8 executed
Stopped 0 worker daemon(s).
In discussion it turned out that OP wants to stop the service started before running test no matter what e.g. compilation errors. It can be done with the following script:
ext.integrationTearDown = {
workingDir "$projectDir/resources/integration"
commandLine 'sh', './stop_service.sh'
}
task(type: Exec, 'stop_service', integrationTearDown)
gradle.buildFinished {
exec integrationTearDown
}
testIntegration.dependsOn integrationSetup
testIntegration.finalizedBy stop_service
With this piece of code the service will be stopped after every build - event if it succeeds. To avoid this behaviour BuildResult which is passed to buildFinished may be used to determine the required behaviour.

Run same jar file sequentially in a loop for different inputs

Am executing a jar file in remote server using jenkins job build step through publish over ssh.
Input build parameters for the job,say list - a,b,c,d,e
Execution command for publish over ssh -
cd /myjarfilepath
for input in $list
do
java -Xmx1024m -cp myApp.jar com.CommandLineRunner $input
done
job fails with error
ERROR: Exception when publishing, exception message [Exec timed out or was interrupted after 120,000 ms]
It runs successfully for one input. Say if it fails for input b then it gets terminated without executing the jar for c,d,e. I want execute the jar for all the inputs available.
Any suggestions will be appreciated!
Thanks.
Yes this is because of default timeout set to=120000. By updating transfers->Advanced->Exec Timeout(ms). I was able to build for all in loop successfully.

JAVA(TM) binary has stopped working while ant converts .jmx to .jtl

I'm trying to generate HTML reports of jmeter files using apache ant. while running the test .jmx file tries to convert itself into .jtl file, at that time java binary has not working pop appears and build fails.
D:\softwares\apache-jmeter-2.13\apache-jmeter-2.13\extras>ant -Dtest=RetailerPor
tal
Picked up _JAVA_OPTIONS: -Xmx256M
Buildfile: D:\softwares\apache-jmeter-2.13\apache-jmeter-2.13\extras\build.xml
run:
[echo] funcMode = false
[jmeter] Executing test plan: D:\softwares\apache-jmeter-2.13\apache-jmeter-2
.13\extras\RetailerPortal.jmx ==> D:\softwares\apache-jmeter-2.13\apache-jmeter-
2.13\extras\RetailerPortal.jtl
_message_xalan:
xslt-report:
BUILD FAILED
D:\softwares\apache-jmeter-2.13\apache-jmeter-2.13\extras\build.xml:132: input f
ile D:\softwares\apache-jmeter-2.13\apache-jmeter-2.13\extras\RetailerPortal.jtl
does not exist
Total time: 17 seconds
According to the output it fails during execution of the JMeter test, most likely due to low Java Heap Size value (-Xmx256M). Check out jmeter.log file - it usually contains all the necessary information.
Add the following line to <jmeter> section of your build.xml file:
<jvmarg value="-Xmx1234M"/>
or set it via ANT_OPTS environment variable on OS level like:
set ANT_OPTS=-Xmx1234M
Replace 1234 with memory size (in megabytes) you want to make available to JMeter (I would go for 70% - 80% of your total physical RAM amount)
See 9 Easy Solutions for a JMeter Load Test “Out of Memory” Failure guide for more JMeter tweaks, tips and tricks
Increasing the RAM size works fine.
Please check about Test.jtl file which is created in apacheant\bin. You might have created a new test documet and replaced its name with Test.jtl simply... Try to open it and save as it with .jtl extension... Make sure you've removed .txt.

Categories

Resources