Explorar el Código

ZF-9428: Empty Memcached throwed Exception on getFillingPercentage

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@21519 44c647ce-9c0f-0410-b52a-842ac1e357ba
mabe hace 16 años
padre
commit
bae261e5cc

+ 4 - 4
library/Zend/Cache/Backend/Memcached.php

@@ -381,10 +381,10 @@ class Zend_Cache_Backend_Memcached extends Zend_Cache_Backend implements Zend_Ca
     {
     {
         $mems = $this->_memcache->getExtendedStats();
         $mems = $this->_memcache->getExtendedStats();
 
 
-        $memSize = 0;
-        $memUsed = 0;
+        $memSize = null;
+        $memUsed = null;
         foreach ($mems as $key => $mem) {
         foreach ($mems as $key => $mem) {
-            if ($mem === false || !$mem['limit_maxbytes']) {
+            if ($mem === false) {
                 $this->_log('can\'t get stat from ' . $key);
                 $this->_log('can\'t get stat from ' . $key);
                 continue;
                 continue;
             }
             }
@@ -399,7 +399,7 @@ class Zend_Cache_Backend_Memcached extends Zend_Cache_Backend implements Zend_Ca
             $memUsed += $eachUsed;
             $memUsed += $eachUsed;
         }
         }
 
 
-        if (!$memSize || !$memUsed) {
+        if ($memSize === null || $memUsed === null) {
             Zend_Cache::throwException('Can\'t get filling percentage');
             Zend_Cache::throwException('Can\'t get filling percentage');
         }
         }
 
 

+ 11 - 0
tests/Zend/Cache/CommonExtendedBackendTest.php

@@ -65,6 +65,17 @@ class Zend_Cache_CommonExtendedBackendTest extends Zend_Cache_CommonBackendTest
         $this->assertTrue($res <= 100);
         $this->assertTrue($res <= 100);
     }
     }
 
 
+    public function testGetFillingPercentageOnEmptyBackend()
+    {
+        $this->_instance->setDirectives(array('logging' => false)); // ???
+        $this->_instance->clean(Zend_Cache::CLEANING_MODE_ALL);
+        $res = $this->_instance->getFillingPercentage();
+        $this->_instance->setDirectives(array('logging' => true)); // ???
+        $this->assertTrue(is_integer($res));
+        $this->assertTrue($res >= 0);
+        $this->assertTrue($res <= 100);
+    }
+
     public function testGetIds()
     public function testGetIds()
     {
     {
         if (!($this->_capabilities['get_list'])) {
         if (!($this->_capabilities['get_list'])) {

+ 6 - 0
tests/Zend/Cache/MemcachedBackendTest.php

@@ -167,6 +167,12 @@ class Zend_Cache_MemcachedBackendTest extends Zend_Cache_CommonExtendedBackendTe
         parent::testGetFillingPercentage();
         parent::testGetFillingPercentage();
     }
     }
 
 
+    public function testGetFillingPercentageOnEmptyBackend()
+    {
+        $this->_instance->setDirectives(array('logging' => false));
+        parent::testGetFillingPercentageOnEmptyBackend();
+    }
+
 }
 }