<commit_before><?php
/**
 * Created by PhpStorm.
 * User: cwioro
 * Date: 22.06.15
 * Time: 13:57
 */

namespace test\job;

require_once __DIR__ . '/../../vendor/autoload.php';



use bitcodin\Job;
use bitcodin\Output;
use bitcodin\S3OutputConfig;
use test\BitcodinApiTestBaseClass;
use DateTime;

abstract class AbstractJobTest extends BitcodinApiTestBaseClass {

    /** HELPER METHODS **/
    protected function updateJob(Job $job)
    {
        /* WAIT TIL JOB IS FINISHED */
        $this->waitTillJobGetsExpectedStatus($job, Job::STATUS_FINISHED, Job::STATUS_ERROR);
        $this->assertEquals($job->status, Job::STATUS_FINISHED);

        return $job;
    }

    protected function updateJobError(Job $job)
    {
        $this->waitTillJobGetsExpectedStatus($job, Job::STATUS_ERROR, Job::STATUS_FINISHED);
        $this->assertEquals($job->status, Job::STATUS_ERROR);

        return $job;
    }

    private function waitTillJobGetsExpectedStatus(Job $job, $expectedStatus, $notExpectedStatus, $timeOutSeconds = 1000)
    {
        $expireTime = (new DateTime())->add(new \DateInterval('PT'.$timeOutSeconds.'S'));
        do{
            $job->update();
            $this->assertNotEquals($job->status, $notExpectedStatus);
            sleep(1);
            $this->assertTrue($expireTime >= new DateTime(), 'Timeout during job update!');

        } while($job->status != $expectedStatus);
    }

    protected function transferJob(Job $job)
    {
        $s3Config = $this->getKey('s3output');
        $outputConfig = new S3OutputConfig();
        $outputConfig->accessKey = $s3Config->accessKey;
        $outputConfig->secretKey = $s3Config->secretKey;
        $outputConfig->name = $s3Config->name;<commit_msg>AbstractJobTest.php: update job after sleep, set sleep to 2 seconds<commit_after><?php
/**
 * Created by PhpStorm.
 * User: cwioro
 * Date: 22.06.15
 * Time: 13:57
 */

namespace test\job;

require_once __DIR__ . '/../../vendor/autoload.php';



use bitcodin\Job;
use bitcodin\Output;
use bitcodin\S3OutputConfig;
use test\BitcodinApiTestBaseClass;
use DateTime;

abstract class AbstractJobTest extends BitcodinApiTestBaseClass {

    /** HELPER METHODS **/
    protected function updateJob(Job $job)
    {
        /* WAIT TIL JOB IS FINISHED */
        $this->waitTillJobGetsExpectedStatus($job, Job::STATUS_FINISHED, Job::STATUS_ERROR);
        $this->assertEquals($job->status, Job::STATUS_FINISHED);

        return $job;
    }

    protected function updateJobError(Job $job)
    {
        $this->waitTillJobGetsExpectedStatus($job, Job::STATUS_ERROR, Job::STATUS_FINISHED);
        $this->assertEquals($job->status, Job::STATUS_ERROR);

        return $job;
    }

    private function waitTillJobGetsExpectedStatus(Job $job, $expectedStatus, $notExpectedStatus, $timeOutSeconds = 1000)
    {
        $expireTime = (new DateTime())->add(new \DateInterval('PT'.$timeOutSeconds.'S'));
        do{
            sleep(2);
            $job->update();
            $this->assertNotEquals($job->status, $notExpectedStatus);
            $this->assertTrue($expireTime >= new DateTime(), 'Timeout during job update!');

        } while($job->status != $expectedStatus);
    }

    protected function transferJob(Job $job)
    {
        $s3Config = $this->getKey('s3output');
        $outputConfig = new S3OutputConfig();
        $outputConfig->accessKey = $s3Config->accessKey;
        $outputConfig->secretKey = $s3Config->secretKey;
        $outputConfig->name = $s3Config->name;
{'fraction_non_alphanumeric': 0.13930205949656752, 'fraction_numerical': 0.012871853546910755, 'mean_word_length': 3.2285368802902057, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1854160', 'n_tokens_mistral': 1113, 'n_tokens_neox': 1060, 'n_words': 208}