final CalculationJob job = new CalculationJob(createJobSpecification(), 0, VersionCorrection.LATEST, null, Arrays.asList(JOB_ITEM_A, JOB_ITEM_AB, JOB_ITEM_BC, JOB_ITEM_BCD),
CacheSelectHint.sharedValues(Arrays.asList(VS_D)));
final JobResultReceiver receiver = Mockito.mock(JobResultReceiver.class);
final StandardJob standard = new StandardJob(dispatcher, job, receiver);
final WatchedJob watched = new WatchedJob.Whole(standard, job, receiver);
final DispatchableJob split = watched.prepareRetryJob(null);
final CalculationJob job1 = split.getJob();
assertEquals(job1.getJobItems(), Arrays.asList(JOB_ITEM_A, JOB_ITEM_AB));
assertTrue(job1.getCacheSelectHint().isPrivateValue(VS_A));
assertFalse(job1.getCacheSelectHint().isPrivateValue(VS_B));
final CalculationJobResult result1 = new CalculationJobResult(job1.getSpecification(), 0, Arrays.asList(CalculationJobResultItem.success(), CalculationJobResultItem.success()), "1");
split.getResultReceiver(result1).resultReceived(result1);
Mockito.verifyZeroInteractions(receiver);
assertEquals(dispatched.size(), 1);
final DispatchableJob next = dispatched.poll();
final CalculationJob job2 = next.getJob();
assertEquals(job2.getJobItems(), Arrays.asList(JOB_ITEM_BC, JOB_ITEM_BCD));
assertFalse(job2.getCacheSelectHint().isPrivateValue(VS_B));
assertTrue(job2.getCacheSelectHint().isPrivateValue(VS_C));
assertFalse(job2.getCacheSelectHint().isPrivateValue(VS_D));
final CalculationJobResult result2 = new CalculationJobResult(job2.getSpecification(), 0, Arrays.asList(CalculationJobResultItem.failure("Foo", "Bar"), CalculationJobResultItem.success()), "2");
next.getResultReceiver(result2).resultReceived(result2);
Mockito.verify(receiver).resultReceived(
new CalculationJobResult(job.getSpecification(), 0, Arrays.asList(CalculationJobResultItem.success(), CalculationJobResultItem.success(), CalculationJobResultItem.failure("Foo", "Bar"),
CalculationJobResultItem.success()), "1, 2"));
assertTrue(job1.getSpecification().getJobId() != job2.getSpecification().getJobId());
assertTrue(job2.getSpecification().getJobId() == job.getSpecification().getJobId());