gearman_client_021.phpt 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. --TEST--
  2. GearmanClient::enableExceptionHandler(),gearman_client_enable_exception_handler()
  3. --SKIPIF--
  4. <?php if (!extension_loaded("gearman")) print "skip";
  5. require_once('skipifconnect.inc');
  6. ?>
  7. --FILE--
  8. <?php
  9. // Test 1: GearmanClient::addServers, Exception callback disabled. Exceptions
  10. // should be skipped until we call enableExceptionHandler. Port 4731 is not
  11. // being used as the port for GearmanD, so it will fail
  12. $client = new GearmanClient();
  13. $client->addServers('localhost:4731,localhost', false);
  14. // Enabling the exception handler, which will attempt to connect to
  15. // the server and in doing so throw an exception since we can't
  16. // connect to a server that doesn't exist
  17. try {
  18. $client->enableExceptionHandler();
  19. } catch (Exception $e) {
  20. print "Exception 1 caught: " . $e->getMessage() . PHP_EOL;
  21. }
  22. // Test 2: GearmanClient::addServers, Exception callback enabled (by default).
  23. // Here, we don't give the second param, so the exception handler is enabled
  24. // upon calling addServers instead of later in enableExceptionHandler
  25. $client2 = new GearmanClient();
  26. try {
  27. $client2->addServers('localhost:4731,localhost');
  28. } catch (Exception $e) {
  29. print "Exception 2 caught: " . $e->getMessage() . PHP_EOL;
  30. }
  31. // Test 3: GearmanClient::addServers, Also, when we explicitly enable in addServers
  32. $client3 = new GearmanClient();
  33. try {
  34. $client3->addServers('localhost:4731,localhost', true);
  35. } catch (Exception $e) {
  36. print "Exception 3 caught: " . $e->getMessage() . PHP_EOL;
  37. }
  38. // Now, do the same as above but with addServer (singular)
  39. // Test 4: GearmanClient::addServer, Exception callback disabled
  40. $client4 = new GearmanClient();
  41. $client4->addServer('localhost', 4731, false);
  42. try {
  43. $client4->enableExceptionHandler();
  44. } catch (Exception $e) {
  45. print "Exception 4 caught: " . $e->getMessage() . PHP_EOL;
  46. }
  47. // Test 5: GearmanClient::addServer, default
  48. $client5 = new GearmanClient();
  49. try {
  50. $client5->addServer('localhost', 4731);
  51. } catch (Exception $e) {
  52. print "Exception 5 caught: " . $e->getMessage() . PHP_EOL;
  53. }
  54. // Test 6: GearmanClient::addServer, explicitly set enableExceptionHandler
  55. $client6 = new GearmanClient();
  56. try {
  57. $client6->addServer('localhost', 4731, true);
  58. } catch (Exception $e) {
  59. print "Exception 6 caught: " . $e->getMessage() . PHP_EOL;
  60. }
  61. print "OK";
  62. ?>
  63. --EXPECTF--
  64. Exception 1 caught: Failed to set exception option
  65. Exception 2 caught: Failed to set exception option
  66. Exception 3 caught: Failed to set exception option
  67. Exception 4 caught: Failed to set exception option
  68. Exception 5 caught: Failed to set exception option
  69. Exception 6 caught: Failed to set exception option
  70. OK