Prechádzať zdrojové kódy

ZF-8897: Zend_Cache_Backend_Memcached: Now getFillingPercentage only throws exception if all server failes

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@20588 44c647ce-9c0f-0410-b52a-842ac1e357ba
mabe 16 rokov pred
rodič
commit
83b4212920

+ 15 - 14
library/Zend/Cache/Backend/Memcached.php

@@ -383,22 +383,23 @@ class Zend_Cache_Backend_Memcached extends Zend_Cache_Backend implements Zend_Ca
         $memSize = 0;
         $memUsed = 0;
         foreach ($mems as $key => $mem) {
-            if ($mem === false) {
-                Zend_Cache::throwException('can\'t get stat from ' . $key);
-            } else {
-                $eachSize = $mem['limit_maxbytes'];
-                if ($eachSize == 0) {
-                    Zend_Cache::throwException('can\'t get memory size from ' . $key);
-                }
-
-                $eachUsed = $mem['bytes'];
-                if ($eachUsed > $eachSize) {
-                    $eachUsed = $eachSize;
-                }
+            if ($mem === false || !$mem['limit_maxbytes']) {
+                $this->_log('can\'t get stat from ' . $key);
+                continue;
+            }
 
-                $memSize += $eachSize;
-                $memUsed += $eachUsed;
+            $eachSize = $mem['limit_maxbytes'];
+            $eachUsed = $mem['bytes'];
+            if ($eachUsed > $eachSize) {
+                $eachUsed = $eachSize;
             }
+
+            $memSize += $eachSize;
+            $memUsed += $eachUsed;
+        }
+
+        if (!$memSize || !$memUsed) {
+            Zend_Cache::throwException('Can\'t get filling percentage');
         }
 
         return ((int) (100. * ($memUsed / $memSize)));

+ 13 - 2
tests/Zend/Cache/MemcachedBackendTest.php

@@ -55,13 +55,18 @@ class Zend_Cache_MemcachedBackendTest extends Zend_Cache_CommonExtendedBackendTe
 
     public function setUp($notag = true)
     {
-        $server = array(
+        $serverValid = array(
             'host' => TESTS_ZEND_CACHE_MEMCACHED_HOST,
             'port' => TESTS_ZEND_CACHE_MEMCACHED_PORT,
             'persistent' => TESTS_ZEND_CACHE_MEMCACHED_PERSISTENT
         );
+        $serverFail = array(
+            'host' => 'not.exist',
+            'port' => TESTS_ZEND_CACHE_MEMCACHED_PORT,
+            'persistent' => TESTS_ZEND_CACHE_MEMCACHED_PERSISTENT
+        );
         $options = array(
-            'servers' => array(0 => $server)
+            'servers' => array($serverValid, $serverFail)
         );
         $this->_instance = new Zend_Cache_Backend_Memcached($options);
         parent::setUp($notag);
@@ -156,6 +161,12 @@ class Zend_Cache_MemcachedBackendTest extends Zend_Cache_CommonExtendedBackendTe
         parent::testGetMetadatas(true);
     }
 
+    public function testGetFillingPercentage()
+    {
+        $this->_instance->setDirectives(array('logging' => false));
+        parent::testGetFillingPercentage();
+    }
+
 }