/**
  * @return tx_caretaker_TestServiceInterface
  */
 public function getTestService()
 {
     if ($this->testService === NULL) {
         if ($this->testServiceType) {
             $info = t3lib_extMgm::findService('caretaker_test_service', $this->testServiceType);
             if ($info && $info['classFile']) {
                 $requireFile = t3lib_div::getFileAbsFileName($info['classFile']);
                 if (@is_file($requireFile)) {
                     t3lib_div::requireOnce($requireFile);
                     $this->testService = t3lib_div::makeInstance($info['className']);
                     if ($this->testService) {
                         $this->testService->setInstance($this->getInstance());
                         $this->testService->setConfiguration($this->testServiceConfiguration);
                     } else {
                         throw new Exception('testservice class ' . $info['className'] . ' could not be instantiated');
                     }
                 } else {
                     throw new Exception('testservice ' . $this->testServiceType . ' class file ' . $requireFile . ' not found');
                 }
             } else {
                 throw new Exception('caretaker testservice ' . $this->testServiceType . ' not found');
             }
         }
     }
     return $this->testService;
 }
 /**
  * @return tx_caretaker_TestServiceInterface
  * @throws Exception
  */
 public function getTestService()
 {
     if ($this->testService === NULL) {
         if ($this->testServiceType) {
             $info = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::findService('caretaker_test_service', $this->testServiceType);
             if ($info && $info['className']) {
                 if (class_exists($info['className'])) {
                     $this->testService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($info['className']);
                     if ($this->testService) {
                         $this->testService->setInstance($this->getInstance());
                         $this->testService->setConfiguration($this->testServiceConfiguration);
                     } else {
                         throw new Exception('testservice class ' . $info['className'] . ' could not be instantiated');
                     }
                 } else {
                     throw new Exception('testservice ' . $this->testServiceType . ' class ' . $info['className'] . ' not found');
                 }
             } else {
                 throw new Exception('caretaker testservice ' . $this->testServiceType . ' not found');
             }
         }
     }
     return $this->testService;
 }
 /**
  *
  * @param tx_caretaker_TestServiceInterface $testService
  * @param tx_caretaker_TestNode $node
  * @param tx_caretaker_NodeResult $latestTestResult
  * @param array $options
  * @return tx_caretaker_NodeResult
  */
 protected function executeTestServiceRun($testService, $node, $latestTestResult, $options)
 {
     // check wether the test can be executed
     if ($testService && $testService->isExecutable()) {
         try {
             $result = $testService->runTest();
         } catch (Exception $e) {
             $result = tx_caretaker_TestResult::create(tx_caretaker_Constants::state_error, 0, '{LLL:EXT:caretaker/locallang_fe.xml:service_exception}' . $e->getMessage);
         }
         // retry if not ok and retrying is enabled
         if ($result->getState() != 0 && $node->getTestRetry() > 0) {
             $round = 0;
             while ($round < $node->getTestRetry() && $result->getState() != 0) {
                 // TODO make sleep time between retry configurable
                 sleep(1);
                 try {
                     $result = $testService->runTest();
                 } catch (Exception $e) {
                     $result = tx_caretaker_TestResult::create(tx_caretaker_Constants::state_error, 0, '{LLL:EXT:caretaker/locallang_fe.xml:service_exception}' . $e->getMessage);
                 }
                 $round++;
             }
             $result->addSubMessage(new tx_caretaker_ResultMessage('LLL:EXT:caretaker/locallang_fe.xml:retry_info', array('number' => $round)));
         }
         // save to repository after reading the previous result
         $resultRepository = tx_caretaker_TestResultRepository::getInstance();
         $resultRepository->saveTestResultForNode($node, $result);
         // trigger notification
         $node->notify('updatedTestResult', $result, $latestTestResult);
         return $result;
     } else {
         $result = tx_caretaker_TestResult::undefined();
         $result->addSubMessage(new tx_caretaker_ResultMessage('test service was not executable this time so the cached result is used'));
         $node->notify('cachedTestResult', $result, $latestTestResult);
         return $latestTestResult;
     }
 }