public function testWriteTo() { $stream = fopen('php://temp', 'w+b'); $this->req->writeTo($stream); rewind($stream); $data = stream_get_contents($stream); fclose($stream); $this->assertEquals(strlen($data), $this->req->sizeInBytes()); $this->assertContains($this->topic, $data); $this->assertContains($this->partition, $data); }
public function testWriteCompletelyWithBigRequest() { $topicSize = 9000; $this->topic = str_repeat('a', $topicSize); //bigger than the fread buffer, 8192 $this->req = new Kafka_FetchRequest($this->topic, $this->partition, $this->offset); $this->obj = new Kafka_BoundedByteBuffer_Send($this->req); // 4 bytes = size // 2 bytes = request ID $this->assertEquals(4 + $this->req->sizeInBytes() + 2, $this->obj->writeCompletely($this->stream)); }
public function testWriteTo() { $stream = fopen('php://temp', 'w+b'); $socket = Kafka_Socket::createFromStream($stream); $this->req->writeTo($socket); rewind($stream); $data = stream_get_contents($stream); fclose($stream); $expected_len = strlen($data) - 6; //6 Bytes of headers + data $this->assertEquals($expected_len, $this->req->sizeInBytes()); $this->assertContains($this->topic, $data); $this->assertContains($this->partition, $data); }
/** * Constructor * * @param Kafka_FetchRequest $req Request object */ public function __construct(Kafka_FetchRequest $req) { $this->size = $req->sizeInBytes() + 2; $this->buffer = fopen('php://temp', 'w+b'); fwrite($this->buffer, pack('n', $req->id)); $req->writeTo($this->buffer); rewind($this->buffer); //fseek($this->buffer, $req->getOffset(), SEEK_SET); }