protected $maxConsecutiveFailedTextRetrievals = 200;
protected $failureTimeout = 5; // Seconds to sleep after db failure
+ protected $bufferSize = 524288; // In bytes. Maximum size to read from the stub in on go.
+
protected $php = "php";
protected $spawn = false;
$url = $this->processFileOpt( $val, $param );
switch ( $opt ) {
+ case 'buffersize':
+ // Lower bound for xml reading buffer size is 4 KB
+ $this->bufferSize = max( intval( $val ), 4 * 1024 );
+ break;
case 'prefetch':
require_once "$IP/maintenance/backupPrefetch.inc";
$this->prefetch = new BaseDump( $url );
xml_set_character_data_handler( $parser, array( &$this, 'characterData' ) );
$offset = 0; // for context extraction on error reporting
- $bufferSize = 512 * 1024;
do {
if ( $this->checkIfTimeExceeded() ) {
$this->setTimeExceeded();
}
- $chunk = fread( $input, $bufferSize );
+ $chunk = fread( $input, $this->bufferSize );
if ( !xml_parse( $parser, $chunk, feof( $input ) ) ) {
wfDebug( "TextDumpPass::readDump encountered XML parsing error\n" );
require_once __DIR__ . "/../../../maintenance/backupTextPass.inc";
/**
- * Tests for page dumps of BackupDumper
+ * Tests for TextPassDumper that rely on the database
*
* @group Database
* @group Dump
* @covers TextPassDumper
*/
-class TextPassDumperTest extends DumpTestCase {
+class TextPassDumperDatabaseTest extends DumpTestCase {
// We'll add several pages, revision and texts. The following variables hold the
// corresponding ids.
}
}
+
+/**
+ * Tests for TextPassDumper that do not rely on the database
+ *
+ * (As the Database group is only detected at class level (not method level), we
+ * cannot bring this test case's tests into the above main test case.)
+ *
+ * @group Dump
+ * @covers TextPassDumper
+ */
+class TextPassDumperDatabaselessTest extends MediaWikiLangTestCase {
+ /**
+ * Ensures that setting the buffer size is effective.
+ *
+ * @dataProvider bufferSizeProvider
+ */
+ function testBufferSizeSetting( $expected, $size, $msg ) {
+ $dumper = new TextPassDumperAccessor( array( "--buffersize=" . $size ) );
+ $this->assertEquals( $expected, $dumper->getBufferSize(), $msg);
+ }
+
+ /**
+ * Ensures that setting the buffer size is effective.
+ *
+ * @dataProvider bufferSizeProvider
+ */
+ function bufferSizeProvider() {
+ // expected, bufferSize to initialize with, message
+ return array(
+ array( 512 * 1024, 512 * 1024, "Setting 512KB is not effective" ),
+ array( 8192, 8192, "Setting 8KB is not effective" ),
+ array( 4096, 2048, "Could set buffer size below lower bound" )
+ );
+ }
+}
+
+/**
+ * Accessor for internal state of TextPassDumper
+ *
+ * Do not warrentless add getters here.
+ */
+class TextPassDumperAccessor extends TextPassDumper {
+ /**
+ * Gets the bufferSize.
+ *
+ * If bufferSize setting does not work correctly, testCheckpoint... tests
+ * fail and point in the wrong direction. To aid in troubleshooting when
+ * testCheckpoint... tests break at some point in the future, we test the
+ * bufferSize setting, hence need this accessor.
+ *
+ * (Yes, bufferSize is internal state of the TextPassDumper, but aiding
+ * debugging of testCheckpoint... in the future seems to be worth testing
+ * against it nonetheless.)
+ */
+ public function getBufferSize() {
+ return $this->bufferSize;
+ }
+}