OLD | NEW |
(Empty) | |
| 1 <?php |
| 2 /* |
| 3 * |
| 4 * Copyright 2015-2016, Google Inc. |
| 5 * All rights reserved. |
| 6 * |
| 7 * Redistribution and use in source and binary forms, with or without |
| 8 * modification, are permitted provided that the following conditions are |
| 9 * met: |
| 10 * |
| 11 * * Redistributions of source code must retain the above copyright |
| 12 * notice, this list of conditions and the following disclaimer. |
| 13 * * Redistributions in binary form must reproduce the above |
| 14 * copyright notice, this list of conditions and the following disclaimer |
| 15 * in the documentation and/or other materials provided with the |
| 16 * distribution. |
| 17 * * Neither the name of Google Inc. nor the names of its |
| 18 * contributors may be used to endorse or promote products derived from |
| 19 * this software without specific prior written permission. |
| 20 * |
| 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 32 * |
| 33 */ |
| 34 class EndToEndTest extends PHPUnit_Framework_TestCase |
| 35 { |
| 36 public function setUp() |
| 37 { |
| 38 $this->server = new Grpc\Server([]); |
| 39 $this->port = $this->server->addHttp2Port('0.0.0.0:0'); |
| 40 $this->channel = new Grpc\Channel('localhost:'.$this->port, []); |
| 41 $this->server->start(); |
| 42 } |
| 43 |
| 44 public function tearDown() |
| 45 { |
| 46 unset($this->channel); |
| 47 unset($this->server); |
| 48 } |
| 49 |
| 50 public function testSimpleRequestBody() |
| 51 { |
| 52 $deadline = Grpc\Timeval::infFuture(); |
| 53 $status_text = 'xyz'; |
| 54 $call = new Grpc\Call($this->channel, |
| 55 'dummy_method', |
| 56 $deadline); |
| 57 |
| 58 $event = $call->startBatch([ |
| 59 Grpc\OP_SEND_INITIAL_METADATA => [], |
| 60 Grpc\OP_SEND_CLOSE_FROM_CLIENT => true, |
| 61 ]); |
| 62 |
| 63 $this->assertTrue($event->send_metadata); |
| 64 $this->assertTrue($event->send_close); |
| 65 |
| 66 $event = $this->server->requestCall(); |
| 67 $this->assertSame('dummy_method', $event->method); |
| 68 $server_call = $event->call; |
| 69 |
| 70 $event = $server_call->startBatch([ |
| 71 Grpc\OP_SEND_INITIAL_METADATA => [], |
| 72 Grpc\OP_SEND_STATUS_FROM_SERVER => [ |
| 73 'metadata' => [], |
| 74 'code' => Grpc\STATUS_OK, |
| 75 'details' => $status_text, |
| 76 ], |
| 77 Grpc\OP_RECV_CLOSE_ON_SERVER => true, |
| 78 ]); |
| 79 |
| 80 $this->assertTrue($event->send_metadata); |
| 81 $this->assertTrue($event->send_status); |
| 82 $this->assertFalse($event->cancelled); |
| 83 |
| 84 $event = $call->startBatch([ |
| 85 Grpc\OP_RECV_INITIAL_METADATA => true, |
| 86 Grpc\OP_RECV_STATUS_ON_CLIENT => true, |
| 87 ]); |
| 88 |
| 89 $status = $event->status; |
| 90 $this->assertSame([], $status->metadata); |
| 91 $this->assertSame(Grpc\STATUS_OK, $status->code); |
| 92 $this->assertSame($status_text, $status->details); |
| 93 |
| 94 unset($call); |
| 95 unset($server_call); |
| 96 } |
| 97 |
| 98 public function testMessageWriteFlags() |
| 99 { |
| 100 $deadline = Grpc\Timeval::infFuture(); |
| 101 $req_text = 'message_write_flags_test'; |
| 102 $status_text = 'xyz'; |
| 103 $call = new Grpc\Call($this->channel, |
| 104 'dummy_method', |
| 105 $deadline); |
| 106 |
| 107 $event = $call->startBatch([ |
| 108 Grpc\OP_SEND_INITIAL_METADATA => [], |
| 109 Grpc\OP_SEND_MESSAGE => ['message' => $req_text, |
| 110 'flags' => Grpc\WRITE_NO_COMPRESS, ], |
| 111 Grpc\OP_SEND_CLOSE_FROM_CLIENT => true, |
| 112 ]); |
| 113 |
| 114 $this->assertTrue($event->send_metadata); |
| 115 $this->assertTrue($event->send_close); |
| 116 |
| 117 $event = $this->server->requestCall(); |
| 118 $this->assertSame('dummy_method', $event->method); |
| 119 $server_call = $event->call; |
| 120 |
| 121 $event = $server_call->startBatch([ |
| 122 Grpc\OP_SEND_INITIAL_METADATA => [], |
| 123 Grpc\OP_SEND_STATUS_FROM_SERVER => [ |
| 124 'metadata' => [], |
| 125 'code' => Grpc\STATUS_OK, |
| 126 'details' => $status_text, |
| 127 ], |
| 128 ]); |
| 129 |
| 130 $event = $call->startBatch([ |
| 131 Grpc\OP_RECV_INITIAL_METADATA => true, |
| 132 Grpc\OP_RECV_STATUS_ON_CLIENT => true, |
| 133 ]); |
| 134 |
| 135 $status = $event->status; |
| 136 $this->assertSame([], $status->metadata); |
| 137 $this->assertSame(Grpc\STATUS_OK, $status->code); |
| 138 $this->assertSame($status_text, $status->details); |
| 139 |
| 140 unset($call); |
| 141 unset($server_call); |
| 142 } |
| 143 |
| 144 public function testClientServerFullRequestResponse() |
| 145 { |
| 146 $deadline = Grpc\Timeval::infFuture(); |
| 147 $req_text = 'client_server_full_request_response'; |
| 148 $reply_text = 'reply:client_server_full_request_response'; |
| 149 $status_text = 'status:client_server_full_response_text'; |
| 150 |
| 151 $call = new Grpc\Call($this->channel, |
| 152 'dummy_method', |
| 153 $deadline); |
| 154 |
| 155 $event = $call->startBatch([ |
| 156 Grpc\OP_SEND_INITIAL_METADATA => [], |
| 157 Grpc\OP_SEND_CLOSE_FROM_CLIENT => true, |
| 158 Grpc\OP_SEND_MESSAGE => ['message' => $req_text], |
| 159 ]); |
| 160 |
| 161 $this->assertTrue($event->send_metadata); |
| 162 $this->assertTrue($event->send_close); |
| 163 $this->assertTrue($event->send_message); |
| 164 |
| 165 $event = $this->server->requestCall(); |
| 166 $this->assertSame('dummy_method', $event->method); |
| 167 $server_call = $event->call; |
| 168 |
| 169 $event = $server_call->startBatch([ |
| 170 Grpc\OP_SEND_INITIAL_METADATA => [], |
| 171 Grpc\OP_SEND_MESSAGE => ['message' => $reply_text], |
| 172 Grpc\OP_SEND_STATUS_FROM_SERVER => [ |
| 173 'metadata' => [], |
| 174 'code' => Grpc\STATUS_OK, |
| 175 'details' => $status_text, |
| 176 ], |
| 177 Grpc\OP_RECV_MESSAGE => true, |
| 178 Grpc\OP_RECV_CLOSE_ON_SERVER => true, |
| 179 ]); |
| 180 |
| 181 $this->assertTrue($event->send_metadata); |
| 182 $this->assertTrue($event->send_status); |
| 183 $this->assertTrue($event->send_message); |
| 184 $this->assertFalse($event->cancelled); |
| 185 $this->assertSame($req_text, $event->message); |
| 186 |
| 187 $event = $call->startBatch([ |
| 188 Grpc\OP_RECV_INITIAL_METADATA => true, |
| 189 Grpc\OP_RECV_MESSAGE => true, |
| 190 Grpc\OP_RECV_STATUS_ON_CLIENT => true, |
| 191 ]); |
| 192 |
| 193 $this->assertSame([], $event->metadata); |
| 194 $this->assertSame($reply_text, $event->message); |
| 195 $status = $event->status; |
| 196 $this->assertSame([], $status->metadata); |
| 197 $this->assertSame(Grpc\STATUS_OK, $status->code); |
| 198 $this->assertSame($status_text, $status->details); |
| 199 |
| 200 unset($call); |
| 201 unset($server_call); |
| 202 } |
| 203 |
| 204 /** |
| 205 * @expectedException InvalidArgumentException |
| 206 */ |
| 207 public function testInvalidClientMessageArray() |
| 208 { |
| 209 $deadline = Grpc\Timeval::infFuture(); |
| 210 $req_text = 'client_server_full_request_response'; |
| 211 $reply_text = 'reply:client_server_full_request_response'; |
| 212 $status_text = 'status:client_server_full_response_text'; |
| 213 |
| 214 $call = new Grpc\Call($this->channel, |
| 215 'dummy_method', |
| 216 $deadline); |
| 217 |
| 218 $event = $call->startBatch([ |
| 219 Grpc\OP_SEND_INITIAL_METADATA => [], |
| 220 Grpc\OP_SEND_CLOSE_FROM_CLIENT => true, |
| 221 Grpc\OP_SEND_MESSAGE => 'invalid', |
| 222 ]); |
| 223 } |
| 224 |
| 225 /** |
| 226 * @expectedException InvalidArgumentException |
| 227 */ |
| 228 public function testInvalidClientMessageString() |
| 229 { |
| 230 $deadline = Grpc\Timeval::infFuture(); |
| 231 $req_text = 'client_server_full_request_response'; |
| 232 $reply_text = 'reply:client_server_full_request_response'; |
| 233 $status_text = 'status:client_server_full_response_text'; |
| 234 |
| 235 $call = new Grpc\Call($this->channel, |
| 236 'dummy_method', |
| 237 $deadline); |
| 238 |
| 239 $event = $call->startBatch([ |
| 240 Grpc\OP_SEND_INITIAL_METADATA => [], |
| 241 Grpc\OP_SEND_CLOSE_FROM_CLIENT => true, |
| 242 Grpc\OP_SEND_MESSAGE => ['message' => 0], |
| 243 ]); |
| 244 } |
| 245 |
| 246 /** |
| 247 * @expectedException InvalidArgumentException |
| 248 */ |
| 249 public function testInvalidClientMessageFlags() |
| 250 { |
| 251 $deadline = Grpc\Timeval::infFuture(); |
| 252 $req_text = 'client_server_full_request_response'; |
| 253 $reply_text = 'reply:client_server_full_request_response'; |
| 254 $status_text = 'status:client_server_full_response_text'; |
| 255 |
| 256 $call = new Grpc\Call($this->channel, |
| 257 'dummy_method', |
| 258 $deadline); |
| 259 |
| 260 $event = $call->startBatch([ |
| 261 Grpc\OP_SEND_INITIAL_METADATA => [], |
| 262 Grpc\OP_SEND_CLOSE_FROM_CLIENT => true, |
| 263 Grpc\OP_SEND_MESSAGE => ['message' => 'abc', |
| 264 'flags' => 'invalid'], |
| 265 ]); |
| 266 } |
| 267 |
| 268 /** |
| 269 * @expectedException InvalidArgumentException |
| 270 */ |
| 271 public function testInvalidServerStatusMetadata() |
| 272 { |
| 273 $deadline = Grpc\Timeval::infFuture(); |
| 274 $req_text = 'client_server_full_request_response'; |
| 275 $reply_text = 'reply:client_server_full_request_response'; |
| 276 $status_text = 'status:client_server_full_response_text'; |
| 277 |
| 278 $call = new Grpc\Call($this->channel, |
| 279 'dummy_method', |
| 280 $deadline); |
| 281 |
| 282 $event = $call->startBatch([ |
| 283 Grpc\OP_SEND_INITIAL_METADATA => [], |
| 284 Grpc\OP_SEND_CLOSE_FROM_CLIENT => true, |
| 285 Grpc\OP_SEND_MESSAGE => ['message' => $req_text], |
| 286 ]); |
| 287 |
| 288 $this->assertTrue($event->send_metadata); |
| 289 $this->assertTrue($event->send_close); |
| 290 $this->assertTrue($event->send_message); |
| 291 |
| 292 $event = $this->server->requestCall(); |
| 293 $this->assertSame('dummy_method', $event->method); |
| 294 $server_call = $event->call; |
| 295 |
| 296 $event = $server_call->startBatch([ |
| 297 Grpc\OP_SEND_INITIAL_METADATA => [], |
| 298 Grpc\OP_SEND_MESSAGE => ['message' => $reply_text], |
| 299 Grpc\OP_SEND_STATUS_FROM_SERVER => [ |
| 300 'metadata' => 'invalid', |
| 301 'code' => Grpc\STATUS_OK, |
| 302 'details' => $status_text, |
| 303 ], |
| 304 Grpc\OP_RECV_MESSAGE => true, |
| 305 Grpc\OP_RECV_CLOSE_ON_SERVER => true, |
| 306 ]); |
| 307 } |
| 308 |
| 309 /** |
| 310 * @expectedException InvalidArgumentException |
| 311 */ |
| 312 public function testInvalidServerStatusCode() |
| 313 { |
| 314 $deadline = Grpc\Timeval::infFuture(); |
| 315 $req_text = 'client_server_full_request_response'; |
| 316 $reply_text = 'reply:client_server_full_request_response'; |
| 317 $status_text = 'status:client_server_full_response_text'; |
| 318 |
| 319 $call = new Grpc\Call($this->channel, |
| 320 'dummy_method', |
| 321 $deadline); |
| 322 |
| 323 $event = $call->startBatch([ |
| 324 Grpc\OP_SEND_INITIAL_METADATA => [], |
| 325 Grpc\OP_SEND_CLOSE_FROM_CLIENT => true, |
| 326 Grpc\OP_SEND_MESSAGE => ['message' => $req_text], |
| 327 ]); |
| 328 |
| 329 $this->assertTrue($event->send_metadata); |
| 330 $this->assertTrue($event->send_close); |
| 331 $this->assertTrue($event->send_message); |
| 332 |
| 333 $event = $this->server->requestCall(); |
| 334 $this->assertSame('dummy_method', $event->method); |
| 335 $server_call = $event->call; |
| 336 |
| 337 $event = $server_call->startBatch([ |
| 338 Grpc\OP_SEND_INITIAL_METADATA => [], |
| 339 Grpc\OP_SEND_MESSAGE => ['message' => $reply_text], |
| 340 Grpc\OP_SEND_STATUS_FROM_SERVER => [ |
| 341 'metadata' => [], |
| 342 'code' => 'invalid', |
| 343 'details' => $status_text, |
| 344 ], |
| 345 Grpc\OP_RECV_MESSAGE => true, |
| 346 Grpc\OP_RECV_CLOSE_ON_SERVER => true, |
| 347 ]); |
| 348 } |
| 349 |
| 350 /** |
| 351 * @expectedException InvalidArgumentException |
| 352 */ |
| 353 public function testMissingServerStatusCode() |
| 354 { |
| 355 $deadline = Grpc\Timeval::infFuture(); |
| 356 $req_text = 'client_server_full_request_response'; |
| 357 $reply_text = 'reply:client_server_full_request_response'; |
| 358 $status_text = 'status:client_server_full_response_text'; |
| 359 |
| 360 $call = new Grpc\Call($this->channel, |
| 361 'dummy_method', |
| 362 $deadline); |
| 363 |
| 364 $event = $call->startBatch([ |
| 365 Grpc\OP_SEND_INITIAL_METADATA => [], |
| 366 Grpc\OP_SEND_CLOSE_FROM_CLIENT => true, |
| 367 Grpc\OP_SEND_MESSAGE => ['message' => $req_text], |
| 368 ]); |
| 369 |
| 370 $this->assertTrue($event->send_metadata); |
| 371 $this->assertTrue($event->send_close); |
| 372 $this->assertTrue($event->send_message); |
| 373 |
| 374 $event = $this->server->requestCall(); |
| 375 $this->assertSame('dummy_method', $event->method); |
| 376 $server_call = $event->call; |
| 377 |
| 378 $event = $server_call->startBatch([ |
| 379 Grpc\OP_SEND_INITIAL_METADATA => [], |
| 380 Grpc\OP_SEND_MESSAGE => ['message' => $reply_text], |
| 381 Grpc\OP_SEND_STATUS_FROM_SERVER => [ |
| 382 'metadata' => [], |
| 383 'details' => $status_text, |
| 384 ], |
| 385 Grpc\OP_RECV_MESSAGE => true, |
| 386 Grpc\OP_RECV_CLOSE_ON_SERVER => true, |
| 387 ]); |
| 388 } |
| 389 |
| 390 /** |
| 391 * @expectedException InvalidArgumentException |
| 392 */ |
| 393 public function testInvalidServerStatusDetails() |
| 394 { |
| 395 $deadline = Grpc\Timeval::infFuture(); |
| 396 $req_text = 'client_server_full_request_response'; |
| 397 $reply_text = 'reply:client_server_full_request_response'; |
| 398 $status_text = 'status:client_server_full_response_text'; |
| 399 |
| 400 $call = new Grpc\Call($this->channel, |
| 401 'dummy_method', |
| 402 $deadline); |
| 403 |
| 404 $event = $call->startBatch([ |
| 405 Grpc\OP_SEND_INITIAL_METADATA => [], |
| 406 Grpc\OP_SEND_CLOSE_FROM_CLIENT => true, |
| 407 Grpc\OP_SEND_MESSAGE => ['message' => $req_text], |
| 408 ]); |
| 409 |
| 410 $this->assertTrue($event->send_metadata); |
| 411 $this->assertTrue($event->send_close); |
| 412 $this->assertTrue($event->send_message); |
| 413 |
| 414 $event = $this->server->requestCall(); |
| 415 $this->assertSame('dummy_method', $event->method); |
| 416 $server_call = $event->call; |
| 417 |
| 418 $event = $server_call->startBatch([ |
| 419 Grpc\OP_SEND_INITIAL_METADATA => [], |
| 420 Grpc\OP_SEND_MESSAGE => ['message' => $reply_text], |
| 421 Grpc\OP_SEND_STATUS_FROM_SERVER => [ |
| 422 'metadata' => [], |
| 423 'code' => Grpc\STATUS_OK, |
| 424 'details' => 0, |
| 425 ], |
| 426 Grpc\OP_RECV_MESSAGE => true, |
| 427 Grpc\OP_RECV_CLOSE_ON_SERVER => true, |
| 428 ]); |
| 429 } |
| 430 |
| 431 /** |
| 432 * @expectedException InvalidArgumentException |
| 433 */ |
| 434 public function testMissingServerStatusDetails() |
| 435 { |
| 436 $deadline = Grpc\Timeval::infFuture(); |
| 437 $req_text = 'client_server_full_request_response'; |
| 438 $reply_text = 'reply:client_server_full_request_response'; |
| 439 $status_text = 'status:client_server_full_response_text'; |
| 440 |
| 441 $call = new Grpc\Call($this->channel, |
| 442 'dummy_method', |
| 443 $deadline); |
| 444 |
| 445 $event = $call->startBatch([ |
| 446 Grpc\OP_SEND_INITIAL_METADATA => [], |
| 447 Grpc\OP_SEND_CLOSE_FROM_CLIENT => true, |
| 448 Grpc\OP_SEND_MESSAGE => ['message' => $req_text], |
| 449 ]); |
| 450 |
| 451 $this->assertTrue($event->send_metadata); |
| 452 $this->assertTrue($event->send_close); |
| 453 $this->assertTrue($event->send_message); |
| 454 |
| 455 $event = $this->server->requestCall(); |
| 456 $this->assertSame('dummy_method', $event->method); |
| 457 $server_call = $event->call; |
| 458 |
| 459 $event = $server_call->startBatch([ |
| 460 Grpc\OP_SEND_INITIAL_METADATA => [], |
| 461 Grpc\OP_SEND_MESSAGE => ['message' => $reply_text], |
| 462 Grpc\OP_SEND_STATUS_FROM_SERVER => [ |
| 463 'metadata' => [], |
| 464 'code' => Grpc\STATUS_OK, |
| 465 ], |
| 466 Grpc\OP_RECV_MESSAGE => true, |
| 467 Grpc\OP_RECV_CLOSE_ON_SERVER => true, |
| 468 ]); |
| 469 } |
| 470 |
| 471 /** |
| 472 * @expectedException InvalidArgumentException |
| 473 */ |
| 474 public function testInvalidStartBatchKey() |
| 475 { |
| 476 $deadline = Grpc\Timeval::infFuture(); |
| 477 $req_text = 'client_server_full_request_response'; |
| 478 $reply_text = 'reply:client_server_full_request_response'; |
| 479 $status_text = 'status:client_server_full_response_text'; |
| 480 |
| 481 $call = new Grpc\Call($this->channel, |
| 482 'dummy_method', |
| 483 $deadline); |
| 484 |
| 485 $event = $call->startBatch([ |
| 486 9999999 => [], |
| 487 ]); |
| 488 } |
| 489 |
| 490 /** |
| 491 * @expectedException LogicException |
| 492 */ |
| 493 public function testInvalidStartBatch() |
| 494 { |
| 495 $deadline = Grpc\Timeval::infFuture(); |
| 496 $req_text = 'client_server_full_request_response'; |
| 497 $reply_text = 'reply:client_server_full_request_response'; |
| 498 $status_text = 'status:client_server_full_response_text'; |
| 499 |
| 500 $call = new Grpc\Call($this->channel, |
| 501 'dummy_method', |
| 502 $deadline); |
| 503 |
| 504 $event = $call->startBatch([ |
| 505 Grpc\OP_SEND_INITIAL_METADATA => [], |
| 506 Grpc\OP_SEND_CLOSE_FROM_CLIENT => true, |
| 507 Grpc\OP_SEND_MESSAGE => ['message' => $req_text], |
| 508 Grpc\OP_SEND_STATUS_FROM_SERVER => [ |
| 509 'metadata' => [], |
| 510 'code' => Grpc\STATUS_OK, |
| 511 'details' => 'abc', |
| 512 ], |
| 513 ]); |
| 514 } |
| 515 |
| 516 public function testGetTarget() |
| 517 { |
| 518 $this->assertTrue(is_string($this->channel->getTarget())); |
| 519 } |
| 520 |
| 521 public function testGetConnectivityState() |
| 522 { |
| 523 $this->assertTrue($this->channel->getConnectivityState() == Grpc\CHANNEL
_IDLE); |
| 524 } |
| 525 |
| 526 public function testWatchConnectivityStateFailed() |
| 527 { |
| 528 $idle_state = $this->channel->getConnectivityState(); |
| 529 $this->assertTrue($idle_state == Grpc\CHANNEL_IDLE); |
| 530 |
| 531 $now = Grpc\Timeval::now(); |
| 532 $delta = new Grpc\Timeval(500000); // should timeout |
| 533 $deadline = $now->add($delta); |
| 534 |
| 535 $this->assertFalse($this->channel->watchConnectivityState( |
| 536 $idle_state, $deadline)); |
| 537 } |
| 538 |
| 539 public function testWatchConnectivityStateSuccess() |
| 540 { |
| 541 $idle_state = $this->channel->getConnectivityState(true); |
| 542 $this->assertTrue($idle_state == Grpc\CHANNEL_IDLE); |
| 543 |
| 544 $now = Grpc\Timeval::now(); |
| 545 $delta = new Grpc\Timeval(3000000); // should finish well before |
| 546 $deadline = $now->add($delta); |
| 547 |
| 548 $this->assertTrue($this->channel->watchConnectivityState( |
| 549 $idle_state, $deadline)); |
| 550 |
| 551 $new_state = $this->channel->getConnectivityState(); |
| 552 $this->assertTrue($idle_state != $new_state); |
| 553 } |
| 554 |
| 555 public function testWatchConnectivityStateDoNothing() |
| 556 { |
| 557 $idle_state = $this->channel->getConnectivityState(); |
| 558 $this->assertTrue($idle_state == Grpc\CHANNEL_IDLE); |
| 559 |
| 560 $now = Grpc\Timeval::now(); |
| 561 $delta = new Grpc\Timeval(100000); |
| 562 $deadline = $now->add($delta); |
| 563 |
| 564 $this->assertFalse($this->channel->watchConnectivityState( |
| 565 $idle_state, $deadline)); |
| 566 |
| 567 $new_state = $this->channel->getConnectivityState(); |
| 568 $this->assertTrue($new_state == Grpc\CHANNEL_IDLE); |
| 569 } |
| 570 |
| 571 /** |
| 572 * @expectedException InvalidArgumentException |
| 573 */ |
| 574 public function testGetConnectivityStateInvalidParam() |
| 575 { |
| 576 $this->assertTrue($this->channel->getConnectivityState( |
| 577 new Grpc\Timeval)); |
| 578 } |
| 579 |
| 580 /** |
| 581 * @expectedException InvalidArgumentException |
| 582 */ |
| 583 public function testWatchConnectivityStateInvalidParam() |
| 584 { |
| 585 $this->assertTrue($this->channel->watchConnectivityState( |
| 586 0, 1000)); |
| 587 } |
| 588 |
| 589 /** |
| 590 * @expectedException InvalidArgumentException |
| 591 */ |
| 592 public function testChannelConstructorInvalidParam() |
| 593 { |
| 594 $this->channel = new Grpc\Channel('localhost:'.$this->port, NULL); |
| 595 } |
| 596 |
| 597 public function testClose() |
| 598 { |
| 599 $this->assertNull($this->channel->close()); |
| 600 } |
| 601 |
| 602 } |
OLD | NEW |