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:----Btet2PCycj9MboCfFtFHL3xWGHuNnAzvo0bWkQavOTei3w1M6wZ85+1b1qE+05tJ5st4D50xdTg5syY/4vZMCOz0YUuOOBEI4B5BMqpF5xKzvwUvLc7ip7XwQMsfvexer61T1dn0fL5i33SUOMn157K8WgV/6lcEuaX7AyHAoT8qY08nRAx2bUb6Fa0IVUoW7uo/hsArYl8FxHrIg8SxJexkVX/XbfdIwhK36QyHHHEx1L41UKV6PSypzDwkombBz7OlAXhfnOHSY3zvOKv29pUtybOn12O8aaeLicRZhA8gtQWK8aYVgGRIleCf1g+R6b34JWubIZNqc6NngagLWITRXU71zmU15PjDWrE7t8n+qrK4Kp6nc68WOVR2pPN6ZEmSK4MuCyI9/uOapZn6Xv25K12ZrVtOu/q/Bj+pPhrTwanWFicmTP92JWUDxUX/gOWC/AK9gOME6vNCu4av6BCuZjaC1XxzmVKVe3fsG3SNTGrHPEBmOeo+mBywBNo3Iwzm9aiy9CxgVV9g5/FUHoPE2ZkWI9ol7ZcjGlk6rw7Gb5F1VsaColjcvE1X5hz7NnnRs5VHU1b9nv2r/fpTn+FteK+naIcLStM5LCNVenNnaN4BtFc7iIdXscyz2ssLXR21/0QGhJFaM5FMz4/appXu/QU/bi2gVWzOzTeCPV8=----ATTACHMENT:----NDM5MzE4NzkwNTg2NDY3MCA1ODA5NDE2MTc3NDY4MjY4IDU0NzIwNjQ4MTU3MTA1OQ==