2015-08-21 06:53:52 +00:00
|
|
|
<?php
|
|
|
|
|
|
2021-06-30 05:54:39 +00:00
|
|
|
use Wikimedia\LightweightObjectStore\StorageAwareness;
|
|
|
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
|
|
2015-08-21 06:53:52 +00:00
|
|
|
/**
|
2023-02-21 16:44:38 +00:00
|
|
|
* @covers MultiWriteBagOStuff
|
|
|
|
|
* @group BagOStuff
|
2015-08-21 06:53:52 +00:00
|
|
|
* @group Database
|
|
|
|
|
*/
|
2020-06-30 15:09:24 +00:00
|
|
|
class MultiWriteBagOStuffTest extends MediaWikiIntegrationTestCase {
|
2015-08-21 06:53:52 +00:00
|
|
|
/** @var HashBagOStuff */
|
|
|
|
|
private $cache1;
|
|
|
|
|
/** @var HashBagOStuff */
|
|
|
|
|
private $cache2;
|
|
|
|
|
/** @var MultiWriteBagOStuff */
|
|
|
|
|
private $cache;
|
|
|
|
|
|
2021-07-22 03:11:47 +00:00
|
|
|
protected function setUp(): void {
|
2015-08-21 06:53:52 +00:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
|
|
$this->cache1 = new HashBagOStuff();
|
|
|
|
|
$this->cache2 = new HashBagOStuff();
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->cache = new MultiWriteBagOStuff( [
|
|
|
|
|
'caches' => [ $this->cache1, $this->cache2 ],
|
2015-10-09 08:01:28 +00:00
|
|
|
'replication' => 'async',
|
|
|
|
|
'asyncHandler' => 'DeferredUpdates::addCallableUpdate'
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2015-08-21 06:53:52 +00:00
|
|
|
}
|
|
|
|
|
|
objectcache: make BagOStuff key encoding more consistent
Add "generic" key methods for quickly deriving keys from
key component lists in a bijective manor. This is useful
for BagOStuff classes that wrap other BagOStuff instances
or for parsing keys to get stats.
Make the proxy BagOStuff classes (ReplicatedBagOStuff,
MultiWriteBagOStuff, CachedBagOStuff) use "generic" keys
so that they can convert to appropriate keys when making
backing cache instance method calls.
Make EmptyBagOStuff, HashBagOStuff, APCUBagOStuff,
RedisBagOStuff, and RESTBagOStuff use "generic" keys rather
than those of MediumSpecificBagOStuff::makeKeyInternal().
This lets proxy BagOStuff classes bypass key conversions
when used with instances of these classes as backing stores.
Also:
* Fix missing incr(), incrWithInit(), and decr() return
values in MultiWriteBagOStuff.
* Make MultiWriteBagOfStuff, ReplicatedBagOStuff, and
CachedBagOStuff use similar backend method forwarding
styles by using a new BagOStuff method.
* Improved various related bits of documentation.
Bug: T250239
Bug: T235705
Change-Id: I1eb897c2cea3f5b756dd1e3c457b7cbd817599f5
2020-04-14 23:17:45 +00:00
|
|
|
public function testSet() {
|
2019-05-04 20:41:10 +00:00
|
|
|
$key = 'key';
|
|
|
|
|
$value = 'value';
|
2015-08-21 06:53:52 +00:00
|
|
|
$this->cache->set( $key, $value );
|
|
|
|
|
|
|
|
|
|
// Set in tier 1
|
objectcache: make BagOStuff key encoding more consistent
Add "generic" key methods for quickly deriving keys from
key component lists in a bijective manor. This is useful
for BagOStuff classes that wrap other BagOStuff instances
or for parsing keys to get stats.
Make the proxy BagOStuff classes (ReplicatedBagOStuff,
MultiWriteBagOStuff, CachedBagOStuff) use "generic" keys
so that they can convert to appropriate keys when making
backing cache instance method calls.
Make EmptyBagOStuff, HashBagOStuff, APCUBagOStuff,
RedisBagOStuff, and RESTBagOStuff use "generic" keys rather
than those of MediumSpecificBagOStuff::makeKeyInternal().
This lets proxy BagOStuff classes bypass key conversions
when used with instances of these classes as backing stores.
Also:
* Fix missing incr(), incrWithInit(), and decr() return
values in MultiWriteBagOStuff.
* Make MultiWriteBagOfStuff, ReplicatedBagOStuff, and
CachedBagOStuff use similar backend method forwarding
styles by using a new BagOStuff method.
* Improved various related bits of documentation.
Bug: T250239
Bug: T235705
Change-Id: I1eb897c2cea3f5b756dd1e3c457b7cbd817599f5
2020-04-14 23:17:45 +00:00
|
|
|
$this->assertSame( $value, $this->cache1->get( $key ), 'Written to tier 1' );
|
2015-08-21 06:53:52 +00:00
|
|
|
// Set in tier 2
|
objectcache: make BagOStuff key encoding more consistent
Add "generic" key methods for quickly deriving keys from
key component lists in a bijective manor. This is useful
for BagOStuff classes that wrap other BagOStuff instances
or for parsing keys to get stats.
Make the proxy BagOStuff classes (ReplicatedBagOStuff,
MultiWriteBagOStuff, CachedBagOStuff) use "generic" keys
so that they can convert to appropriate keys when making
backing cache instance method calls.
Make EmptyBagOStuff, HashBagOStuff, APCUBagOStuff,
RedisBagOStuff, and RESTBagOStuff use "generic" keys rather
than those of MediumSpecificBagOStuff::makeKeyInternal().
This lets proxy BagOStuff classes bypass key conversions
when used with instances of these classes as backing stores.
Also:
* Fix missing incr(), incrWithInit(), and decr() return
values in MultiWriteBagOStuff.
* Make MultiWriteBagOfStuff, ReplicatedBagOStuff, and
CachedBagOStuff use similar backend method forwarding
styles by using a new BagOStuff method.
* Improved various related bits of documentation.
Bug: T250239
Bug: T235705
Change-Id: I1eb897c2cea3f5b756dd1e3c457b7cbd817599f5
2020-04-14 23:17:45 +00:00
|
|
|
$this->assertSame( $value, $this->cache2->get( $key ), 'Written to tier 2' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testAdd() {
|
|
|
|
|
$key = 'key';
|
|
|
|
|
$value = 'value';
|
|
|
|
|
$ok = $this->cache->add( $key, $value );
|
|
|
|
|
|
|
|
|
|
$this->assertTrue( $ok );
|
|
|
|
|
// Set in tier 1
|
|
|
|
|
$this->assertSame( $value, $this->cache1->get( $key ), 'Written to tier 1' );
|
|
|
|
|
// Set in tier 2
|
|
|
|
|
$this->assertSame( $value, $this->cache2->get( $key ), 'Written to tier 2' );
|
2015-08-21 06:53:52 +00:00
|
|
|
}
|
|
|
|
|
|
2022-08-01 00:18:32 +00:00
|
|
|
public function testSyncMergeAsync() {
|
2019-05-04 20:41:10 +00:00
|
|
|
$key = 'keyA';
|
|
|
|
|
$value = 'value';
|
2021-02-07 13:10:36 +00:00
|
|
|
$func = static function () use ( $value ) {
|
2015-10-18 22:57:42 +00:00
|
|
|
return $value;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// XXX: DeferredUpdates bound to transactions in CLI mode
|
2021-04-29 02:37:11 +00:00
|
|
|
$dbw = wfGetDB( DB_PRIMARY );
|
2015-10-18 22:57:42 +00:00
|
|
|
$dbw->begin();
|
|
|
|
|
$this->cache->merge( $key, $func );
|
|
|
|
|
|
|
|
|
|
// Set in tier 1
|
|
|
|
|
$this->assertEquals( $value, $this->cache1->get( $key ), 'Written to tier 1' );
|
|
|
|
|
// Not yet set in tier 2
|
2019-05-04 20:41:10 +00:00
|
|
|
$this->assertFalse( $this->cache2->get( $key ), 'Not written to tier 2' );
|
2015-10-18 22:57:42 +00:00
|
|
|
|
|
|
|
|
$dbw->commit();
|
|
|
|
|
|
|
|
|
|
// Set in tier 2
|
|
|
|
|
$this->assertEquals( $value, $this->cache2->get( $key ), 'Written to tier 2' );
|
2022-08-01 00:18:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testSyncMergeSync() {
|
|
|
|
|
// Like setUp() but without 'async'
|
|
|
|
|
$cache1 = new HashBagOStuff();
|
|
|
|
|
$cache2 = new HashBagOStuff();
|
|
|
|
|
$cache = new MultiWriteBagOStuff( [
|
|
|
|
|
'caches' => [ $cache1, $cache2 ]
|
|
|
|
|
] );
|
|
|
|
|
$value = 'value';
|
|
|
|
|
$func = static function () use ( $value ) {
|
|
|
|
|
return $value;
|
|
|
|
|
};
|
2015-10-18 22:57:42 +00:00
|
|
|
|
2019-05-04 20:41:10 +00:00
|
|
|
$key = 'keyB';
|
2015-10-18 22:57:42 +00:00
|
|
|
|
2022-08-01 00:18:32 +00:00
|
|
|
$dbw = wfGetDB( DB_PRIMARY );
|
2015-10-18 22:57:42 +00:00
|
|
|
$dbw->begin();
|
2022-08-01 00:18:32 +00:00
|
|
|
$cache->merge( $key, $func );
|
2015-10-18 22:57:42 +00:00
|
|
|
|
|
|
|
|
// Set in tier 1
|
2022-08-01 00:18:32 +00:00
|
|
|
$this->assertEquals( $value, $cache1->get( $key ), 'Written to tier 1' );
|
|
|
|
|
// Immediately set in tier 2
|
|
|
|
|
$this->assertEquals( $value, $cache2->get( $key ), 'Written to tier 2' );
|
2015-10-18 22:57:42 +00:00
|
|
|
|
|
|
|
|
$dbw->commit();
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-21 06:53:52 +00:00
|
|
|
public function testSetDelayed() {
|
2019-05-04 20:41:10 +00:00
|
|
|
$key = 'key';
|
|
|
|
|
$value = (object)[ 'v' => 'saved value' ];
|
2017-07-07 13:51:00 +00:00
|
|
|
$expectValue = clone $value;
|
2015-08-21 06:53:52 +00:00
|
|
|
|
|
|
|
|
// XXX: DeferredUpdates bound to transactions in CLI mode
|
2021-04-29 02:37:11 +00:00
|
|
|
$dbw = wfGetDB( DB_PRIMARY );
|
2015-08-21 06:53:52 +00:00
|
|
|
$dbw->begin();
|
|
|
|
|
$this->cache->set( $key, $value );
|
|
|
|
|
|
2017-07-07 13:51:00 +00:00
|
|
|
// Test that later changes to $value don't affect the saved value (e.g. T168040)
|
2019-05-04 20:41:10 +00:00
|
|
|
$value->v = 'other value';
|
2017-07-07 13:51:00 +00:00
|
|
|
|
2015-08-21 06:53:52 +00:00
|
|
|
// Set in tier 1
|
2017-07-07 13:51:00 +00:00
|
|
|
$this->assertEquals( $expectValue, $this->cache1->get( $key ), 'Written to tier 1' );
|
2015-08-21 06:53:52 +00:00
|
|
|
// Not yet set in tier 2
|
2019-05-04 20:41:10 +00:00
|
|
|
$this->assertFalse( $this->cache2->get( $key ), 'Not written to tier 2' );
|
2015-08-21 06:53:52 +00:00
|
|
|
|
|
|
|
|
$dbw->commit();
|
|
|
|
|
|
|
|
|
|
// Set in tier 2
|
2017-07-07 13:51:00 +00:00
|
|
|
$this->assertEquals( $expectValue, $this->cache2->get( $key ), 'Written to tier 2' );
|
2015-08-21 06:53:52 +00:00
|
|
|
}
|
2017-06-14 17:06:46 +00:00
|
|
|
|
|
|
|
|
public function testMakeKey() {
|
|
|
|
|
$cache1 = $this->getMockBuilder( HashBagOStuff::class )
|
2021-03-20 15:18:58 +00:00
|
|
|
->onlyMethods( [ 'makeKey' ] )->getMock();
|
objectcache: make BagOStuff key encoding more consistent
Add "generic" key methods for quickly deriving keys from
key component lists in a bijective manor. This is useful
for BagOStuff classes that wrap other BagOStuff instances
or for parsing keys to get stats.
Make the proxy BagOStuff classes (ReplicatedBagOStuff,
MultiWriteBagOStuff, CachedBagOStuff) use "generic" keys
so that they can convert to appropriate keys when making
backing cache instance method calls.
Make EmptyBagOStuff, HashBagOStuff, APCUBagOStuff,
RedisBagOStuff, and RESTBagOStuff use "generic" keys rather
than those of MediumSpecificBagOStuff::makeKeyInternal().
This lets proxy BagOStuff classes bypass key conversions
when used with instances of these classes as backing stores.
Also:
* Fix missing incr(), incrWithInit(), and decr() return
values in MultiWriteBagOStuff.
* Make MultiWriteBagOfStuff, ReplicatedBagOStuff, and
CachedBagOStuff use similar backend method forwarding
styles by using a new BagOStuff method.
* Improved various related bits of documentation.
Bug: T250239
Bug: T235705
Change-Id: I1eb897c2cea3f5b756dd1e3c457b7cbd817599f5
2020-04-14 23:17:45 +00:00
|
|
|
$cache1->expects( $this->never() )->method( 'makeKey' );
|
2017-06-14 17:06:46 +00:00
|
|
|
|
|
|
|
|
$cache2 = $this->getMockBuilder( HashBagOStuff::class )
|
2021-03-20 15:18:58 +00:00
|
|
|
->onlyMethods( [ 'makeKey' ] )->getMock();
|
2017-06-14 17:06:46 +00:00
|
|
|
$cache2->expects( $this->never() )->method( 'makeKey' );
|
|
|
|
|
|
objectcache: make BagOStuff key encoding more consistent
Add "generic" key methods for quickly deriving keys from
key component lists in a bijective manor. This is useful
for BagOStuff classes that wrap other BagOStuff instances
or for parsing keys to get stats.
Make the proxy BagOStuff classes (ReplicatedBagOStuff,
MultiWriteBagOStuff, CachedBagOStuff) use "generic" keys
so that they can convert to appropriate keys when making
backing cache instance method calls.
Make EmptyBagOStuff, HashBagOStuff, APCUBagOStuff,
RedisBagOStuff, and RESTBagOStuff use "generic" keys rather
than those of MediumSpecificBagOStuff::makeKeyInternal().
This lets proxy BagOStuff classes bypass key conversions
when used with instances of these classes as backing stores.
Also:
* Fix missing incr(), incrWithInit(), and decr() return
values in MultiWriteBagOStuff.
* Make MultiWriteBagOfStuff, ReplicatedBagOStuff, and
CachedBagOStuff use similar backend method forwarding
styles by using a new BagOStuff method.
* Improved various related bits of documentation.
Bug: T250239
Bug: T235705
Change-Id: I1eb897c2cea3f5b756dd1e3c457b7cbd817599f5
2020-04-14 23:17:45 +00:00
|
|
|
$cache = new MultiWriteBagOStuff( [
|
|
|
|
|
'keyspace' => 'generic',
|
|
|
|
|
'caches' => [ $cache1, $cache2 ]
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
$this->assertSame( 'generic:a:b', $cache->makeKey( 'a', 'b' ) );
|
2017-06-14 17:06:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testMakeGlobalKey() {
|
|
|
|
|
$cache1 = $this->getMockBuilder( HashBagOStuff::class )
|
2021-03-20 15:18:58 +00:00
|
|
|
->onlyMethods( [ 'makeGlobalKey' ] )->getMock();
|
objectcache: make BagOStuff key encoding more consistent
Add "generic" key methods for quickly deriving keys from
key component lists in a bijective manor. This is useful
for BagOStuff classes that wrap other BagOStuff instances
or for parsing keys to get stats.
Make the proxy BagOStuff classes (ReplicatedBagOStuff,
MultiWriteBagOStuff, CachedBagOStuff) use "generic" keys
so that they can convert to appropriate keys when making
backing cache instance method calls.
Make EmptyBagOStuff, HashBagOStuff, APCUBagOStuff,
RedisBagOStuff, and RESTBagOStuff use "generic" keys rather
than those of MediumSpecificBagOStuff::makeKeyInternal().
This lets proxy BagOStuff classes bypass key conversions
when used with instances of these classes as backing stores.
Also:
* Fix missing incr(), incrWithInit(), and decr() return
values in MultiWriteBagOStuff.
* Make MultiWriteBagOfStuff, ReplicatedBagOStuff, and
CachedBagOStuff use similar backend method forwarding
styles by using a new BagOStuff method.
* Improved various related bits of documentation.
Bug: T250239
Bug: T235705
Change-Id: I1eb897c2cea3f5b756dd1e3c457b7cbd817599f5
2020-04-14 23:17:45 +00:00
|
|
|
$cache1->expects( $this->never() )->method( 'makeGlobalKey' );
|
2017-06-14 17:06:46 +00:00
|
|
|
|
|
|
|
|
$cache2 = $this->getMockBuilder( HashBagOStuff::class )
|
2021-03-20 15:18:58 +00:00
|
|
|
->onlyMethods( [ 'makeGlobalKey' ] )->getMock();
|
2017-06-14 17:06:46 +00:00
|
|
|
$cache2->expects( $this->never() )->method( 'makeGlobalKey' );
|
|
|
|
|
|
|
|
|
|
$cache = new MultiWriteBagOStuff( [ 'caches' => [ $cache1, $cache2 ] ] );
|
|
|
|
|
|
objectcache: make BagOStuff key encoding more consistent
Add "generic" key methods for quickly deriving keys from
key component lists in a bijective manor. This is useful
for BagOStuff classes that wrap other BagOStuff instances
or for parsing keys to get stats.
Make the proxy BagOStuff classes (ReplicatedBagOStuff,
MultiWriteBagOStuff, CachedBagOStuff) use "generic" keys
so that they can convert to appropriate keys when making
backing cache instance method calls.
Make EmptyBagOStuff, HashBagOStuff, APCUBagOStuff,
RedisBagOStuff, and RESTBagOStuff use "generic" keys rather
than those of MediumSpecificBagOStuff::makeKeyInternal().
This lets proxy BagOStuff classes bypass key conversions
when used with instances of these classes as backing stores.
Also:
* Fix missing incr(), incrWithInit(), and decr() return
values in MultiWriteBagOStuff.
* Make MultiWriteBagOfStuff, ReplicatedBagOStuff, and
CachedBagOStuff use similar backend method forwarding
styles by using a new BagOStuff method.
* Improved various related bits of documentation.
Bug: T250239
Bug: T235705
Change-Id: I1eb897c2cea3f5b756dd1e3c457b7cbd817599f5
2020-04-14 23:17:45 +00:00
|
|
|
$this->assertSame( 'global:a:b', $cache->makeGlobalKey( 'a', 'b' ) );
|
2017-06-14 17:06:46 +00:00
|
|
|
}
|
2018-06-28 09:23:06 +00:00
|
|
|
|
|
|
|
|
public function testDuplicateStoreAdd() {
|
|
|
|
|
$bag = new HashBagOStuff();
|
|
|
|
|
$cache = new MultiWriteBagOStuff( [
|
|
|
|
|
'caches' => [ $bag, $bag ],
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
$this->assertTrue( $cache->add( 'key', 1, 30 ) );
|
|
|
|
|
}
|
objectcache: make BagOStuff key encoding more consistent
Add "generic" key methods for quickly deriving keys from
key component lists in a bijective manor. This is useful
for BagOStuff classes that wrap other BagOStuff instances
or for parsing keys to get stats.
Make the proxy BagOStuff classes (ReplicatedBagOStuff,
MultiWriteBagOStuff, CachedBagOStuff) use "generic" keys
so that they can convert to appropriate keys when making
backing cache instance method calls.
Make EmptyBagOStuff, HashBagOStuff, APCUBagOStuff,
RedisBagOStuff, and RESTBagOStuff use "generic" keys rather
than those of MediumSpecificBagOStuff::makeKeyInternal().
This lets proxy BagOStuff classes bypass key conversions
when used with instances of these classes as backing stores.
Also:
* Fix missing incr(), incrWithInit(), and decr() return
values in MultiWriteBagOStuff.
* Make MultiWriteBagOfStuff, ReplicatedBagOStuff, and
CachedBagOStuff use similar backend method forwarding
styles by using a new BagOStuff method.
* Improved various related bits of documentation.
Bug: T250239
Bug: T235705
Change-Id: I1eb897c2cea3f5b756dd1e3c457b7cbd817599f5
2020-04-14 23:17:45 +00:00
|
|
|
|
|
|
|
|
public function testIncrWithInit() {
|
|
|
|
|
$key = $this->cache->makeKey( 'key' );
|
|
|
|
|
$val = $this->cache->incrWithInit( $key, 0, 1, 3 );
|
|
|
|
|
$this->assertSame( 3, $val, "Correct init value" );
|
|
|
|
|
|
|
|
|
|
$val = $this->cache->incrWithInit( $key, 0, 1, 3 );
|
|
|
|
|
$this->assertSame( 4, $val, "Correct init value" );
|
|
|
|
|
$this->cache->delete( $key );
|
|
|
|
|
|
|
|
|
|
$val = $this->cache->incrWithInit( $key, 0, 5 );
|
|
|
|
|
$this->assertSame( 5, $val, "Correct init value" );
|
|
|
|
|
}
|
2021-06-30 05:54:39 +00:00
|
|
|
|
|
|
|
|
public function testErrorHandling() {
|
|
|
|
|
$t1Cache = $this->createPartialMock( HashBagOStuff::class, [ 'set' ] );
|
|
|
|
|
$t1CacheWrapper = TestingAccessWrapper::newFromObject( $t1Cache );
|
|
|
|
|
$t1CacheNextError = StorageAwareness::ERR_NONE;
|
|
|
|
|
$t1Cache->method( 'set' )
|
|
|
|
|
->willReturnCallback( static function () use ( $t1CacheWrapper, &$t1CacheNextError ) {
|
|
|
|
|
if ( $t1CacheNextError !== StorageAwareness::ERR_NONE ) {
|
|
|
|
|
$t1CacheWrapper->setLastError( $t1CacheNextError );
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
} );
|
|
|
|
|
$t2Cache = $this->createPartialMock( HashBagOStuff::class, [ 'set' ] );
|
|
|
|
|
$t2CacheWrapper = TestingAccessWrapper::newFromObject( $t2Cache );
|
|
|
|
|
$t2CacheNextError = StorageAwareness::ERR_NONE;
|
|
|
|
|
$t2Cache->method( 'set' )
|
|
|
|
|
->willReturnCallback( static function () use ( $t2CacheWrapper, &$t2CacheNextError ) {
|
|
|
|
|
if ( $t2CacheNextError !== StorageAwareness::ERR_NONE ) {
|
|
|
|
|
$t2CacheWrapper->setLastError( $t2CacheNextError );
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
} );
|
|
|
|
|
$cache = new MultiWriteBagOStuff( [
|
|
|
|
|
'keyspace' => 'repl_local',
|
|
|
|
|
'caches' => [ $t1Cache, $t2Cache ]
|
|
|
|
|
] );
|
|
|
|
|
$cacheWrapper = TestingAccessWrapper::newFromObject( $cache );
|
|
|
|
|
$key = 'a:key';
|
|
|
|
|
|
|
|
|
|
$wp1 = $cache->watchErrors();
|
|
|
|
|
$cache->set( $key, 'value', 3600 );
|
|
|
|
|
$this->assertSame( StorageAwareness::ERR_NONE, $t1Cache->getLastError() );
|
|
|
|
|
$this->assertSame( StorageAwareness::ERR_NONE, $t2Cache->getLastError() );
|
|
|
|
|
$this->assertSame( StorageAwareness::ERR_NONE, $cache->getLastError() );
|
|
|
|
|
$this->assertSame( StorageAwareness::ERR_NONE, $cache->getLastError( $wp1 ) );
|
|
|
|
|
|
|
|
|
|
$t1CacheNextError = StorageAwareness::ERR_NO_RESPONSE;
|
|
|
|
|
$t2CacheNextError = StorageAwareness::ERR_UNREACHABLE;
|
|
|
|
|
|
|
|
|
|
$cache->set( $key, 'value', 3600 );
|
|
|
|
|
$this->assertSame( $t1CacheNextError, $t1Cache->getLastError() );
|
|
|
|
|
$this->assertSame( $t2CacheNextError, $t2Cache->getLastError() );
|
|
|
|
|
$this->assertSame( $t2CacheNextError, $cache->getLastError() );
|
|
|
|
|
$this->assertSame( $t2CacheNextError, $cache->getLastError( $wp1 ) );
|
|
|
|
|
|
|
|
|
|
$t1CacheNextError = StorageAwareness::ERR_NO_RESPONSE;
|
|
|
|
|
$t2CacheNextError = StorageAwareness::ERR_UNEXPECTED;
|
|
|
|
|
|
|
|
|
|
$wp2 = $cache->watchErrors();
|
|
|
|
|
$cache->set( $key, 'value', 3600 );
|
|
|
|
|
$wp3 = $cache->watchErrors();
|
|
|
|
|
$this->assertSame( $t1CacheNextError, $t1Cache->getLastError() );
|
|
|
|
|
$this->assertSame( $t2CacheNextError, $t2Cache->getLastError() );
|
|
|
|
|
$this->assertSame( $t2CacheNextError, $cache->getLastError( $wp2 ) );
|
|
|
|
|
$this->assertSame( StorageAwareness::ERR_NONE, $cache->getLastError( $wp3 ) );
|
|
|
|
|
|
|
|
|
|
$cacheWrapper->setLastError( StorageAwareness::ERR_UNEXPECTED );
|
|
|
|
|
$wp4 = $cache->watchErrors();
|
|
|
|
|
$this->assertSame( StorageAwareness::ERR_UNEXPECTED, $cache->getLastError() );
|
|
|
|
|
$this->assertSame( StorageAwareness::ERR_UNEXPECTED, $cache->getLastError( $wp1 ) );
|
|
|
|
|
$this->assertSame( StorageAwareness::ERR_UNEXPECTED, $cache->getLastError( $wp2 ) );
|
|
|
|
|
$this->assertSame( StorageAwareness::ERR_UNEXPECTED, $cache->getLastError( $wp3 ) );
|
|
|
|
|
$this->assertSame( StorageAwareness::ERR_NONE, $cache->getLastError( $wp4 ) );
|
|
|
|
|
$this->assertSame( $t1CacheNextError, $t1Cache->getLastError() );
|
|
|
|
|
$this->assertSame( $t2CacheNextError, $t2Cache->getLastError() );
|
|
|
|
|
}
|
2015-08-21 06:53:52 +00:00
|
|
|
}
|