Debian Codegraph @

tests/phpunit/includes/Storage/SqlBlobStoreTest.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Tests\Storage;
4
5 use ConcatenatedGzipHistoryBlob;
6 use ExternalStoreAccess;
7 use ExternalStoreFactory;
8 use InvalidArgumentException;
9 use MediaWiki\Storage\BadBlobException;
10 use MediaWiki\Storage\BlobAccessException;
11 use MediaWiki\Storage\SqlBlobStore;
12 use MediaWikiIntegrationTestCase;
13 use StatusValue;
14 use Wikimedia\ObjectCache\HashBagOStuff;
15 use Wikimedia\ObjectCache\WANObjectCache;
16 use Wikimedia\Rdbms\LoadBalancer;
17
18 /**
19 * @group Database
20 * @covers \MediaWiki\Storage\SqlBlobStore
21 */
22 class SqlBlobStoreTest extends MediaWikiIntegrationTestCase {
23
24 /**
25 * @param WANObjectCache|null $cache
26 * @param ExternalStoreAccess|null $extStore
27 * @return SqlBlobStore
28 */
29 public function getBlobStore(
30 ?WANObjectCache $cache = null,
31 ?ExternalStoreAccess $extStore = null
32 ) {
33 $services = $this->getServiceContainer();
34
35 $store = new SqlBlobStore(
36 $services->getDBLoadBalancer(),
37 $extStore ?: $services->getExternalStoreAccess(),
38 $cache ?: $services->getMainWANObjectCache()
39 );
40
41 return $store;
42 }
43
44 public function testGetSetCompressRevisions() {
45 $store = $this->getBlobStore();
46 $this->assertFalse( $store->getCompressBlobs() );
47 $store->setCompressBlobs( true );
48 $this->assertTrue( $store->getCompressBlobs() );
49 }
50
51 public function testGetSetLegacyEncoding() {
52 $store = $this->getBlobStore();
53 $this->assertFalse( $store->getLegacyEncoding() );
54 $store->setLegacyEncoding( 'foo' );
55 $this->assertSame( 'foo', $store->getLegacyEncoding() );
56 }
57
58 public function testGetSetCacheExpiry() {
59 $store = $this->getBlobStore();
60 $this->assertSame( 604800, $store->getCacheExpiry() );
61 $store->setCacheExpiry( 12 );
62 $this->assertSame( 12, $store->getCacheExpiry() );
63 }
64
65 public function testGetSetUseExternalStore() {
66 $store = $this->getBlobStore();
67 $this->assertFalse( $store->getUseExternalStore() );
68 $store->setUseExternalStore( true );
69 $this->assertTrue( $store->getUseExternalStore() );
70 }
71
72 private function makeObjectBlob( $text ) {
73 $obj = new ConcatenatedGzipHistoryBlob();
74 $obj->setText( $text );
75 return serialize( $obj );
76 }
77
78 public function provideDecompress() {
79 yield '(no legacy encoding), empty in empty out' => [ false, '', [], '' ];
80 yield '(no legacy encoding), string in string out' => [ false, 'A', [], 'A' ];
81 yield '(no legacy encoding), error flag -> false' => [ false, 'X', [ 'error' ], false ];
82 yield '(no legacy encoding), string in with gzip flag returns string' => [
83 // gzip string below generated with gzdeflate( 'AAAABBAAA' )
84 false, "sttttr\002\022\000", [ 'gzip' ], 'AAAABBAAA',
85 ];
86 yield '(no legacy encoding), string in with object flag returns false' => [
87 // gzip string below generated with serialize( 'JOJO' )
88 false, "s:4:\"JOJO\";", [ 'object' ], false,
89 ];
90
91 yield '(no legacy encoding), serialized object in with object flag returns string' => [
92 false,
93 $this->makeObjectBlob( 'HHJJDDFF' ),
94 [ 'object' ],
95 'HHJJDDFF',
96 ];
97 yield '(no legacy encoding), serialized object in with object & gzip flag returns string' => [
98 false,
99 gzdeflate( $this->makeObjectBlob( '8219JJJ840' ) ),
100 [ 'object', 'gzip' ],
101 '8219JJJ840',
102 ];
103 yield '(ISO-8859-1 encoding), string in string out' => [
104 'ISO-8859-1',
105 iconv( 'utf-8', 'ISO-8859-1', "1®Àþ1" ),
106 [],
107 '1®Àþ1',
108 ];
109 yield '(ISO-8859-1 encoding), serialized object in with gzip flags returns string' => [
110 'ISO-8859-1',
111 gzdeflate( iconv( 'utf-8', 'ISO-8859-1', "4®Àþ4" ) ),
112 [ 'gzip' ],
113 '4®Àþ4',
114 ];
115 yield '(ISO-8859-1 encoding), serialized object in with object flags returns string' => [
116 'ISO-8859-1',
117 $this->makeObjectBlob( iconv( 'utf-8', 'ISO-8859-1', "3®Àþ3" ) ),
118 [ 'object' ],
119 '3®Àþ3',
120 ];
121 yield '(ISO-8859-1 encoding), serialized object in with object & gzip flags returns string' => [
122 'ISO-8859-1',
123 gzdeflate( $this->makeObjectBlob( iconv( 'utf-8', 'ISO-8859-1', "2®Àþ2" ) ) ),
124 [ 'gzip', 'object' ],
125 '2®Àþ2',
126 ];
127 yield 'T184749 (windows-1252 encoding), string in string out' => [
128 'windows-1252',
129 iconv( 'utf-8', 'windows-1252', "sammansättningar" ),
130 [],
131 'sammansättningar',
132 ];
133 yield 'T184749 (windows-1252 encoding), string in string out with gzip' => [
134 'windows-1252',
135 gzdeflate( iconv( 'utf-8', 'windows-1252', "sammansättningar" ) ),
136 [ 'gzip' ],
137 'sammansättningar',
138 ];
139 }
140
141 /**
142 * @dataProvider provideDecompress
143 * @param string|bool $legacyEncoding
144 * @param mixed $data
145 * @param array $flags
146 * @param mixed $expected
147 */
148 public function testDecompressData( $legacyEncoding, $data, $flags, $expected ) {
149 $store = $this->getBlobStore();
150
151 if ( $legacyEncoding ) {
152 $store->setLegacyEncoding( $legacyEncoding );
153 }
154
155 $this->assertSame(
156 $expected,
157 $store->decompressData( $data, $flags )
158 );
159 }
160
161 public function testCompressRevisionTextUtf8() {
162 $store = $this->getBlobStore();
163 $row = (object)[ 'old_text' => "Wiki est l'\xc3\xa9cole superieur !" ];
164 $row->old_flags = $store->compressData( $row->old_text );
165 $this->assertStringContainsString( 'utf-8', $row->old_flags,
166 "Flags should contain 'utf-8'" );
167 $this->assertStringNotContainsString( 'gzip', $row->old_flags,
168 "Flags should not contain 'gzip'" );
169 $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
170 $row->old_text, "Direct check" );
171 }
172
173 /**
174 * @requires extension zlib
175 */
176 public function testCompressRevisionTextUtf8Gzip() {
177 $store = $this->getBlobStore();
178 $store->setCompressBlobs( true );
179
180 $row = (object)[ 'old_text' => "Wiki est l'\xc3\xa9cole superieur !" ];
181 $row->old_flags = $store->compressData( $row->old_text );
182 $this->assertStringContainsString( 'utf-8', $row->old_flags,
183 "Flags should contain 'utf-8'" );
184 $this->assertStringContainsString( 'gzip', $row->old_flags,
185 "Flags should contain 'gzip'" );
186 $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
187 gzinflate( $row->old_text ), "Direct check" );
188 }
189
190 public static function provideBlobs() {
191 yield [ '' ];
192 yield [ 'someText' ];
193 yield [ "söme\ntäxt" ];
194 }
195
196 public function testSimpleStoreGetBlobKnownBad() {
197 $store = $this->getBlobStore();
198 $this->expectException( BadBlobException::class );
199 $store->getBlob( 'bad:lost?bug=T12345' );
200 }
201
202 /**
203 * @param string $blob
204 * @dataProvider provideBlobs
205 */
206 public function testSimpleStoreGetBlobSimpleRoundtrip( $blob ) {
207 $store = $this->getBlobStore();
208 $address = $store->storeBlob( $blob );
209 $this->assertSame( $blob, $store->getBlob( $address ) );
210 }
211
212 public function testSimpleStorageGetBlobBatchSimpleEmpty() {
213 $store = $this->getBlobStore();
214 $this->assertArrayEquals(
215 [],
216 $store->getBlobBatch( [] )->getValue()
217 );
218 }
219
220 /**
221 * @param string $blob
222 * @dataProvider provideBlobs
223 */
224 public function testSimpleStorageGetBlobBatchSimpleRoundtrip( $blob ) {
225 $store = $this->getBlobStore();
226 $addresses = [
227 $store->storeBlob( $blob ),
228 $store->storeBlob( $blob . '1' )
229 ];
230 $this->assertArrayEquals(
231 array_combine( $addresses, [ $blob, $blob . '1' ] ),
232 $store->getBlobBatch( $addresses )->getValue()
233 );
234 }
235
236 public function testCachingConsistency() {
237 $cache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
238 $store = $this->getBlobStore( $cache );
239
240 $addrA = $store->storeBlob( 'A' );
241 $addrB = $store->storeBlob( 'B' );
242 $addrC = $store->storeBlob( 'C' );
243 $addrD = $store->storeBlob( 'D' );
244 $addrX = 'tt:0';
245
246 $dataZ = "söme\ntäxt!";
247 $addrZ = $store->storeBlob( $dataZ );
248
249 $this->assertArrayEquals(
250 [ $addrA => 'A', $addrC => 'C', $addrX => null ],
251 $store->getBlobBatch( [ $addrA, $addrC, $addrX ] )->getValue(),
252 false, true
253 );
254
255 $this->assertEquals( 'A', $store->getBlob( $addrA ) );
256 $this->assertEquals( 'B', $store->getBlob( $addrB ) );
257 $this->assertEquals( 'C', $store->getBlob( $addrC ) );
258
259 $this->assertArrayEquals(
260 [ $addrB => 'B', $addrC => 'C', $addrD => 'D' ],
261 $store->getBlobBatch( [ $addrB, $addrC, $addrD ] )->getValue(),
262 false, true
263 );
264
265 $this->assertEquals( $dataZ, $store->getBlob( $addrZ ) );
266
267 $this->assertArrayEquals(
268 [ $addrA => 'A', $addrZ => $dataZ ],
269 $store->getBlobBatch( [ $addrA, $addrZ ] )->getValue(),
270 false, true
271 );
272 }
273
274 public function testSimpleStorageNonExistentBlob() {
275 $this->expectException( BlobAccessException::class );
276 $store = $this->getBlobStore();
277 $store->getBlob( 'tt:this_will_not_exist' );
278 }
279
280 public function testSimpleStorageNonExistentBlobBatch() {
281 $store = $this->getBlobStore();
282 $result = $store->getBlobBatch( [
283 'tt:this_will_not_exist',
284 'tt:0',
285 'tt:-1',
286 'tt:10000',
287 'bla:1001'
288 ] );
289 $resultBlobs = $result->getValue();
290 $expected = [
291 'tt:this_will_not_exist' => null,
292 'tt:0' => null,
293 'tt:-1' => null,
294 'tt:10000' => null,
295 'bla:1001' => null
296 ];
297
298 ksort( $expected );
299 ksort( $resultBlobs );
300 $this->assertSame( $expected, $resultBlobs );
301
302 $this->assertStatusMessagesExactly(
303 StatusValue::newGood()
304 ->warning( 'internalerror', 'Bad blob address: tt:this_will_not_exist. Use findBadBlobs.php to remedy.' )
305 ->warning( 'internalerror', 'Bad blob address: tt:0. Use findBadBlobs.php to remedy.' )
306 ->warning( 'internalerror', 'Bad blob address: tt:-1. Use findBadBlobs.php to remedy.' )
307 ->warning( 'internalerror', 'Unknown blob address schema: bla. Use findBadBlobs.php to remedy.' )
308 ->warning( 'internalerror', 'Unable to fetch blob at tt:10000. Use findBadBlobs.php to remedy.' ),
309 $result
310 );
311 }
312
313 public function testSimpleStoragePartialNonExistentBlobBatch() {
314 $store = $this->getBlobStore();
315 $address = $store->storeBlob( 'test_data' );
316 $result = $store->getBlobBatch( [ $address, 'tt:this_will_not_exist_too' ] );
317 $resultBlobs = $result->getValue();
318 $expected = [
319 $address => 'test_data',
320 'tt:this_will_not_exist_too' => null
321 ];
322
323 ksort( $expected );
324 ksort( $resultBlobs );
325 $this->assertSame( $expected, $resultBlobs );
326 $this->assertStatusMessagesExactly(
327 StatusValue::newGood()
328 ->warning( 'internalerror', 'Bad blob address: tt:this_will_not_exist_too. Use findBadBlobs.php to remedy.' ),
329 $result
330 );
331 }
332
333 /**
334 * @dataProvider provideBlobs
335 */
336 public function testSimpleStoreGetBlobSimpleRoundtripWindowsLegacyEncoding( $blob ) {
337 $store = $this->getBlobStore();
338 $store->setLegacyEncoding( 'windows-1252' );
339 $address = $store->storeBlob( $blob );
340 $this->assertSame( $blob, $store->getBlob( $address ) );
341 }
342
343 /**
344 * @dataProvider provideBlobs
345 */
346 public function testSimpleStoreGetBlobSimpleRoundtripWindowsLegacyEncodingGzip( $blob ) {
347 // FIXME: fails under postgres - T298692
348 $this->markTestSkippedIfDbType( 'postgres' );
349 $store = $this->getBlobStore();
350 $store->setLegacyEncoding( 'windows-1252' );
351 $store->setCompressBlobs( true );
352 $address = $store->storeBlob( $blob );
353 $this->assertSame( $blob, $store->getBlob( $address ) );
354 }
355
356 public static function provideGetTextIdFromAddress() {
357 yield [ 'tt:17', 17 ];
358 yield [ 'xy:17', null ];
359 yield [ 'xy:xyzzy', null ];
360 }
361
362 /**
363 * @dataProvider provideGetTextIdFromAddress
364 */
365 public function testGetTextIdFromAddress( $address, $textId ) {
366 $store = $this->getBlobStore();
367 $this->assertSame( $textId, $store->getTextIdFromAddress( $address ) );
368 }
369
370 public static function provideGetTextIdFromAddressInvalidArgumentException() {
371 yield [ 'tt:xy' ];
372 yield [ 'tt:0' ];
373 yield [ 'tt:' ];
374 yield [ 'xy' ];
375 yield [ '' ];
376 }
377
378 /**
379 * @dataProvider provideGetTextIdFromAddressInvalidArgumentException
380 */
381 public function testGetTextIdFromAddressInvalidArgumentException( $address ) {
382 $this->expectException( InvalidArgumentException::class );
383 $store = $this->getBlobStore();
384 $store->getTextIdFromAddress( $address );
385 }
386
387 public function testMakeAddressFromTextId() {
388 $this->assertSame( 'tt:17', SqlBlobStore::makeAddressFromTextId( 17 ) );
389 }
390
391 public static function providerSplitBlobAddress() {
392 yield [ 'tt:123', 'tt', '123', [] ];
393 yield [ 'bad:foo?x=y', 'bad', 'foo', [ 'x' => 'y' ] ];
394 yield [ 'http://test.com/foo/bar?a=b', 'http', 'test.com/foo/bar', [ 'a' => 'b' ] ];
395 }
396
397 /**
398 * @dataProvider providerSplitBlobAddress
399 */
400 public function testSplitBlobAddress( $address, $schema, $id, $parameters ) {
401 $this->assertSame( 'tt:17', SqlBlobStore::makeAddressFromTextId( 17 ) );
402 }
403
404 public static function provideExpandBlob() {
405 yield 'Generic test' => [
406 'This is a goat of revision text.',
407 'old_flags' => '',
408 'old_text' => 'This is a goat of revision text.',
409 ];
410 }
411
412 /**
413 * @dataProvider provideExpandBlob
414 */
415 public function testExpandBlob( $expected, $flags, $raw ) {
416 $blobStore = $this->getBlobStore();
417 $this->assertEquals(
418 $expected,
419 $blobStore->expandBlob( $raw, explode( ',', $flags ) )
420 );
421 }
422
423 public static function provideExpandBlobWithZlibExtension() {
424 yield 'Generic gzip test' => [
425 'This is a small goat of revision text.',
426 'old_flags' => 'gzip',
427 'old_text' => gzdeflate( 'This is a small goat of revision text.' ),
428 ];
429 }
430
431 /**
432 * @dataProvider provideExpandBlobWithZlibExtension
433 * @requires extension zlib
434 */
435 public function testGetRevisionWithZlibExtension( $expected, $flags, $raw ) {
436 $blobStore = $this->getBlobStore();
437 $this->assertEquals(
438 $expected,
439 $blobStore->expandBlob( $raw, explode( ',', $flags ) )
440 );
441 }
442
443 public static function provideExpandBlobWithZlibExtension_badData() {
444 yield 'Generic gzip test' => [
445 'old_flags' => 'gzip',
446 'old_text' => 'DEAD BEEF',
447 ];
448 }
449
450 /**
451 * @dataProvider provideExpandBlobWithZlibExtension_badData
452 * @requires extension zlib
453 */
454 public function testGetRevisionWithZlibExtension_badData( $flags, $raw ) {
455 $blobStore = $this->getBlobStore();
456
457 $this->assertFalse(
458 @$blobStore->expandBlob( $raw, explode( ',', $flags ) )
459 );
460 }
461
462 public static function provideExpandBlobWithLegacyEncoding() {
463 yield 'Utf8Native' => [
464 "Wiki est l'\xc3\xa9cole superieur !",
465 'iso-8859-1',
466 'old_flags' => 'utf-8',
467 'old_text' => "Wiki est l'\xc3\xa9cole superieur !",
468 ];
469 yield 'Utf8Legacy' => [
470 "Wiki est l'\xc3\xa9cole superieur !",
471 'iso-8859-1',
472 'old_flags' => '',
473 'old_text' => "Wiki est l'\xe9cole superieur !",
474 ];
475 }
476
477 /**
478 * @dataProvider provideExpandBlobWithLegacyEncoding
479 */
480 public function testGetRevisionWithLegacyEncoding( $expected, $encoding, $flags, $raw ) {
481 $blobStore = $this->getBlobStore();
482 $blobStore->setLegacyEncoding( $encoding );
483
484 $this->assertEquals(
485 $expected,
486 $blobStore->expandBlob( $raw, explode( ',', $flags ) )
487 );
488 }
489
490 public static function provideExpandBlobWithGzipAndLegacyEncoding() {
491 /**
492 * WARNING!
493 * Do not set the external flag!
494 * Otherwise, getRevisionText will hit the live database (if ExternalStore is enabled)!
495 */
496 yield 'Utf8NativeGzip' => [
497 "Wiki est l'\xc3\xa9cole superieur !",
498 'iso-8859-1',
499 'old_flags' => 'gzip,utf-8',
500 'old_text' => gzdeflate( "Wiki est l'\xc3\xa9cole superieur !" ),
501 ];
502 yield 'Utf8LegacyGzip' => [
503 "Wiki est l'\xc3\xa9cole superieur !",
504 'iso-8859-1',
505 'old_flags' => 'gzip',
506 'old_text' => gzdeflate( "Wiki est l'\xe9cole superieur !" ),
507 ];
508 }
509
510 /**
511 * @dataProvider provideExpandBlobWithGzipAndLegacyEncoding
512 * @requires extension zlib
513 */
514 public function testGetRevisionWithGzipAndLegacyEncoding( $expected, $encoding, $flags, $raw ) {
515 $blobStore = $this->getBlobStore();
516 $blobStore->setLegacyEncoding( $encoding );
517
518 $this->assertEquals(
519 $expected,
520 $blobStore->expandBlob( $raw, explode( ',', $flags ) )
521 );
522 }
523
524 public static function provideTestGetRevisionText_returnsDecompressedTextFieldWhenNotExternal() {
525 yield 'Just text' => [
526 'old_flags' => '',
527 'old_text' => 'SomeText',
528 'SomeText'
529 ];
530 // gzip string below generated with gzdeflate( 'AAAABBAAA' )
531 yield 'gzip text' => [
532 'old_flags' => 'gzip',
533 'old_text' => "sttttr\002\022\000",
534 'AAAABBAAA'
535 ];
536 }
537
538 /**
539 * @dataProvider provideTestGetRevisionText_returnsDecompressedTextFieldWhenNotExternal
540 */
541 public function testGetRevisionText_returnsDecompressedTextFieldWhenNotExternal(
542 $flags,
543 $raw,
544 $expected
545 ) {
546 $blobStore = $this->getBlobStore();
547 $this->assertSame( $expected, $blobStore->expandBlob( $raw, $flags ) );
548 }
549
550 public static function provideTestGetRevisionText_external_returnsFalseWhenNotEnoughUrlParts() {
551 yield 'Just some text' => [ 'someNonUrlText' ];
552 yield 'No second URL part' => [ 'someProtocol://' ];
553 }
554
555 /**
556 * @dataProvider provideTestGetRevisionText_external_returnsFalseWhenNotEnoughUrlParts
557 */
558 public function testGetRevisionText_external_returnsFalseWhenNotEnoughUrlParts(
559 $text
560 ) {
561 $blobStore = $this->getBlobStore();
562 $this->assertFalse(
563 $blobStore->expandBlob(
564 $text,
565 [ 'external' ]
566 )
567 );
568 }
569
570 public function testGetRevisionText_external_noOldId() {
571 $this->setService(
572 'ExternalStoreFactory',
573 new ExternalStoreFactory( [ 'ForTesting' ], [ 'ForTesting://cluster1' ], 'test-id' )
574 );
575 $blobStore = $this->getBlobStore();
576 $this->assertSame(
577 'AAAABBAAA',
578 $blobStore->expandBlob(
579 'ForTesting://cluster1/12345',
580 [ 'external', 'gzip' ]
581 )
582 );
583 }
584
585 private function getWANObjectCache() {
586 return new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
587 }
588
589 public function testGetRevisionText_external_oldId() {
590 $cache = $this->getWANObjectCache();
591 $this->setService( 'MainWANObjectCache', $cache );
592
593 $this->setService(
594 'ExternalStoreFactory',
595 new ExternalStoreFactory( [ 'ForTesting' ], [ 'ForTesting://cluster1' ], 'test-id' )
596 );
597
598 $lb = $this->createMock( LoadBalancer::class );
599 $access = $this->getServiceContainer()->getExternalStoreAccess();
600
601 $blobStore = new SqlBlobStore( $lb, $access, $cache );
602
603 $this->assertSame(
604 'AAAABBAAA',
605 $blobStore->expandBlob(
606 'ForTesting://cluster1/12345',
607 'external,gzip',
608 'tt:7777'
609 )
610 );
611
612 $cacheKey = $cache->makeGlobalKey(
613 'SqlBlobStore-blob',
614 $lb->getLocalDomainID(),
615 'tt:7777'
616 );
617 $this->assertSame( 'AAAABBAAA', $cache->get( $cacheKey ) );
618 }
619
620 public function testGetRevisionText_external_oldId_direct_access() {
621 $cache = $this->getWANObjectCache();
622 $this->setService( 'MainWANObjectCache', $cache );
623
624 $this->setService(
625 'ExternalStoreFactory',
626 new ExternalStoreFactory( [ 'ForTesting' ], [ 'ForTesting://cluster1' ], 'test-id' )
627 );
628
629 $lb = $this->createMock( LoadBalancer::class );
630 $access = $this->getServiceContainer()->getExternalStoreAccess();
631
632 $blobStore = new SqlBlobStore( $lb, $access, $cache );
633
634 $this->assertSame(
635 'AAAABBAAA',
636 $blobStore->getBlob( 'es:ForTesting://cluster1/12345?flags=external,gzip' )
637 );
638
639 $cacheKey = $cache->makeGlobalKey(
640 'SqlBlobStore-blob',
641 $lb->getLocalDomainID(),
642 // See ExternalStoreForTesting for the path
643 'es:ForTesting://cluster1/12345?flags=external,gzip'
644 );
645 $this->assertSame( 'AAAABBAAA', $cache->get( $cacheKey ) );
646 }
647
648 public static function provideTestGetRevisionText_external_oldId_direct_store() {
649 yield 'no compression' => [ false ];
650 yield 'compression' => [ true ];
651 }
652
653 /**
654 * @dataProvider provideTestGetRevisionText_external_oldId_direct_store
655 */
656 public function testGetRevisionText_external_oldId_direct_store( bool $compression ) {
657 $cache = $this->getWANObjectCache();
658 $this->setService( 'MainWANObjectCache', $cache );
659
660 $this->setService(
661 'ExternalStoreFactory',
662 new ExternalStoreFactory( [ 'ForTesting' ], [ 'ForTesting://cluster1' ], 'test-id' )
663 );
664
665 $lb = $this->createMock( LoadBalancer::class );
666 $access = $this->getServiceContainer()->getExternalStoreAccess();
667
668 $blobStore = new SqlBlobStore( $lb, $access, $cache );
669 $blobStore->setUseExternalStore( true );
670 $blobStore->setCompressBlobs( $compression );
671 $id = $blobStore->storeBlob( 'A very unique text' );
672 $this->assertStringStartsWith( 'es:ForTesting://cluster1/', $id );
673
674 $this->assertSame(
675 'A very unique text',
676 $blobStore->getBlob( $id )
677 );
678
679 $cacheKey = $cache->makeGlobalKey(
680 'SqlBlobStore-blob',
681 $lb->getLocalDomainID(),
682 $id
683 );
684 $this->assertSame( 'A very unique text', $cache->get( $cacheKey ) );
685 }
686 }