Exemplo n.º 1
0
 public function testHandleLogWithGoodMessageNotImplementingJobInterface()
 {
     $worker = new WorkerPresence();
     $worker->setMemory(12345);
     $frame = new Frame('MESSAGE', array('delivery_tag' => 'delivery-' . mt_rand()), $worker->toJson());
     $loop = LoopFactory::create();
     $options = array('eventloop' => $loop, 'on_error' => array($this, 'throwRedisError'));
     $redisSync = new PredisSync('tcp://127.0.0.1:6379');
     $redisSync->connect();
     $resolver = $this->getResolver();
     $resolver->expects($this->once())->method('ack');
     $done = false;
     $phpunit = $this;
     $redis = new PredisAsync('tcp://127.0.0.1:6379', $options);
     $redis->connect(function () use($resolver, $phpunit, $redis, $frame, $redisSync, &$done, $worker) {
         $component = new LogBuilderComponent();
         $component->handleLog($redis, $phpunit->getLogger(), $frame, $resolver)->then(function ($hashId) use($phpunit, $redis, $redisSync, &$done, $worker) {
             $redis->disconnect();
             $phpunit->assertEquals($worker->toJson(), $redisSync->get($hashId));
             $phpunit->assertTrue($redisSync->sismember('garbages', $hashId));
             $done = true;
         });
     });
     $loop->run();
     $this->assertTrue($done);
 }
Exemplo n.º 2
0
 public function onPresence(WorkerPresence $presence)
 {
     if (!array_key_exists('http://phraseanet.com/gloubster/monitor', $this->subscribedTopics)) {
         return;
     }
     // re-send the serialized json to all the clients subscribed to that category
     $this->subscribedTopics['http://phraseanet.com/gloubster/monitor']->broadcast($presence->toJson());
 }
Exemplo n.º 3
0
 public function getData()
 {
     $delivery = new FilesystemDelivery();
     $delivery->setTarget('/path/to/Target');
     /**
      * @todo add receipts
      */
     $receipts = array();
     $image = new ImageJob();
     $image->setEnd(microtime(true))->setDeliveryDuration(25.4)->setDelivery($delivery)->setError(true)->setErrorMessage('An error ploped')->setParameters(array('param1' => 'val1', 'param2' => 'val2'))->setProcessDuration(23.42)->setWorkerId('a worker-id')->setSource('/path/to/source')->setReceipts($receipts);
     $video = new VideoJob();
     $image->setEnd(microtime(true))->setDeliveryDuration(25.4)->setDelivery($delivery)->setError(true)->setErrorMessage('An error ploped')->setParameters(array('param1' => 'val1', 'param2' => 'val2'))->setProcessDuration(23.42)->setWorkerId('a worker-id')->setSource('/path/to/source')->setReceipts($receipts);
     $presence = new WorkerPresence();
     $presence->setWorkerType('worker-type')->setFailureJobs(mt_rand())->setId(mt_rand())->setMemory(123456789)->setStartedTime(223456789.98765433)->setLastJobTime(333456789.9876543)->setTotalJobs(mt_rand())->setSuccessJobs(mt_rand())->setReportTime(444456789.98765445)->setIdle(true);
     return array(array($image, $image->toJson()), array($video, $video->toJson()), array($presence, $presence->toJson()));
 }
 /**
  * @covers Gloubster\Message\Presence\WorkerPresence::getArrayData
  * @covers Gloubster\Message\AbstractMessage::toJson
  * @covers Gloubster\Message\AbstractMessage::fromJson
  */
 public function testFromToJson()
 {
     $type = 'worker-type';
     $this->object->setWorkerType($type);
     $total = mt_rand();
     $this->object->setFailureJobs($total);
     $id = mt_rand();
     $this->object->setId($id);
     $memory = 123456789;
     $this->object->setMemory($memory);
     $time = 223456789.98765433;
     $this->object->setStartedTime($time);
     $time = 333456789.9876543;
     $this->object->setLastJobTime($time);
     $total = mt_rand();
     $this->object->setTotalJobs($total);
     $success = mt_rand();
     $this->object->setSuccessJobs($success);
     $time = 444456789.98765445;
     $this->object->setReportTime($time);
     $idle = true;
     $this->object->setIdle($idle);
     $this->assertEquals($this->object, WorkerPresence::fromJson($this->object->toJson()));
 }
Exemplo n.º 5
0
 /**
  * @test
  * @expectedException RuntimeException
  */
 public function itShouldFailWithInvalidJobData()
 {
     $presence = new WorkerPresence();
     $handler = new MessageHandler($this->getStompClient(), $this->getLogger());
     $this->assertFalse($handler->receive($presence->toJson()));
 }
Exemplo n.º 6
0
 /**
  * @expectedException Gloubster\Exception\RuntimeException
  * @covers Gloubster\Message\Acknowledgement\Factory::fromJson
  */
 public function testFromJsonFailsWithWrongType()
 {
     $presence = new WorkerPresence();
     $presence->setWorkerType('worker-type')->setFailureJobs(mt_rand())->setId(mt_rand())->setMemory(123456789)->setStartedTime(223456789.98765433)->setLastJobTime(333456789.9876543)->setTotalJobs(mt_rand())->setSuccessJobs(mt_rand())->setReportTime(444456789.98765445)->setIdle(true);
     Factory::fromJson($presence->toJson());
 }
Exemplo n.º 7
0
 public final function sendPresence()
 {
     $presence = new WorkerPresence();
     $presence->setFailureJobs($this->jobCounter->getFailures())->setId($this->id)->setIdle(false)->setLastJobTime($this->jobCounter->getUpdateTimestamp())->setReportTime(microtime(true))->setStartedTime($this->jobCounter->getStartTimestamp())->setSuccessJobs($this->jobCounter->getSuccess())->setTotalJobs($this->jobCounter->getTotal())->setMemory(memory_get_usage())->setWorkerType($this->getType());
     $this->channel->basic_publish(new AMQPMessage($presence->toJson()), Configuration::EXCHANGE_MONITOR);
 }