示例#1
0
 public function testWrite()
 {
     $this->connection = new \Nsq\Connection\Connection("127.0.0.1", 4150);
     $this->encoder = new \Nsq\Encoding\Encoder();
     $this->assertTrue($this->connection->write($this->encoder->magic()));
     $this->assertTrue($this->connection->write($this->encoder->pub("phpnsq_1", "test")));
     $decoder = new \Nsq\Encoding\Decoder();
     $frame = $decoder->readFame($this->connection, true);
     $this->assertEquals("OK", $frame->getContent());
 }
示例#2
0
 public function testClose()
 {
     fwrite($this->socket_client, $this->encoder->pub("phpnsq_1", "test"));
     $data = fread($this->socket_client, 1024);
     $this->decoder->readSize($data);
     $this->decoder->readType($data);
     $this->decoder->readContent($data);
     $frame = $this->decoder->getFrame();
     $this->assertEquals("OK", $frame->getContent());
     $this->assertEquals(6, $frame->getSize());
     $this->assertEquals(0, $frame->getType());
     fwrite($this->socket_client, $this->encoder->sub("phpnsq_1", 1));
     fwrite($this->socket_client, $this->encoder->cls());
 }