+ /**
+ * @covers BagOStuff::get
+ * @covers BagOStuff::getMulti
+ * @covers BagOStuff::merge
+ * @covers BagOStuff::delete
+ */
+ public function testSetSegmentable() {
+ $key = $this->cache->makeKey( self::TEST_KEY );
+ $tiny = 418;
+ $small = wfRandomString( 32 );
+ // 64 * 8 * 32768 = 16777216 bytes
+ $big = str_repeat( wfRandomString( 32 ) . '-' . wfRandomString( 32 ), 32768 );
+
+ $callback = function ( $cache, $key, $oldValue ) {
+ return $oldValue . '!';
+ };
+
+ foreach ( [ $tiny, $small, $big ] as $value ) {
+ $this->cache->set( $key, $value, 10, BagOStuff::WRITE_ALLOW_SEGMENTS );
+ $this->assertEquals( $value, $this->cache->get( $key ) );
+ $this->assertEquals( $value, $this->cache->getMulti( [ $key ] )[$key] );
+
+ $this->assertTrue( $this->cache->merge( $key, $callback, 5 ) );
+ $this->assertEquals( "$value!", $this->cache->get( $key ) );
+ $this->assertEquals( "$value!", $this->cache->getMulti( [ $key ] )[$key] );
+
+ $this->assertTrue( $this->cache->deleteMulti( [ $key ] ) );
+ $this->assertFalse( $this->cache->get( $key ) );
+ $this->assertEquals( [], $this->cache->getMulti( [ $key ] ) );
+
+ $this->cache->set( $key, "@$value", 10, BagOStuff::WRITE_ALLOW_SEGMENTS );
+ $this->assertEquals( "@$value", $this->cache->get( $key ) );
+ $this->assertTrue( $this->cache->delete( $key, BagOStuff::WRITE_PRUNE_SEGMENTS ) );
+ $this->assertFalse( $this->cache->get( $key ) );
+ $this->assertEquals( [], $this->cache->getMulti( [ $key ] ) );
+ }
+
+ $this->cache->set( $key, 666, 10, BagOStuff::WRITE_ALLOW_SEGMENTS );
+
+ $this->assertEquals( 667, $this->cache->incr( $key ) );
+ $this->assertEquals( 667, $this->cache->get( $key ) );
+
+ $this->assertEquals( 664, $this->cache->decr( $key, 3 ) );
+ $this->assertEquals( 664, $this->cache->get( $key ) );
+
+ $this->assertTrue( $this->cache->delete( $key ) );
+ $this->assertFalse( $this->cache->get( $key ) );
+ }
+