public function testCommandReply() { $commandId1 = Uuid::uuid1()->toString(); $commandId2 = Uuid::uuid1()->toString(); $this->testSubject->writeCommandReply($commandId1, $commandId1); $data = $this->testSubject->readCommandReply($commandId1); $this->assertEquals($commandId1, $data[1]); $data = $this->testSubject->readCommandReply($commandId2, 1); $this->assertNull($data); }
public function processCommand() { $data = $this->template->dequeueCommand(); if (null === $data) { $this->logger->info('Timeout while waiting for commands, re-entering loop'); return; } $dispatchMessage = DispatchMessage::fromBytes($this->serializer, $data[1]); $self = $this; $successCallback = function ($result) use($dispatchMessage, $self) { $message = new ReplyMessage($dispatchMessage->getCommandIdentifier(), $self->serializer, $result); $self->template->writeCommandReply($dispatchMessage->getCommandIdentifier(), $message->toBytes()); }; $failureCallback = function (\Exception $cause) use($dispatchMessage, $self) { $message = new ReplyMessage($dispatchMessage->getCommandIdentifier(), $self->serializer, $cause, false); $self->template->writeCommandReply($dispatchMessage->getCommandIdentifier(), $message->toBytes()); }; $this->localSegment->dispatch($dispatchMessage->getCommandMessage(), $dispatchMessage->isExpectReply() ? new ClosureCommandCallback($successCallback, $failureCallback) : null); }
public function testRemoteDispatchReplyTimeout() { $this->localSegment->subscribe(TestCommand::class, new TestCommandHandler()); $remoteTemplate = new RedisTemplate('tcp://127.0.0.1:6379?read_write_timeout=-1', 'test-node2', []); $remoteTemplate->subscribe(TestCommand::class); $this->template->setTimeout(1); $interceptor = new DispatchInterceptor(); $this->localSegment->setDispatchInterceptors([$interceptor]); $callback = new ClosureCommandCallback(function ($result) { $this->fail('Exception expected'); }, function ($error) { $this->assertInstanceOf(CommandTimeoutException::class, $error); }); $this->testSubject->send('key', GenericCommandMessage::asCommandMessage(new TestCommand('key')), $callback); $this->assertEmpty($interceptor->commands); $this->assertEmpty($this->template->getClient()->keys('governor:response:*')); $this->assertCount(1, $this->template->getPendingCommands($remoteTemplate->getNodeName())); }
/** * @return string */ public function getNodeName() { return $this->template->getNodeName(); }