Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » Waiting for a job in a unit test?
Waiting for a job in a unit test? [message #1446846] Fri, 17 October 2014 11:48 Go to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 1252
Registered: October 2011
Senior Member
In our project we use a Job to refresh the whole form during execChangedValue(). We have a Junit test with a Scout Context where the Server is mocked.

Since the introduction of the Job (to solve loop detection problems), we have the problem that the Unit no longer works. Here some code:
// install the mocked services with TestingUtility.registerServices(..)

// The process service defined the behavior for: load() and calculate()
// * loadFormData for OtherField contains LOADED_VALUE
// * calcFormData for OtherField contains CALCULATED_VALUE

when(service.load(any(MyFormData.class))).thenReturn(loadFormData);
when(service.calculate(any(MyFormData.class))).thenReturn(calcFormData);

Form f = new Form();
f.startNew();
assertEquals(LOADED_VALUE, f.getOtherField().getValue());

f.getMyField().setValue(NEW_VALUE); //<= this triggers a calculate job

// TODO: how to tell the test he should wait on the calculate_job?

assertEquals(CALCULATED_VALUE, f.getOtherField().getValue());

verify(service, times(1)).calculate(any(MyFormData.class));


The assertion for the calculated value is not working.
When I debug, I see that I have a job/threading problem.

Thank you in advance.

.
Re: Waiting for a job in a unit test? [message #1446884 is a reply to message #1446846] Fri, 17 October 2014 13:04 Go to previous messageGo to next message
Matthias Villiger is currently offline Matthias VilligerFriend
Messages: 232
Registered: September 2011
Senior Member
Without having tested it, just as an idea: Have you tried to join the job family?

e.g. the following snippet if you are using ClientSyncJobs:

Job.getJobManager().join(ClientSyncJob.class, null);



regards
matthias
Re: Waiting for a job in a unit test? [message #1447378 is a reply to message #1446884] Sat, 18 October 2014 06:54 Go to previous message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 1252
Registered: October 2011
Senior Member
Thanks for your proposition.

My first tests show that it produces a dead-lock.

I have also tried to make another job family (CalculateClientSyncJob extends ClientSyncJob).
Previous Topic:How integrate image in a JasperReport
Next Topic:Mockito Spy and inner classes
Goto Forum:
  


Current Time: Fri Apr 26 09:12:07 GMT 2024

Powered by FUDForum. Page generated in 0.03375 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top