+ public function testAsyncWrites() {
+ $be = TestingAccessWrapper::newFromObject(
+ new FileBackendMultiWrite( array(
+ 'name' => 'localtesting',
+ 'wikiId' => wfWikiId() . mt_rand(),
+ 'backends' => array(
+ array( // backend 0
+ 'name' => 'multitesting0',
+ 'class' => 'MemoryFileBackend',
+ 'isMultiMaster' => false
+ ),
+ array( // backend 1
+ 'name' => 'multitesting1',
+ 'class' => 'MemoryFileBackend',
+ 'isMultiMaster' => true
+ )
+ ),
+ 'replication' => 'async'
+ ) )
+ );
+
+ DeferredUpdates::forceDeferral( true );
+
+ $p = 'container/test-cont/file.txt';
+ $be->quickCreate( array(
+ 'dst' => "mwstore://localtesting/$p", 'content' => 'cattitude' ) );
+
+ $this->assertEquals(
+ false,
+ $be->backends[0]->getFileContents( array( 'src' => "mwstore://multitesting0/$p" ) ),
+ "File not yet written to backend 0"
+ );
+ $this->assertEquals(
+ 'cattitude',
+ $be->backends[1]->getFileContents( array( 'src' => "mwstore://multitesting1/$p" ) ),
+ "File already written to backend 1"
+ );
+
+ DeferredUpdates::doUpdates();
+ DeferredUpdates::forceDeferral( false );
+
+ $this->assertEquals(
+ 'cattitude',
+ $be->backends[0]->getFileContents( array( 'src' => "mwstore://multitesting0/$p" ) ),
+ "File now written to backend 0"
+ );
+ }
+
+ public function testSanitizeOpHeaders() {
+ $be = TestingAccessWrapper::newFromObject( new MemoryFileBackend( array(
+ 'name' => 'localtesting',
+ 'wikiId' => wfWikiID()
+ ) ) );
+
+ $name = wfRandomString( 300 );
+
+ $input = array(
+ 'headers' => array(
+ 'content-Disposition' => FileBackend::makeContentDisposition( 'inline', $name ),
+ 'Content-dUration' => 25.6,
+ 'X-LONG-VALUE' => str_pad( '0', 300 ),
+ 'CONTENT-LENGTH' => 855055,
+ )
+ );
+ $expected = array(
+ 'headers' => array(
+ 'content-disposition' => FileBackend::makeContentDisposition( 'inline', $name ),
+ 'content-duration' => 25.6,
+ 'content-length' => 855055
+ )
+ );
+
+ MediaWiki\suppressWarnings();
+ $actual = $be->sanitizeOpHeaders( $input );
+ MediaWiki\restoreWarnings();
+
+ $this->assertEquals( $expected, $actual, "Header sanitized properly" );
+ }
+