public function testLookupWithInvalidResponseEntry() { $newIdentity = new Identity('foo', ['http://localhost']); $this->backend->expects(self::exactly(2))->method('get')->with('foo')->willReturnOnConsecutiveCalls(null, $newIdentity); $this->discovery->expects(self::once())->method('call')->with(new Discover())->willReturn(new Promise(function () { return new Response([['name' => 'foo', 'urls' => ['http://localhost']], ['invalid']]); })); $this->backend->expects(self::once())->method('register')->with($newIdentity); $identity = $this->registry->get('foo'); self::assertSame($newIdentity, $identity); }
public function testHandleRPCException() { $this->endpoint->expects($this->once())->method('call')->willThrowException(new \Exception('foo', 129)); $request = new Delivery($this->channel, 'cons', 1, false, '', 'boo', '{}', ['reply-to' => 'foo']); $reply = $this->handler->handle($request); $this->assertNotNull($reply); $headers = $reply->getHeaders(); $this->assertArrayHasKey('x-error', $headers); $this->assertEquals('foo', $headers['x-error']); $this->assertArrayHasKey('x-error-code', $headers); $this->assertEquals(129, $headers['x-error-code']); }
/** * @throws DiscoveryException */ private function update() { $response = $this->discovery->call(new Discover())->fallback(function (\Exception $e) { throw new DiscoveryException(sprintf('An error occur while fetching discovery information: %s', $e->getMessage()), 0, $e); })->resolve()->getValue(); if (!is_array($response)) { throw new DiscoveryException(sprintf('Invalid response type \\"%s\\", array expected', gettype($response))); } foreach ($response as $entry) { if (empty($entry['name']) || !isset($entry['urls'])) { continue; } $this->register(new Identity($entry['name'], $entry['urls'])); } }
/** * @param Delivery $message * * @return Message|null * * @throws \Exception */ public function handle(Delivery $message) { $request = $this->createRequest($message); if (!$message->hasProperty('reply-to')) { $this->endpoint->publish($request); return; } try { $response = $this->endpoint->call($request)->resolve(); } catch (\Exception $e) { $response = new Response('', ['x-error' => $e->getMessage(), 'x-error-code' => $e->getCode()]); } $reply = $this->createReply($response); if ($message->hasProperty('correlation-id')) { $reply = $reply->withProperty('correlation-id', $message->getProperty('correlation-id')); } return $reply; }
/** * {@inheritdoc} */ protected function setUp() { $this->endpoint = $this->createMock(EndpointInterface::class); $this->endpoint->expects(self::once())->method('getIdentity')->willReturn(new Identity('foo')); $this->discovery = new ArrayDiscovery([$this->endpoint]); }