}
/**
- * @dataProvider provider_testSetAndGet
+ * @dataProvider provideSetAndGet
* @covers WANObjectCache::set()
* @covers WANObjectCache::get()
* @param mixed $value
}
}
- public static function provider_testSetAndGet() {
+ public static function provideSetAndGet() {
return array(
array( 14141, 3 ),
array( 3535.666, 3 ),
);
}
+ /**
+ * @covers WANObjectCache::get()
+ */
public function testGetNotExists() {
$key = wfRandomString();
$curTTL = null;
$this->assertNull( $curTTL, "Non-existing key has null current TTL" );
}
+ /**
+ * @covers WANObjectCache::set()
+ */
public function testSetOver() {
$key = wfRandomString();
for ( $i = 0; $i < 3; ++$i ) {
}
}
+ /**
+ * @covers WANObjectCache::set()
+ */
public function testStaleSet() {
$key = wfRandomString();
$value = wfRandomString();
/**
* @covers WANObjectCache::getWithSetCallback()
+ * @covers WANObjectCache::doGetWithSetCallback()
*/
public function testGetWithSetCallback() {
$cache = $this->cache;
/**
* @covers WANObjectCache::getWithSetCallback()
+ * @covers WANObjectCache::doGetWithSetCallback()
*/
public function testLockTSE() {
$cache = $this->cache;
/**
* @covers WANObjectCache::getWithSetCallback()
+ * @covers WANObjectCache::doGetWithSetCallback()
*/
public function testLockTSESlow() {
$cache = $this->cache;
$this->assertLessThan( 0, $curTTLs[$key2], 'Key 2 has negative current TTL' );
}
+ /**
+ * @covers WANObjectCache::getMulti()
+ * @covers WANObjectCache::processCheckKeys()
+ */
+ public function testGetMultiCheckKeys() {
+ $cache = $this->cache;
+
+ $checkAll = wfRandomString();
+ $check1 = wfRandomString();
+ $check2 = wfRandomString();
+ $check3 = wfRandomString();
+ $value1 = wfRandomString();
+ $value2 = wfRandomString();
+
+ // Fake initial check key to be set in the past. Otherwise we'd have to sleep for
+ // several seconds during the test to assert the behaviour.
+ foreach ( array( $checkAll, $check1, $check2 ) as $checkKey ) {
+ $this->internalCache->set( $cache::TIME_KEY_PREFIX . $checkKey,
+ $cache::PURGE_VAL_PREFIX . microtime( true ) - $cache::HOLDOFF_TTL, $cache::CHECK_KEY_TTL );
+ }
+
+ $cache->set( 'key1', $value1, 10 );
+ $cache->set( 'key2', $value2, 10 );
+
+ $curTTLs = array();
+ $result = $cache->getMulti( array( 'key1', 'key2', 'key3' ), $curTTLs, array(
+ 'key1' => $check1,
+ $checkAll,
+ 'key2' => $check2,
+ 'key3' => $check3,
+ ) );
+ $this->assertEquals(
+ array( 'key1' => $value1, 'key2' => $value2 ),
+ $result,
+ 'Initial values'
+ );
+ $this->assertEquals(
+ array( 'key1' => 0, 'key2' => 0 ),
+ $curTTLs,
+ 'Initial ttls'
+ );
+
+ $cache->touchCheckKey( $check1 );
+ usleep( 100 );
+
+ $curTTLs = array();
+ $result = $cache->getMulti( array( 'key1', 'key2', 'key3' ), $curTTLs, array(
+ 'key1' => $check1,
+ $checkAll,
+ 'key2' => $check2,
+ 'key3' => $check3,
+ ) );
+ $this->assertEquals(
+ array( 'key1' => $value1, 'key2' => $value2 ),
+ $result,
+ 'key1 expired by check1, but value still provided'
+ );
+ $this->assertLessThan( 0, $curTTLs['key1'], 'key1 TTL expired' );
+ $this->assertEquals( 0, $curTTLs['key2'], 'key2 still valid' );
+
+ $cache->touchCheckKey( $checkAll );
+ usleep( 100 );
+
+ $curTTLs = array();
+ $result = $cache->getMulti( array( 'key1', 'key2', 'key3' ), $curTTLs, array(
+ 'key1' => $check1,
+ $checkAll,
+ 'key2' => $check2,
+ 'key3' => $check3,
+ ) );
+ $this->assertEquals(
+ array( 'key1' => $value1, 'key2' => $value2 ),
+ $result,
+ 'All keys expired by checkAll, but value still provided'
+ );
+ $this->assertLessThan( 0, $curTTLs['key1'], 'key1 expired by checkAll' );
+ $this->assertLessThan( 0, $curTTLs['key2'], 'key2 expired by checkAll' );
+ }
+
/**
* @covers WANObjectCache::delete()
*/
$this->assertEquals( $t5, $t6, 'Check key time did not change' );
}
+ /**
+ * @covers WANObjectCache::getMulti()
+ */
+ public function testGetWithSeveralCheckKeys() {
+ $key = wfRandomString();
+ $tKey1 = wfRandomString();
+ $tKey2 = wfRandomString();
+ $value = 'meow';
+
+ // Two check keys are newer (given hold-off) than $key, another is older
+ $this->internalCache->set(
+ WANObjectCache::TIME_KEY_PREFIX . $tKey2,
+ WANObjectCache::PURGE_VAL_PREFIX . ( microtime( true ) - 3 )
+ );
+ $this->internalCache->set(
+ WANObjectCache::TIME_KEY_PREFIX . $tKey2,
+ WANObjectCache::PURGE_VAL_PREFIX . ( microtime( true ) - 5 )
+ );
+ $this->internalCache->set(
+ WANObjectCache::TIME_KEY_PREFIX . $tKey1,
+ WANObjectCache::PURGE_VAL_PREFIX . ( microtime( true ) - 30 )
+ );
+ $this->cache->set( $key, $value, 30 );
+
+ $curTTL = null;
+ $v = $this->cache->get( $key, $curTTL, array( $tKey1, $tKey2 ) );
+ $this->assertEquals( $value, $v, "Value matches" );
+ $this->assertLessThan( -5, $curTTL, "Correct CTL" );
+ $this->assertGreaterThan( -5.1, $curTTL, "Correct CTL" );
+ }
+
+ /**
+ * @covers WANObjectCache::set()
+ */
public function testSetWithLag() {
$value = 1;
$this->assertEquals( false, $this->cache->get( $key ), "Lagged value not written." );
}
+ /**
+ * @covers WANObjectCache::set()
+ */
public function testWritePending() {
$value = 1;