public function handle(Message $message, QueueInterface $queue) { /** @var SerializedCallback $callback */ $callback = $message->getData(); call_user_func_array($callback->callback, $callback->params); return new Result(true); }
/** * @test */ public function acks() { $message = Message::create('lus'); $this->ed->expects($this->once())->method('dispatch')->with(Events::ACK, $this->isInstanceOf('Pekkis\\Queue\\SymfonyBridge\\MessageEvent')); $this->innerqueue->expects($this->once())->method('ack')->with($message)->will($this->returnValue(true)); $ret = $this->queue->ack($message); $this->assertTrue($ret); }
public function setUp() { $this->message = Message::create('lussuti.lus'); $this->ed = new EventDispatcher(); $this->output = $this->getMock('Symfony\\Component\\Console\\Output\\ConsoleOutputInterface'); $subscriber = new ConsoleOutputSubscriber($this->output); $this->ed->addSubscriber($subscriber); }
/** * @test */ public function handles() { $data = new SerializedCallback('\\touchMyTrallala', ['xooxer']); $message = Message::create('xoo.lus', $data); $this->assertFileNotExists(ROOT_TESTS . '/data/temp/ping.txt'); $handler = new FilelibMessageHandler(); $handler->handle($message, $this->prophesize('Pekkis\\Queue\\Queue')->reveal()); $this->assertFileExists(ROOT_TESTS . '/data/temp/ping.txt'); }
/** * @param Message $message * @return Result */ public function handle(Message $message, QueueInterface $queue) { /** @var ReservationRequest $reservation */ $reservation = $message->getData(); if (rand(1, 100) >= 75) { // If a result is not successful the message will stay on the queue. $result = new Result(false, 'Oh dear, the reservation could not be created. It will be retried... soon!'); } else { $msg = sprintf("Reservation created from %s to %s", $reservation->getFrom()->format('Y-m-d H:i:d'), $reservation->getTo()->format('Y-m-d H:i:d')); // If a result is successful, the message is acked (acknowledged to be processed, removed from queue) $result = new Result(true, $msg); } return $result; }
/** * @test * @dataProvider provideData */ public function messagesAreHandled($successfulResult) { $message = Message::create('test', array('banana' => 'is not just a banaana, banaana')); $this->queue->expects($this->once())->method('dequeue')->will($this->returnValue($message)); $mockHandler2 = $this->getMock('Pekkis\\Queue\\Processor\\MessageHandler'); $mockHandler2->expects($this->never())->method('willHandle'); $mockHandler = $this->getMock('Pekkis\\Queue\\Processor\\MessageHandler'); $mockHandler->expects($this->once())->method('willHandle')->with($message)->will($this->returnValue(true)); $message2 = Message::create('test', array('banana' => 'is not just a banaana, banaana')); $message3 = Message::create('test', array('banana' => 'is not just a banaana, banaana')); $result = new Result($successfulResult); $mockHandler->expects($this->once())->method('handle')->with($message, $this->queue)->will($this->returnValue($result)); if ($successfulResult) { $this->queue->expects($this->once())->method('ack')->with($message); } else { $this->queue->expects($this->never())->method('ack'); } $this->processor->registerHandler($mockHandler2); $this->processor->registerHandler($mockHandler); $this->processor->process(); }
/** * Acknowledges message * * @param Message $message */ public function ack(Message $message) { return $this->adapter->ack($message->getIdentifier(), $message->getInternals()); }
/** * @test */ public function ackDelegates() { $message = Message::create('test-message', array('aybabtu' => 'lussentus')); $this->adapter->expects($this->once())->method('ack')->will($this->returnValue('luslus')); $this->assertSame('luslus', $this->queue->ack($message)); }
/** * @test */ public function setDataSetsData() { $message = Message::create('luss', array('mussutus' => 'kovaa mussutusta')); $message->setData('lussuttakeepa imaisua'); $this->assertEquals('lussuttakeepa imaisua', $message->getData()); }