storage/test/unit/test_cache_size.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 // This file tests that dbs of various page sizes are using the right cache
     5 // size (bug 703113).
     7 /**
     8  * In order to change the cache size, we must open a DB, change the page
     9  * size, create a table, close the DB, then re-open the DB.  We then check
    10  * the cache size after reopening.
    11  *
    12  * @param dbOpener
    13  *        function that opens the DB specified in file
    14  * @param file
    15  *        file holding the database
    16  * @param pageSize
    17  *        the DB's page size
    18  * @param expectedCacheSize
    19  *        the expected cache size for the given page size
    20  */
    21 function check_size(dbOpener, file, pageSize, expectedCacheSize)
    22 {
    23   // Open the DB, immediately change its page size.
    24   let db = dbOpener(file);
    25   db.executeSimpleSQL("PRAGMA page_size = " + pageSize);
    27   // Check the page size change worked.
    28   let stmt = db.createStatement("PRAGMA page_size");
    29   do_check_true(stmt.executeStep());
    30   do_check_eq(stmt.row.page_size, pageSize);
    31   stmt.finalize();
    33   // Create a simple table.
    34   db.executeSimpleSQL("CREATE TABLE test ( id INTEGER PRIMARY KEY )");
    36   // Close and re-open the DB.
    37   db.close();
    38   db = dbOpener(file);
    40   // Check cache size is as expected.
    41   let stmt = db.createStatement("PRAGMA cache_size");
    42   do_check_true(stmt.executeStep());
    43   do_check_eq(stmt.row.cache_size, expectedCacheSize);
    44   stmt.finalize();
    45 }
    47 function new_file(name)
    48 {
    49   let file = dirSvc.get("ProfD", Ci.nsIFile);
    50   file.append(name + ".sqlite");
    51   do_check_false(file.exists());
    52   return file;
    53 }
    55 function run_test()
    56 {
    57   const kExpectedCacheSize = -2048; // 2MiB
    59   let pageSizes = [
    60     1024,
    61     4096,
    62     32768,
    63   ];
    65   for (let i = 0; i < pageSizes.length; i++) {
    66     let pageSize = pageSizes[i];
    67     check_size(getDatabase,
    68                new_file("shared" + pageSize), pageSize, kExpectedCacheSize);
    69     check_size(getService().openUnsharedDatabase,
    70                new_file("unshared" + pageSize), pageSize, kExpectedCacheSize);
    71   }
    72 }

mercurial