<commit_before><?php
abstract class Vps_Util_PubSubHubbub_AbstractTest extends PHPUnit_Framework_TestCase
{
    protected $_hubApp;
    protected $_hubUrl;
    protected $_testId;
    protected $_testFeedUrl;
    private $_storePath;

    public function setUp()
    {
        $debugOutput = false;

        $this->_storePath = tempnam('/tmp', 'pshb');
        unlink($this->_storePath);
        mkdir($this->_storePath);
        //installation see here: http://code.google.com/p/pubsubhubbub/wiki/DeveloperGettingStartedGuide
        if (!$this->_startHub($debugOutput)) {
            //try again with differnet port
            $this->assertTrue($this->_startHub($debugOutput));
        }

        $this->_testId = rand(0, 1000000);
        touch('/tmp/lastCallback'.$this->_testId);
        file_put_contents('/tmp/feedRequested'.$this->_testId, 0);

        $domain = Vps_Registry::get('config')->server->domain;
        $urlPrefix = 'http://'.$domain.'/vps/test';
        $this->_testFeedUrl = $urlPrefix.'/vps_util_pub-sub-hubbub_test-feed?id='.$this->_testId;

        $this->_writeTestFeedContent(1);

    }

    private function _startHub($debugOutput)
    {
        $descriptorspec = array();
        if ($debugOutput) {
            $descriptorspec = array(
                1 => STDOUT,
                2 => STDOUT
            );
        } else {
            $descriptorspec = array(
                1 => array('file', '/dev/null', 'w'),
                2 => array('file', '/dev/null', 'w')
            );
        }

        $address = trim(`hostname`);
        if ($address == 'vivid-test-server') {
            $d = "/var/www/library/pshb/";
        } else {
            $d = "/www/public/library/pshb/";
        }
        $port = rand(8000, 10000);
        $cmd = "python2.5 {$d}google_appengine/dev_appserver.py {$d}pubsubhubbub/hub/ ".
               "--port=$port --address=$address --clear_datastore ".
               "--datastore_path=$this->_storePath/dev_appserver.datastore ".
               "--history_path=$this->_storePath/dev_appserver.datastore.history";
        if ($debugOutput) echo "$cmd\n";
        $this->_hubApp = proc_open($cmd, $descriptorspec, $pipes);
        $this->_hubUrl = "http://$address:$port";
        sleep(1);
        $status = proc_get_status($this->_hubApp);
        return $status['running'];
    }

    public function tearDown()
    {
        unlink('/tmp/feed'.$this->_testId);
        unlink('/tmp/lastCallback'.$this->_testId);
        unlink('/tmp/feedRequested'.$this->_testId);
        system("rm -r $this->_storePath");

        proc_terminate($this->_hubApp, SIGTERM);
        do {
            $status = proc_get_status($this->_hubApp);
            sleep(1);
        } while ($status['running']);
    }

    protected function assertFeedRequested($num)
    {
        $this->assertEquals($num, file_get_contents('/tmp/feedRequested'.$this->_testId));
    }

    protected function _writeTestFeedContent($entries, $advertiseHub = true)
    {
        file_put_contents('/tmp/feed'.$this->_testId, $this->_getTestFeedContent($entries, $advertiseHub));
    }

    protected function _publishTestFeedUpdate()
    {
        $p = new Vps_Util_PubSubHubbub_Publisher($this->_hubUrl.'/');
        $p->publishUpdate($this->_testFeedUrl);
    }<commit_msg>debug ausgabe wenn hub nicht gestartet werden kann<commit_after><?php
abstract class Vps_Util_PubSubHubbub_AbstractTest extends PHPUnit_Framework_TestCase
{
    protected $_hubApp;
    protected $_hubUrl;
    protected $_testId;
    protected $_testFeedUrl;
    private $_storePath;
    private $_pipes;

    public function setUp()
    {
        $debugOutput = false;

        $this->_storePath = tempnam('/tmp', 'pshb');
        unlink($this->_storePath);
        mkdir($this->_storePath);
        //installation see here: http://code.google.com/p/pubsubhubbub/wiki/DeveloperGettingStartedGuide
        if (!$this->_startHub($debugOutput)) {
            //try again with differnet port
            $this->assertTrue($this->_startHub($debugOutput));
        }
        try {
            $c = file_get_contents($this->_hubUrl);
            $this->assertContains('Welcome to the demo PubSubHubbub reference Hub server', $c);
        } catch (Exception $e) {
            $this->fail("Failed starting hub, output: ".stream_get_contents($this->_pipes[1]));
        }

        $this->_testId = rand(0, 1000000);
        touch('/tmp/lastCallback'.$this->_testId);
        file_put_contents('/tmp/feedRequested'.$this->_testId, 0);

        $domain = Vps_Registry::get('config')->server->domain;
        $urlPrefix = 'http://'.$domain.'/vps/test';
        $this->_testFeedUrl = $urlPrefix.'/vps_util_pub-sub-hubbub_test-feed?id='.$this->_testId;

        $this->_writeTestFeedContent(1);

    }

    private function _startHub($debugOutput)
    {
        $descriptorspec = array();
        if ($debugOutput) {
            $descriptorspec = array(
                1 => STDOUT,
                2 => STDOUT
            );
        } else {
            $descriptorspec = array(
                1 => array('pipe', 'w'),
                2 => STDOUT //should be empty
            );
        }

        $address = trim(`hostname`);
        if ($address == 'vivid-test-server') {
            $d = "/var/www/library/pshb/";
        } else {
            $d = "/www/public/library/pshb/";
        }
        $port = rand(8000, 10000);
        $cmd = "python2.5 {$d}google_appengine/dev_appserver.py {$d}pubsubhubbub/hub/ ".
               "--port=$port --address=$address --clear_datastore ".
               "--datastore_path=$this->_storePath/dev_appserver.datastore ".
               "--history_path=$this->_storePath/dev_appserver.datastore.history".
               " 2>&1";
        if ($debugOutput) echo "$cmd\n";
        $this->_hubApp = proc_open($cmd, $descriptorspec, $this->_pipes);
        $this->assertTrue(is_resource($this->_hubApp));
        $this->_hubUrl = "http://$address:$port";
        sleep(1);
        $status = proc_get_status($this->_hubApp);
        return $status['running'];
    }

    public function tearDown()
    {
        unlink('/tmp/feed'.$this->_testId);
        unlink('/tmp/lastCallback'.$this->_testId);
        unlink('/tmp/feedRequested'.$this->_testId);

        proc_terminate($this->_hubApp, SIGTERM);
        do {
            $status = proc_get_status($this->_hubApp);
            if ($status['running']) sleep(1);
        } while ($status['running']);

        system("rm -r $this->_storePath");
    }

    protected function assertFeedRequested($num)
    {
        $this->assertEquals($num, file_get_contents('/tmp/feedRequested'.$this->_testId));
    }

    protected function _writeTestFeedContent($entries, $advertiseHub = true)
    {
        file_put_contents('/tmp/feed'.$this->_testId, $this->_getTestFeedContent($entries, $advertiseHub));
    }

    protected function _publishTestFeedUpdate()
    {
        $p = new Vps_Util_PubSubHubbub_Publisher($this->_hubUrl.'/');
        $p->publishUpdate($this->_testFeedUrl);
    }
{'fraction_non_alphanumeric': 0.15738773197336733, 'fraction_numerical': 0.008074798130046749, 'mean_word_length': 2.3443865466603504, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 83, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6072247', 'n_tokens_mistral': 2173, 'n_tokens_neox': 2123, 'n_words': 331}