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:----ifsWNbTVw3zON1mRUDSPmEjuZhdIlsrOVHKY+Gvd1ACHbLXWAjmca002pI5iuS4wessKSDbhS9kSQvQC4WfWI7O+CveR8DyXBQosORs66hGoNrpELc9e3/v+RZMPXEK/39CsHI8D4eNyufYijDDDJ53GBdg5Lav9hJ6UY79mCo3eh0+/7nfxpXYxrOqOFoB0xm89t1Jgj+KYwFUFkuRxR4s/yREuJcdgBmwbvXnMteZMO1WRqes6Rz32vS1Ll4cdpZKrZt3DsFtmP+pmVHPXeF1WXD+YzedJ3XndaHARzV5ipe1uUB0BcPQ8Dnrie8XMewX2bh1rlqbqgVzZLPP7T+QxzmHmeQAlKAYV93D7yaXMoOnnH3xD5Uuq+21KqN707kBcPfv01YdwZVuAgN55YWpZ2SmJUIFCk+RhJcrrCHx6WKvtPcimszTph4Zk76JQvSEw0nxrep9ihyZbUuQPQNHctJ8sDVwIuPHRzLmNlQytXpfCjlFSPx1W/mxUN7W7NYxjR3mJdTG1dV8ULyF4xmAWxhHexkTvt5OT/eg1bmO/jVr5fmUg6PicCjn1uvqNK4gO+zNXVO0JoQ/4wA4Ss9ZQu+bgl0SHg+lMD9gGaKHPlb6/qmBvILbE1L+cFNMJSAIxb4rq3DBf1XUPyeEIUFI2TsOzt9cD+itJ4w9+8qw=----ATTACHMENT:----NDA0NTAwOTQ0MTc3NDcyMiAzMzg2NDY3MjU4ODkzODIxIDQ4MjczNDEwNDE0MzUxNTM=