Esempio n. 1
0
 public void testWatchedJob_prepareRetryJob_split_one() {
   final Queue<DispatchableJob> dispatched = new LinkedList<DispatchableJob>();
   final JobDispatcher dispatcher =
       new JobDispatcher() {
         @Override
         protected void dispatchJobImpl(final DispatchableJob job) {
           dispatched.add(job);
         }
       };
   final CalculationJob job =
       new CalculationJob(
           createJobSpecification(),
           0,
           null,
           Arrays.asList(JOB_ITEM_A, JOB_ITEM_AB),
           CacheSelectHint.privateValues(Arrays.asList(VS_A)));
   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));
   assertFalse(job1.getCacheSelectHint().isPrivateValue(VS_A));
   final CalculationJobResult result1 =
       new CalculationJobResult(
           job1.getSpecification(), 0, Arrays.asList(CalculationJobResultItem.success()), "Test");
   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_AB));
   assertFalse(job2.getCacheSelectHint().isPrivateValue(VS_A));
   final CalculationJobResult result2 =
       new CalculationJobResult(
           job2.getSpecification(),
           0,
           Arrays.asList(CalculationJobResultItem.failure("Foo", "Bar")),
           "Test");
   next.getResultReceiver(result2).resultReceived(result2);
   Mockito.verify(receiver)
       .resultReceived(
           new CalculationJobResult(
               job.getSpecification(),
               0,
               Arrays.asList(
                   CalculationJobResultItem.success(),
                   CalculationJobResultItem.failure("Foo", "Bar")),
               "Test"));
   assertTrue(job1.getSpecification().getJobId() != job2.getSpecification().getJobId());
   assertTrue(job2.getSpecification().getJobId() == job.getSpecification().getJobId());
 }
Esempio n. 2
0
 public void testStandardJob_WholeWatchedJob() {
   final CalculationJob job1 =
       new CalculationJob(
           createJobSpecification(),
           0,
           null,
           Arrays.asList(JOB_ITEM_A),
           CacheSelectHint.allShared());
   final CalculationJob job2 =
       new CalculationJob(
           createJobSpecification(),
           0,
           new long[] {job1.getSpecification().getJobId()},
           Arrays.asList(JOB_ITEM_AB),
           CacheSelectHint.allShared());
   job1.addTail(job2);
   final CalculationJob job3 =
       new CalculationJob(
           createJobSpecification(),
           0,
           new long[] {job1.getSpecification().getJobId()},
           Arrays.asList(JOB_ITEM_AC),
           CacheSelectHint.allShared());
   job1.addTail(job3);
   final CalculationJob job4 =
       new CalculationJob(
           createJobSpecification(),
           0,
           new long[] {job2.getSpecification().getJobId(), job3.getSpecification().getJobId()},
           Arrays.asList(JOB_ITEM_BCD),
           CacheSelectHint.allShared());
   job3.addTail(job4);
   final JobResultReceiver receiver = Mockito.mock(JobResultReceiver.class);
   final Queue<DispatchableJob> dispatched = new LinkedList<DispatchableJob>();
   final JobDispatcher dispatcher =
       new JobDispatcher() {
         @Override
         protected void dispatchJobImpl(final DispatchableJob job) {
           dispatched.add(job);
         }
       };
   final StandardJob parent = new StandardJob(dispatcher, job1, receiver);
   final WholeWatchedJob wjob1 = parent.createWholeWatchedJob(job1);
   final CalculationJobResult result1 =
       new CalculationJobResult(
           job1.getSpecification(), 0, Arrays.asList(CalculationJobResultItem.success()), "Test");
   wjob1.getResultReceiver(result1).resultReceived(result1);
   Mockito.verify(receiver).resultReceived(result1);
   Mockito.reset();
   assertEquals(dispatched.size(), 2);
   final WholeWatchedJob wjob2 = (WholeWatchedJob) dispatched.poll();
   final WholeWatchedJob wjob3 = (WholeWatchedJob) dispatched.poll();
   final CalculationJobResult result2 =
       new CalculationJobResult(
           job2.getSpecification(), 0, Arrays.asList(CalculationJobResultItem.success()), "Test");
   final CalculationJobResult result3 =
       new CalculationJobResult(
           job3.getSpecification(), 0, Arrays.asList(CalculationJobResultItem.success()), "Test");
   wjob3.getResultReceiver(result3).resultReceived(result3);
   Mockito.verify(receiver).resultReceived(result3);
   Mockito.reset();
   assertEquals(dispatched.size(), 0);
   wjob2.getResultReceiver(result2).resultReceived(result2);
   Mockito.verify(receiver).resultReceived(result2);
   Mockito.reset();
   assertEquals(dispatched.size(), 1);
   final WholeWatchedJob wjob4 = (WholeWatchedJob) dispatched.poll();
   final CalculationJobResult result4 =
       new CalculationJobResult(
           job4.getSpecification(), 0, Arrays.asList(CalculationJobResultItem.success()), "Test");
   wjob4.getResultReceiver(result4).resultReceived(result4);
   Mockito.verify(receiver).resultReceived(result4);
   Mockito.reset();
 }