Thucydides mark step failed and continue test execution - thucydides

I have thucydides + easyb.
I have some method with #Test annotation. For examle:
#Test
public void Step1(){
assertThat(true).isTrue();
}
#Test
public void Step2(){
assertThat(true).isFalse();
}
#Test
public void Step3(){
assertThat(true).isTrue();
}
In test story methods are execute in next order:
step1
step2
step3
In step2 AssertionError has threw. And step3 will skipped.
I need that step2 in report will marked as failed. And step3 will execute and mark as passed in report.
I can wrap assert in try catch, but I can't find any ways to mark step2 failed with thucydides callbacks.
Can anyone help me, please?

Related

Purging workflow after couple minutes

I have a Workflow step which if meet issues throw WorkflowException with a message and stacktrace, in effect - blocks whole workflow launcher with the payload. Finally, the workflow is indefinitely in the RUNNING state and does not handle any updates for blocked payload. This situation requires admin action to manually terminate the workflow.
There is how the simple workflow looks:
#Service
#Component
#Properties({
#Property(name = Constants.SERVICE_DESCRIPTION, value = "Workflow"),
#Property(name = "process.label", value = "Workflow Step") })
public class WorkflowStep implements WorkflowProcess {
#Override
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap)throws WorkflowException {
try {
... doing some stuff ...
} catch (Exception e) {
throw new WorkflowException(e.getMessage(), e);
}
}
}
I want to check after i.e 2 minutes if the workflow is COMPLETED if not - terminate them to unblock the payload and after upload the next asset into this path - again handle by the workflow.
Any idea how to solve it without using CRON Scheduler?
If you catch the exception, why don't you terminate the workflow right then instead of throwing a WorkflowException?
You could log whatever you want, handle the error and then terminate...
BR,
Oliver

Repeat tasklet step until certain condition

I used Spring batch to build a ETL job. My main job is simply read from a db and write to another one. Before my main job, I need to check a status in the source db to see if it is ready or not. I will proceed with the main job only if the source db is ready. I implemented the check status logic as a Tasklet and I build my job with the simple logic that if check status step failed repeat this step util the step succeed, then proceed with the main job. I build the job as follows:
#Bean
public Job myJob(MyListener listener) {
return jobBuilderFactory.get(jobName)
.incrementer(new RunIdIncrementer())
.listener(listener)
.start(checkStatusStep())
.on("*").to(mainStep())
.on(ExitStatus.FAILED.getExitCode())
.to(checkStatusStep())
.end()
.build();
}
The check status step is a tasklet as follows:
#Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws InterruptedException {
//isReady method check the db to see if it is ready
if (isReady()) {
//contribution.setExitStatus(ExitStatus.COMPLETED);
return RepeatStatus.FINISHED;
} else {
//contribution.setExitStatus(ExitStatus.FAILED);
return RepeatStatus.CONTINUABLE;
}
}
I read the spring batch document and get that the ON method in the conditional follow will check the exit status of the step so that I set the exit status in the StepContribution. What makes me confused is that when I comment those two lines out and the code still works.
So my question is, first, if the conditional flow checks the exit status why my code works without explicitly change the exit status? Second, why tasklet return a repeat status and by whom this repeat status is consumed.
Third, is there a better way to achieve my goal?
if the conditional flow checks the exit status why my code works without explicitly change the exit status?
Because by default if the tasklet returns RepeatStatus.FINISHED, its exit code will be set to COMPLETED
Second, why tasklet return a repeat status and by whom this repeat status is consumed.
A tasklet is called repeatedly by the TaskletStep until it either returns RepeatStatus.FINISHED or throws an exception to signal a failure. Each call to a Tasklet is wrapped in a transaction. The structure is therefore that of a loop with transaction boundary inside the loop.
Third, is there a better way to achieve my goal?
IMO, your Tasklet implementation is ok as is, you don't need the exit status. Something like:
#Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws InterruptedException {
//isReady method check the db to see if it is ready
if (isReady()) {
return RepeatStatus.FINISHED;
} else {
return RepeatStatus.CONTINUABLE;
}
}
This will continuously run until isReady is true, so you don't need to implement the iteration with a flow at the job level. The job definition would be:
#Bean
public Job myJob(MyListener listener) {
return jobBuilderFactory.get(jobName)
.incrementer(new RunIdIncrementer())
.listener(listener)
.start(checkStatusStep())
.next(mainStep())
.build();
}
Hope this helps.

How to Pause your script in selenium untill your Autoit script gets completed?

I want Selenium to wait untill and unless Autoit Script is completed.
Right Now whats happening is When I run TestNG.xml file it runs all the #Test Priority wise and within 5 sec TestNg output Console Shows all the #Test are Passed.
While my AutoIT scripts are still running parallely in background.
The Code is as Follows:
#Test (priority=1)
public void CreateNew() throws Exception
{
Runtime.getRuntime().exec("exeFiles\\CreateNew.exe");
}
#Test (priority=2)
public void OpenaFile() throws Exception
{
Runtime.getRuntime().exec("exeFiles\\OpenaFile.exe");
}
And the Code of AutoIt file is as Follows:
createnew()
Func createnew()
Sleep(2000)
Run("Mspaint.exe")
WinWaitActive("Untitled - Paint")
Send("!f")
Sleep(1000)
Send("n")
Sleep(2000)
WinClose("Untitled - Paint")
EndFunc ;==>createnew
You need to create a new process for AutoIt and wait for the process to complete. Look at below example.
#Test (priority=1)
public void CreateNew() throws Exception
{
Process p =Runtime.getRuntime().exec("exeFiles\\CreateNew.exe");
p.waitFor();
}
#Test (priority=2)
public void OpenaFile() throws Exception
{
Process p = Runtime.getRuntime().exec("exeFiles\\OpenaFile.exe");
p.waitFor();
}
p.waitFor() will make the current Thread to wait for the process.

Setting EXIT_MESSAGE in batch_job_execution

One of the step in my job is having an exception and hence the job is failing with the EXIT_CODE "FAILED". Now I want to set the EXIT_MESSAGE as well, I did the following but the message is not getting set.. Any ideas??
chunkContext.getStepContext().getStepExecution().getJobExecution().setExitStatus(ExitStatus.FAILED);
ExitStatus es = jobExecution.getExitStatus();
es = exitStatus.**addExitDescription**("CUSTOM EXCEPTION MESSAGE");
chunkContext.getStepContext().getStepExecution().getJobExecution().setExitStatus(es);
I also tried the following but didn't work.
setExitStatus(new ExitStatus("FAILED","CUSTOM EXCEPTION MESSAGE"));
The way to manipulate the exit status of a job (aka the Job's ExitStatus) is via a JobExecutionLisener. The way you're attempting to manipulate it is using a copy of the real thing. We do that so that rollback can be implemented cleanly. You can read more about the JobExecutionListener in the documentation here: http://docs.spring.io/spring-batch/apidocs/org/springframework/batch/core/JobExecutionListener.html
Gotcha!!!
Adding the listener at the job level and then giving a custom EXIT_CODE made it work.
Thanks Michael.
public class SampleJobListener implements JobExecutionListener {
#Override
public void beforeJob(JobExecution jobExecution) {
}
#Override
public void afterJob(JobExecution jobExecution) {
// Setting the exception in batch EXIT MESSAGE
jobExecution.setExitStatus(new ExitStatus("ERROR","Exception in JOB"));
}
}

Java Program output printed in random position in Eclipse console

I have a JUnit class in Eclipse project. It is like the following:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*some other imports*/
public class _JunitTests{
final Logger logger = LoggerFactory.getLogger(_JunitTests.class);
public void test(int num){
logger.info("**** tests no."+num+" ***");
/* some code */
}
#Test
public static void test1() {
test(1);
}
#Test
public static void test2() {
test(2);
}
#Test
public static void test3() {
test(3);
}
#Test
public static void test1() {
test(1);
}
}
When I run all the tests, I was expecting output such as[class information of info is ignored]
**** tests no.1 ***
/* somethings */
**** tests no.2 ***
/* somethings */
**** tests no.3 ***
/* somethings */
However, the result shown in console is usually messed up like:
**** tests no.1 ***
**** tests no.2 ***
**** tests
/* somethings */
no.3 ***
/* somethings */
/* somethings */
This happens a lot before with my other codes when there are Exception messages.
My guess before is stderr and stdout are handled in different threads, and so the result would be displayed without a certain order.
Since the info from Logger is also red in Eclipse console, my guess is that it uses stderr to display the message? is it the case? if so, is there a way to solve the problem of messed up order? thanks.
Which logging framework do you use with SLF4J? It could be that the logging framework is configured to write the log messages asynchronously in a background thread.
You can try to replace the log call with a System.out.println() and see if that produces the output you expect. If it does you may want to reconfigure the logging framework to log the messages synchronously.