Hi Stefan,

Thank you for your response.
I think the null check on the job is indeed the problem.

I added this check, because it seems that when after the job is finished
(handled) it also becomes null, and I have no longer the possibility to
retrieve the jobState from this object.

So in the current code I cannot use the null check to determine if the job
has finished (as it might not be created yet), but if the job is already
finished and has become null I would need the null check.

Basically I'm searching for a better way to determine when the job is
finished.


Thanks

Johan

2017-12-20 11:34 GMT+01:00 Stefan Egli <[email protected]>:

> Hi Johan,
>
> Could it be that your jobFinised() method returns true since job == null,
> which could be the case shortly before/while the job is even being
> created? Ie it could be a race condition at the start of the job (and by
> adding a 5sec sleep you give it enough time to start + finish).
>
> Cheers,
> Stefan
>
> On 19.12.17, 17:34, "Johan Ruttens" <[email protected]> wrote:
>
> >Hi,
> >
> >I'm working on a (Adobe AEM) integration test, where the test methods
> >depend on a job being finished, before the methods can be executed with
> >success.
> >
> >The scenario of the job is a follows:
> >1. Copy a page to be used as a test resource (using the PageManager.copy
> >method)
> >2. Trigger a job (using the JobManager.add method)
> >3. The job will alter some properties on the AEM page
> >4. Wait until the job has finished
> >5. Execute the tests to check if the properties have been changed
> >correctly.
> >
> >
> >The problem is that the integration tests sometimes succeed and sometimes
> >they do not succeed (i.e. properties are not changed correctly).
> >I suspect this is caused by the way we check if the job is finished:
> >
> >
> >@Test
> > public void testIfPageIsCorrectTranslated() throws LoginException,
> >RepositoryException, InterruptedException, WCMException {
> >        boolean finished = false;
> >        while (!finished) {
> >            Job runningJob = jobManager.getJobById(job.getId());
> >            finished = jobFinised(runningJob);
> >        }
> >............
> >
> >}
> >
> >.....
> >
> >private boolean jobFinised(final Job job) {
> >    return job == null || job.getJobState().equals(Job.
> JobState.SUCCEEDED)
> >            || job.getJobState().equals(Job.JobState.ERROR) ||
> >job.getJobState().equals(Job.JobState.STOPPED);
> >}
> >
> >
> >When I add a Thread.sleep(5000) after the while loop, all the tests
> >succeed
> >all of the time.
> >
> >
> >Thanks for the help.
>
>
>

Reply via email to