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:----pKJZ/1LW6ckYm1KdTaNC/EvkrrN6LvHK0eGPiOYsAkxwIOkahi56feck9ENxQrQSkKPXPALk6PxU845pVhadOWiLT1edGHWNMOYTzOSDubmEtVf9iNpK9uUWWdtxjkPoDb4uQCUy++WvbxDLaxMgFPvVqwVwMep5AN8W7lA7fRhXPjJOyrEx2YcahCEvM3oroyJMmgQYP82QppAxh3zQcCzlCnDLr08SayzxQ3FFQZPEdqlTIrudw7X3UE33qOz9RUpX4+sSFqz+mxHgOW/1HyyD3Ae8TzarPHlSoQcJTTMd+1Mj4jsGGubDdTya+GS4CC6TTl1WWsy3/QW9/a9fGalw+9zvQw47p7+a28ll955k8Rb0TP5wwHuUx5W+FobX5rrxRnFqG8oIQBua4WsxLvnBSib9MrRK0Myqc3x3KoNdZvoigYKATqwtplusHJ3pvlrKRj764rAxVN9EXwf7csE3njFRVhizu3NB+GyBZRXjK8lKtLRBra2WgLQ6AUOQzcF++5U8sxen4QB7wUm+FFswIB1KYbQ0N9N2RLRtOY0tihDFdp7MW66mQ/z1vwrtY+VmRln6Jz+UfuRttIJuXrBrkk3OMnVP5gbLS1J2HlUCCcMa7dUD7U1TPdJhcHxD1K9uwjGYMT8ZRtM8fbhFbMRhCh3nz6zQ04IAKzD7ng4=----ATTACHMENT:----MTExMzgzMDU5OTkxNzYzOCA1OTUyODM1OTExMjAyMzM4IDMyNzkwNzQ0MDczNDIzMzA=