Ejemplo n.º 1
0
$result_array = iterator_to_array($call->responses());
$result = '';
foreach ($result_array as $num) {
    $result .= ' ' . $num->getNum();
}
p("The first {$limit} Fibonacci numbers are:" . $result);
p('');
p("Running client streaming test:");
$call = $client->Sum();
for ($i = 0; $i <= $limit; $i++) {
    $num = new math\Num();
    $num->setNum($i);
    $call->write($num);
}
list($response, $status) = $call->wait();
p(sprintf("The first %d positive integers sum to: %d", $limit, $response->getNum()));
p('');
p("Running bidi-streaming test:");
$call = $client->DivMany();
for ($i = 0; $i < 7; $i++) {
    $div_arg = new math\DivArgs();
    $dividend = 2 * $i + 1;
    $divisor = 3;
    $div_arg->setDividend($dividend);
    $div_arg->setDivisor($divisor);
    $call->write($div_arg);
    p("client writing: {$dividend} / {$divisor}");
    $response = $call->read();
    p(sprintf("server writing: quotient = %d, remainder = %d", $response->getQuotient(), $response->getRemainder()));
}
$call->writesDone();
Ejemplo n.º 2
0
 public function testBidiStreaming()
 {
     $call = self::$client->DivMany();
     $this->assertTrue(is_string($call->getPeer()));
     for ($i = 0; $i < 7; $i++) {
         $div_arg = new math\DivArgs();
         $div_arg->setDividend(2 * $i + 1);
         $div_arg->setDivisor(2);
         $call->write($div_arg);
         $response = $call->read();
         $this->assertSame($i, $response->getQuotient());
         $this->assertSame(1, $response->getRemainder());
     }
     $call->writesDone();
     $status = $call->getStatus();
     $this->assertSame(\Grpc\STATUS_OK, $status->code);
 }