jenkins-bot has submitted this change and it was merged.

Change subject: Stop cas support
......................................................................


Stop cas support

I3ef82226231f7e03f7493ae042cad22339f4c869 makes all BagOStuff
cas implementations protected.
Flow wasn't really using that, so let's remove support for it.
Well, it is using it as part of it's merge, but that part still
has access to the BagOStuff's cas methods, so we're good there!

Change-Id: I566f5d70f14ffe4c6f0c290f0666cff9637908bb
---
M includes/Data/BagOStuff/BufferedBagOStuff.php
M includes/Data/BufferedCache.php
M tests/phpunit/Data/BagOStuff/BufferedBagOStuffTest.php
3 files changed, 27 insertions(+), 86 deletions(-)

Approvals:
  MaxSem: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/Data/BagOStuff/BufferedBagOStuff.php 
b/includes/Data/BagOStuff/BufferedBagOStuff.php
index 680d023..0110cd3 100644
--- a/includes/Data/BagOStuff/BufferedBagOStuff.php
+++ b/includes/Data/BagOStuff/BufferedBagOStuff.php
@@ -231,7 +231,8 @@
         * @param int $exptime
         * @return bool
         */
-       public function cas( $casToken, $key, $value, $exptime = 0 ) {
+       protected function cas( $casToken, $key, $value, $exptime = 0 ) {
+               $that = $this;
                $cache = $this->cache;
                $originalValue = isset( $this->casTokens[$casToken] ) ? 
$this->casTokens[$casToken] : null;
 
@@ -242,7 +243,9 @@
                 * @param int $exptime
                 * @return bool
                 */
-               $cas = function ( $casToken, $key, $value, $exptime = 0 ) use ( 
$cache, $originalValue ) {
+               $cas = function ( $casToken, $key, $value, $exptime = 0 )
+                       use ( $that, $cache, $originalValue )
+               {
                        // Check if given (local) CAS token was known
                        if ( $originalValue === null ) {
                                return false;
@@ -254,8 +257,16 @@
                        // Check if the value we just read from real cache is 
still the same
                        // as the one we saved when doing the original fetch
                        if ( serialize( $current ) === $originalValue ) {
+                               /*
+                                * Note that all BagOStuff::cas implementations 
are protected!
+                                * We can still call it from here because this 
class too extends
+                                * from BagOStuff, where the cas method is 
defined. PHP will
+                                * allow us access because "because the 
implementation specific
+                                * details are already known."
+                                */
+
                                // Everything still checked out, let's CAS the 
value for real now
-                               return $cache->cas( $casToken, $key, $value, 
$exptime );
+                               return $that->immediateCasInternal( $casToken, 
$key, $value, $exptime );
                        }
 
                        return false;
@@ -277,6 +288,19 @@
        }
 
        /**
+        * Internal function to let closures access protected cache object 
methods
+        *
+        * @param mixed $casToken
+        * @param string $key
+        * @param mixed $value
+        * @param int $exptime
+        * @return type
+        */
+       public function immediateCasInternal( $casToken, $key, $value, $exptime 
) {
+               return $this->cache->cas( $casToken, $key, $value, $exptime );
+       }
+
+       /**
         * @param string $key
         * @param int $time
         * @return bool
diff --git a/includes/Data/BufferedCache.php b/includes/Data/BufferedCache.php
index 12c73f8..94cf5ee 100644
--- a/includes/Data/BufferedCache.php
+++ b/includes/Data/BufferedCache.php
@@ -74,16 +74,6 @@
        }
 
        /**
-        * @param mixed $casToken
-        * @param string $key
-        * @param mixed $value
-        * @return bool
-        */
-       public function cas( $casToken, $key, $value ) {
-               return $this->cache->cas( $casToken, $key, $value, 
$this->exptime );
-       }
-
-       /**
         * @param string $key
         * @param int $time
         * @return bool
diff --git a/tests/phpunit/Data/BagOStuff/BufferedBagOStuffTest.php 
b/tests/phpunit/Data/BagOStuff/BufferedBagOStuffTest.php
index 30c7aa3..1b5368e 100644
--- a/tests/phpunit/Data/BagOStuff/BufferedBagOStuffTest.php
+++ b/tests/phpunit/Data/BagOStuff/BufferedBagOStuffTest.php
@@ -114,79 +114,6 @@
                $this->assertEquals( false, $this->cache->get( 'key' ) );
        }
 
-       public function testCas() {
-               $this->cache->set( 'key', 'value' );
-
-               $casToken = null;
-               $this->bufferedCache->get( 'key', $casToken );
-               $this->bufferedCache->cas( $casToken, 'key', 'updated-value' );
-
-               // check that the value has been CAS'ed to bufferedcache (only)
-               $this->assertEquals( 'updated-value', 
$this->bufferedCache->get( 'key' ) );
-               $this->assertEquals( 'value', $this->cache->get( 'key' ) );
-
-               $this->bufferedCache->commit();
-
-               // check that the value has also been CAS'ed to real cache
-               $this->assertEquals( 'updated-value', 
$this->bufferedCache->get( 'key' ) );
-               $this->assertEquals( 'updated-value', $this->cache->get( 'key' 
) );
-       }
-
-       public function testConsecutiveCas() {
-               $this->cache->set( 'key', 'value' );
-
-               $casToken = null;
-               $this->bufferedCache->get( 'key', $casToken );
-               $this->bufferedCache->cas( $casToken, 'key', 'updated-value' );
-               $this->bufferedCache->get( 'key', $casToken );
-               $this->bufferedCache->cas( $casToken, 'key', 'updated-value-2' 
);
-
-               // check that the value has been CAS'ed to bufferedcache (only)
-               $this->assertEquals( 'updated-value-2', 
$this->bufferedCache->get( 'key' ) );
-               $this->assertEquals( 'value', $this->cache->get( 'key' ) );
-
-               $this->bufferedCache->commit();
-
-               // check that the value has also been CAS'ed to real cache
-               $this->assertEquals( 'updated-value-2', 
$this->bufferedCache->get( 'key' ) );
-               $this->assertEquals( 'updated-value-2', $this->cache->get( 
'key' ) );
-       }
-
-       public function testCasFailImmediately() {
-               $this->cache->set( 'key', 'value' );
-
-               $casToken = null;
-               $this->bufferedCache->get( 'key', $casToken );
-               $this->bufferedCache->cas( 'wrong-token', 'key', 
'updated-value' );
-
-               $this->bufferedCache->commit();
-
-               // check that the value hasn't been CAS'ed anywhere
-               $this->assertEquals( 'value', $this->bufferedCache->get( 'key' 
) );
-               $this->assertEquals( 'value', $this->cache->get( 'key' ) );
-       }
-
-       public function testCasFailDeferred() {
-               $this->cache->set( 'key', 'value' );
-
-               $casToken = null;
-               $this->bufferedCache->get( 'key', $casToken );
-               $this->bufferedCache->cas( $casToken, 'key', 'updated-value' );
-
-               // something else directly overwrites key in the meantime...
-               $this->cache->set( 'key', 'conflicting-value' );
-
-               // check that the value has been CAS'ed to buffered cache but 
not yet to real cache
-               $this->assertEquals( 'updated-value', 
$this->bufferedCache->get( 'key' ) );
-               $this->assertEquals( 'conflicting-value', $this->cache->get( 
'key' ) );
-
-               $this->bufferedCache->commit();
-
-               // check that the value failed to CAS
-               $this->assertEquals( false, $this->bufferedCache->get( 'key' ) 
);
-               $this->assertEquals( false, $this->cache->get( 'key' ) );
-       }
-
        public function testDelete() {
                $this->cache->set( 'key', 'value' );
 

-- 
To view, visit https://gerrit.wikimedia.org/r/189487
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I566f5d70f14ffe4c6f0c290f0666cff9637908bb
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Matthias Mullie <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: SG <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to