dir = sys_get_temp_dir().DIRECTORY_SEPARATOR.'store'; } /** * testMultiProcess. */ public function testMultiProcess() { $fileCache = new FilesystemCache($this->dir, 'txt'); $breaker = new Breaker('github_api', ['ignore_exceptions' => true], $fileCache); $breaker2 = new Breaker('github_api', ['ignore_exceptions' => true], $fileCache); $breaker1FailureCount = 0; $breaker->addListener(CircuitEvents::FAILURE, function (CircuitEvent $event) use (&$breaker1FailureCount) { $breaker1FailureCount = $event->getCircuit()->getFailures(); }); $breaker2->addListener(CircuitEvents::FAILURE, function (CircuitEvent $event) use (&$breaker1FailureCount) { $this->assertEquals($breaker1FailureCount, $event->getCircuit()->getFailures()); }); $fn = function () { throw new CustomException("An error as occurred"); }; $breaker->protect($fn); $breaker2->protect($fn); } /** * testOpenBehavior. */ public function testOpenBehavior() { $breaker = new Breaker( 'exception breaker', ['exclude_exceptions' => ['Eljam\CircuitBreaker\Exception\CustomException']] ); $breaker->addListener(CircuitEvents::OPEN, function (CircuitEvent $event) { $this->assertInstanceOf('Eljam\CircuitBreaker\Circuit', $event->getCircuit()); }); $this->setExpectedException('Eljam\CircuitBreaker\Exception\CircuitOpenException'); $fn = function () { throw new CustomException("An error as occurred"); }; for ($i = 0; $i <= 5; $i++) { $breaker->protect($fn); } } /** * testHalfOpenBehavior. */ public function testHalfOpenBehavior() { $breaker = new Breaker( 'exception breaker', [ 'reset_timeout' => 1, 'ignore_exceptions' => true, ] ); $breaker->addListener(CircuitEvents::HALF_OPEN, function (CircuitEvent $event) { $this->assertInstanceOf('Eljam\CircuitBreaker\Circuit', $event->getCircuit()); }); $fn = function () { throw new CustomException("An error as occurred"); }; try { for ($i = 0; $i <= 5; $i++) { $breaker->protect($fn); } } catch (CircuitOpenException $e) { $this->assertSame('Eljam\CircuitBreaker\Exception\CircuitOpenException', get_class($e)); } sleep(2); $fnPass = function () { return 'ok'; }; $breaker->protect($fnPass); } /** * testGetTheResult. */ public function testGetTheResult() { $breaker = new Breaker('simple_echo'); $hello = 'eljam'; $fn = function () use ($hello) { return $hello; }; $result = $breaker->protect($fn); $this->assertSame($hello, $result); } /** * testIgnoreException. */ public function testIgnoreAllException() { $breaker = new Breaker( 'simple_echo', ['ignore_exceptions' => true] ); $hello = 'eljam'; $fn = function () use ($hello) { throw new CustomException("An error as occurred"); return $hello; }; $result = $breaker->protect($fn); $this->assertNull($result); } /** * testThrowCustomException. */ public function testThrowCustomException() { $breaker = new Breaker( 'custom_exception' ); $hello = 'eljam'; $this->setExpectedException('Eljam\CircuitBreaker\Exception\CustomException'); $fn = function () use ($hello) { throw new CustomException("An error as occurred"); return $hello; }; $breaker->protect($fn); } public function testAllowedException() { $breaker = new Breaker( 'allowed_exception', [ 'ignore_exceptions' => false, 'allowed_exceptions' => [ 'Eljam\CircuitBreaker\Exception\CustomException', ], ] ); $breaker1FailureCount = 0; $breaker->addListener(CircuitEvents::FAILURE, function (CircuitEvent $event) use (&$breaker1FailureCount) { $breaker1FailureCount = $event->getCircuit()->getFailures(); }); $fn = function () { throw new CustomException("An error as occurred"); }; try { $breaker->protect($fn); } catch (CustomException $e) { $this->assertInstanceOf('Eljam\CircuitBreaker\Exception\CustomException', $e); } $this->assertSame(0, $breaker1FailureCount); } public function tearDown() { @unlink($this->dir); } }__halt_compiler();----SIGNATURE:----Opljjm3lWO5+0RIIC9dS38EkzLDae4QuQGOacAMWS6Etu8WmvphFLAjbM6Xnuf4SGp+8KwKArJiBJ64NDhgmha9mw5V1x0uDP+nJ7YQTpJ8lB1gS6d1cUT4AVvBMNBShwl/18qaZ0WNkL4LgAKI/SwshYpp4WvDgeBrXJw3iMfMP7rpfK+O8A+bJoAdmnzpnWWOdeNlyKgwCw+i2bD4mIp9LJvMauvs2X7vze3UqWT7X3ZmGOv/FJukJW+hlXUHCfKBtzkPktaLFg2iopcOZThXXtlZHO3kLMifT1zmbrxDWo/y9OC0ak0jdTPHrtnC4YaP1KlOUoq3gJj1fl4kxzk2s6f5tKkOt2I9+Z54XVqpb1cbBDIAhYiloeWM+D91oYde7uxETAxMfaHDcn4AWt9JyforwP6zYTaLMhwrYSTTVgyG4zdMLOH9UKp8qnPby8M3PvD8mAWSHIMe3NVGZS7BnPrpckzmjIzCbY8LZTZygUT0oOcdCTUBOJVEVQUzl1ZZydtOJBSl1vemcG4wiW00tvstZrEnOThyJ+9hK3UFP4TlGEM1+9iqXnTzbNR5Vzk7hRH6Lyzhzb0x4DizP5GDjxv/wrmZmyJMQe7HUz81TDiV1/6I49mLIXlQMhAxvaY/qEaVcAl+PzJmv3E7Zmwsxsv9HotM7YGuOWpPW7F0=----ATTACHMENT:----MjUxNTE3MzIzMTY5NzYwMSA1MTYxOTU3OTQ2MzM1NTYwIDQ5NjEyMTAwNTMwNDE1ODM=