public function testHandleLogWithJob() { $job = new ImageJob(); $job->setBeginning('begin'); $job->setEnd('end'); $frame = new Frame('MESSAGE', array('delivery_tag' => 'delivery-' . mt_rand()), $job->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($phpunit, $redis, $frame, $redisSync, &$done, $resolver) { $component = new LogBuilderComponent(); $component->handleLog($redis, $phpunit->getLogger(), $frame, $resolver)->then(function ($hashId) use($phpunit, $redis, $redisSync, &$done) { $redis->disconnect(); $data = $redisSync->hgetall($hashId); $phpunit->assertGreaterThan(0, count($data)); $phpunit->assertEquals('Gloubster\\Message\\Job\\ImageJob', $data['type']); $phpunit->assertTrue($redisSync->sismember('jobs', $hashId)); $done = true; }); }); $loop->run(); $this->assertTrue($done); }
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); return array(array($image, $image->toJson()), array($video, $video->toJson())); }
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())); }
private function specificationsFromJob(ImageJob $job) { $specifications = new Image(); $parameters = $this->populateParameters($job->getParameters(), array('width' => null, 'height' => null, 'quality' => null, 'resize-mode' => null, 'resolution' => null, 'resolution-units' => null, 'resolution-x' => null, 'resolution-y' => null, 'rotation' => null, 'strip' => null)); if ($parameters['width'] && $parameters['height']) { $specifications->setDimensions($parameters['width'], $parameters['height']); } if ($parameters['quality']) { $specifications->setQuality($parameters['quality']); } if ($parameters['resize-mode']) { switch ($parameters['resize-mode']) { case ImageJob::RESIZE_OUTBOUND: $mode = Image::RESIZE_MODE_OUTBOUND; break; case ImageJob::RESIZE_INBOUND: $mode = Image::RESIZE_MODE_INBOUND; break; default: case ImageJob::RESIZE_INBOUND_FIXEDRATIO: $mode = Image::RESIZE_MODE_INBOUND_FIXEDRATIO; break; } $specifications->setResizeMode($mode); } if ($parameters['resolution'] || $parameters['resolution-x'] && $parameters['resolution-y']) { $units = Image::RESOLUTION_PIXELPERINCH; if ($parameters['resolution-units'] === ImageJob::RESOLUTION_PER_CENTIMETERS) { $units = Image::RESOLUTION_PIXELPERCENTIMETER; } if ($parameters['resolution']) { $res_x = $res_y = $parameters['resolution']; } else { $res_x = $parameters['resolution-x']; $res_y = $parameters['resolution-y']; } $specifications->setResolution($res_x, $res_y, $units); } if ($parameters['rotation']) { $specifications->setRotationAngle($parameters['rotation']); } if ($parameters['strip']) { $specifications->setStrip($parameters['strip']); } return $specifications; }
/** @test */ public function itShouldWork() { $job = ImageJob::create('/path/to/source', new DeliveryMock(), array('format' => 'jpeg')); $logger = $this->getLogger(); $logger->expects($this->never())->method('addError'); $logger->expects($this->never())->method('addInfo'); $client = $this->getStompClient(); $client->expects($this->once())->method('isConnected')->will($this->returnValue(true)); $handler = new MessageHandler($client, $logger); $handler->receive($job->toJson()); }
public function testWithOptions() { $parameters = array('width' => 320, 'height' => 240, 'format' => 'gif', 'resize-mode' => ImageJob::RESIZE_INBOUND, 'resolution-units' => ImageJob::RESOLUTION_PER_CENTIMETERS, 'resolution' => 200, 'strip' => true, 'rotation' => 90, 'quality' => 100); $job = ImageJob::create(__DIR__ . '/../../../testfiles/photo02.JPG', Filesystem::create($this->target), $parameters); $message = $this->getAMQPMessage($job->toJson()); $this->getWorker()->process($message); $this->assertTrue(file_exists($this->target)); }
public function testCreateJob() { $delivery = $this->getMockBuilder('Gloubster\\Delivery\\DeliveryInterface')->disableOriginalConstructor()->getMock(); $job = ImageJob::create('/path/to/source', $delivery, array('format' => 'bingo')); $this->assertTrue($job->isOk()); }
/** * @expectedException Gloubster\Exception\RuntimeException */ public function testFromJsonFailsWithWrongType() { $job = new ImageJob(); Factory::fromJson($job->toJson()); }