public function testQueueProcessAfterNonMultiYield() { $seq = 0; // there will be two callees //// Mocking $realm = $this->getMockBuilder('\\Thruway\\Realm')->setConstructorArgs(["theRealm"])->setMethods(["publishMeta"])->getMock(); $sessionMockBuilder = $this->getMockBuilder('\\Thruway\\Session')->setMethods(['sendMessage'])->disableOriginalConstructor(); $callee0Session = $sessionMockBuilder->getMock(); $callee1Session = $sessionMockBuilder->getMock(); $callerSession = $sessionMockBuilder->getMock(); $callee0Session->setRealm($realm); $callee1Session->setRealm($realm); $callerSession->setRealm($realm); //// End of Mocking $realm->expects($this->exactly(2))->method("publishMeta")->with($this->equalTo('thruway.metaevent.procedure.congestion'), $this->equalTo([["name" => "qpanmy_proc0"]])); $invocationIDs = []; $callee0Session->expects($this->exactly(6))->method("sendMessage")->withConsecutive([$this->isInstanceOf('\\Thruway\\Message\\RegisteredMessage')], [$this->callback(function ($value) use(&$invocationIDs) { $this->assertInstanceOf('\\Thruway\\Message\\InvocationMessage', $value); $invocationIDs[0] = $value->getRequestId(); return true; })], [$this->callback(function ($value) use(&$invocationIDs) { $this->assertInstanceOf('\\Thruway\\Message\\InvocationMessage', $value); $invocationIDs[1] = $value->getRequestId(); return true; })], [$this->isInstanceOf('\\Thruway\\Message\\RegisteredMessage')], [$this->callback(function ($value) use(&$invocationIDs) { $this->assertInstanceOf('\\Thruway\\Message\\InvocationMessage', $value); $invocationIDs[2] = $value->getRequestId(); return true; })], [$this->callback(function ($value) use(&$invocationIDs) { // invocation after yield $this->assertInstanceOf('\\Thruway\\Message\\InvocationMessage', $value); $invocationIDs[3] = $value->getRequestId(); return true; })]); // create a dealer $dealer = new \Thruway\Role\Dealer(); // register proc0 as multi $registerMsg = new \Thruway\Message\RegisterMessage(Session::getUniqueId(), ["thruway_multiregister" => true], "qpanmy_proc0"); $dealer->onMessage($callee0Session, $registerMsg); $callMsg = new \Thruway\Message\CallMessage(Session::getUniqueId(), [], "qpanmy_proc0"); $dealer->onMessage($callerSession, $callMsg); $callMsg->setRequestId(Session::getUniqueId()); $dealer->onMessage($callerSession, $callMsg); $dealer->onMessage($callee0Session, new \Thruway\Message\YieldMessage($invocationIDs[0], [])); $dealer->onMessage($callee0Session, new \Thruway\Message\YieldMessage($invocationIDs[1], [])); // there are now zero calls on proc0 $registerMsg = new \Thruway\Message\RegisterMessage(Session::getUniqueId(), [], "qpanmy_proc1"); $callProc1Msg = new \Thruway\Message\CallMessage(Session::getUniqueId(), [], "qpanmy_proc1"); $dealer->onMessage($callee0Session, $registerMsg); $dealer->onMessage($callerSession, $callProc1Msg); // this should cause congestion and queuing because it should be busy with proc1 $callMsg->setRequestId(Session::getUniqueId()); $dealer->onMessage($callerSession, $callMsg); // yield on proc1 - this should cause proc0 to process queue $dealer->onMessage($callee0Session, new \Thruway\Message\YieldMessage($invocationIDs[2], [])); }
public function testInvocationError() { $dealer = new \Thruway\Role\Dealer(); $callerTransport = new \Thruway\Transport\DummyTransport(); $callerSession = new Session($callerTransport); $calleeTransport = new \Thruway\Transport\DummyTransport(); $calleeSession = new Session($calleeTransport); // register from callee $registerMsg = new \Thruway\Message\RegisterMessage(1, new stdClass(), 'test_proc_name'); $dealer->handleRegisterMessage(new \Thruway\Event\MessageEvent($calleeSession, $registerMsg)); $this->assertInstanceOf('\\Thruway\\Message\\RegisteredMessage', $calleeTransport->getLastMessageSent()); // call from one session $callRequestId = \Thruway\Common\Utils::getUniqueId(); $callMsg = new \Thruway\Message\CallMessage($callRequestId, new stdClass(), 'test_proc_name'); $dealer->handleCallMessage(new \Thruway\Event\MessageEvent($callerSession, $callMsg)); $this->assertInstanceOf('\\Thruway\\Message\\InvocationMessage', $calleeTransport->getLastMessageSent()); $errorMsg = \Thruway\Message\ErrorMessage::createErrorMessageFromMessage($calleeTransport->getLastMessageSent(), 'the.error.uri'); $dealer->handleErrorMessage(new \Thruway\Event\MessageEvent($calleeSession, $errorMsg)); /** @var \Thruway\Message\ErrorMessage $returnedError */ $returnedError = $callerTransport->getLastMessageSent(); $this->assertInstanceOf('\\Thruway\\Message\\ErrorMessage', $returnedError); $this->assertEquals(Message::MSG_CALL, $returnedError->getErrorMsgCode()); $this->assertEquals($callRequestId, $returnedError->getErrorRequestId()); $this->assertEquals('the.error.uri', $returnedError->getErrorURI()); }