gearman_worker_018.phpt 3.0 KB

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