Пример #1
0
 /**
  * @dataProvider resolveAsyncToStateThrowsIfJobNotWaitAsync
  * @testdox JQManagedJob::resolveWaitAsyncJob() 
  *
  */
 function testResolveAsyncToStateThrowsIfJobNotWaitAsync($currentState, $expectedOk)
 {
     // create a queuestore
     $q = new JQStore_Array();
     $testJob = new SampleAsyncJob($this);
     $mJob = $q->enqueue($testJob);
     $mJob->markJobStarted();
     JQJobs_TestHelper::moveJobToStatus($mJob, $currentState);
     if ($expectedOk) {
         JQManagedJob::resolveWaitAsyncJob($q, $mJob->getJobId(), JQManagedJob::STATUS_COMPLETED);
         $this->assertEquals(JQManagedJob::STATUS_COMPLETED, $mJob->getStatus());
     } else {
         try {
             JQManagedJob::resolveWaitAsyncJob($q, $mJob->getJobId(), JQManagedJob::STATUS_COMPLETED);
             $this->fail("Expected JQManagedJob_InvalidStateException to be thrown.");
         } catch (JQManagedJob_InvalidStateException $e) {
             $this->assertEquals($currentState, $e->getJobStatus());
         }
     }
 }
Пример #2
0
 /**
  * @dataProvider jobIsPastMaxRuntimeSecondsDataProvider
  */
 function testDetectHungJobs($maxRuntimeSeconds, $currentStatus, $startDts, $expectedMulligan)
 {
     $q = $this->jqStore;
     $mJob = $q->enqueue(new QuietSimpleJob(1, array('maxRuntimeSeconds' => $maxRuntimeSeconds)));
     if ($currentStatus === JQManagedJob::STATUS_RUNNING) {
         $mJob->markJobStarted(new DateTime($startDts));
     } else {
         if ($currentStatus === JQManagedJob::STATUS_WAIT_ASYNC) {
             $mJob->markJobStarted(new DateTime($startDts));
             JQJobs_TestHelper::moveJobToStatus($mJob, $currentStatus);
         } else {
             JQJobs_TestHelper::moveJobToStatus($mJob, $currentStatus);
         }
     }
     $mJob->save();
     // verify initial conditions; one job, and in expected status
     $this->assertEquals(1, $q->count('test'), "Should only be 1 job in test queue for this test.");
     $this->assertEquals(1, $q->count('test', $currentStatus), "Should be one job in test queue with status {$currentStatus}...");
     $this->assertEquals(1, $mJob->getMaxAttempts());
     $q->detectHungJobs();
     // reload job; it was changed possibly in another connection
     $mJob = $q->get($mJob->getJobId());
     if ($expectedMulligan) {
         $this->assertEquals(2, $mJob->getMaxAttempts());
         $this->assertEquals(0, $q->count('test', JQManagedJob::STATUS_RUNNING), "There should be no jobs left running after detectHungJobs.");
         $this->assertEquals(1, $q->count('test', JQManagedJob::STATUS_QUEUED), "The hung job should've been requeued but can't be detected.");
     } else {
         $this->assertEquals(1, $mJob->getMaxAttempts());
         $this->assertEquals(1, $q->count('test', $currentStatus), "The job is considered not hung; it should still be in original status {$currentStatus}.");
     }
 }
Пример #3
0
 /**
  * @dataProvider stateTransitionsDataProvider
  * @dataProviderTestdox Can go from %1$-11s => %2$11s ? %3$s
  */
 function testStateTransitions($from, $to, $expectedOk)
 {
     // create a queuestore
     $q = new JQStore_Array();
     // set up initial condiitions
     $mJob = new JQManagedJob($q);
     JQJobs_TestHelper::moveJobToStatus($mJob, $from);
     $this->assertEquals($from, $mJob->getStatus());
     $transition = "[" . ($expectedOk ? 'OK' : 'NO') . "] {$from} => {$to}";
     if ($expectedOk) {
         $mJob->setStatus($to);
         $this->assertEquals($to, $mJob->getStatus(), "{$transition} should be allowed but failed.");
     } else {
         try {
             $mJob->setStatus($to);
             $this->fail("Expected JQManagedJob->setStatus() to throw Exception due to illegal state change.");
         } catch (Exception $e) {
             $this->assertEquals($from, $mJob->getStatus(), "Unallowed {$transition} still mutated job status.");
         }
     }
 }