Пример #1
0
 public function testServerStreaming()
 {
     $fib_arg = new math\FibArgs();
     $fib_arg->setLimit(7);
     $call = self::$client->Fib($fib_arg);
     $result_array = iterator_to_array($call->responses());
     $extract_num = function ($num) {
         return $num->getNum();
     };
     $values = array_map($extract_num, $result_array);
     $this->assertSame([1, 1, 2, 3, 5, 8, 13], $values);
     $status = $call->getStatus();
     $this->assertSame(\Grpc\STATUS_OK, $status->code);
 }
Пример #2
0
$dividend = 7;
$divisor = 4;
$div_arg = new math\DivArgs();
$div_arg->setDividend($dividend);
$div_arg->setDivisor($divisor);
$call = $client->Div($div_arg);
p("Call peer: " . $call->getPeer());
p("Dividing {$dividend} by {$divisor}");
list($response, $status) = $call->wait();
p("quotient = " . $response->getQuotient());
p("remainder = " . $response->getRemainder());
p('');
p("Running server streaming test:");
$limit = 7;
$fib_arg = new math\FibArgs();
$fib_arg->setLimit($limit);
$call = $client->Fib($fib_arg);
$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);
}