Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e458428e authored by Lee Shombert's avatar Lee Shombert
Browse files

Correct a db perf test

The two multi-threaded read/write performance tests violate the
recommended Android database best practice: the writer loop creates a
new SQLiteDatabase on the test database file.  This leads to two
errors: the writer loop creates its database with an incompatible
journal mode in different from the actual database, and the test exits
without properly closing the database.

This change simply has the writer loop use the existing database for
its test.  The benchmark values for the multi-threaded read/write
tests change dramatically for the TRUNCATE journal mode and slightly
for the WAL journal mode; these metric changes are WAI.

Test: atest
 * SQLiteDatabasePerfTest

Bug: 318742652
Change-Id: Icb2534c6fbaf8daa3eb38e8b1b7f71331d571e9d
parent 046a0f25
Loading
Loading
Loading
Loading
+12 −15
Original line number Diff line number Diff line
@@ -433,6 +433,17 @@ public class SQLiteDatabasePerfTest {
        performMultithreadedReadWriteTest();
    }

    /**
     * This test measures a multi-threaded read-write environment where there are 2 readers and
     * 1 writer in the database using WAL journal mode and NORMAL syncMode.
     */
    @Test
    public void testMultithreadedReadWriteWithWalNormal() {
        recreateTestDatabase(SQLiteDatabase.JOURNAL_MODE_WAL, SQLiteDatabase.SYNC_MODE_NORMAL);
        insertT1TestDataSet();
        performMultithreadedReadWriteTest();
    }

    private void doReadLoop(int totalIterations) {
        Random rnd = new Random(0);
        int currentIteration = 0;
@@ -472,7 +483,6 @@ public class SQLiteDatabasePerfTest {
    }

    private void doUpdateLoop(int totalIterations) {
        SQLiteDatabase db = mContext.openOrCreateDatabase(DB_NAME, Context.MODE_PRIVATE, null);
        Random rnd = new Random(0);
        int i = 0;
        ContentValues cv = new ContentValues();
@@ -485,24 +495,12 @@ public class SQLiteDatabasePerfTest {
            cv.put("COL_B", "UpdatedValue");
            cv.put("COL_C", i);
            argArray[0] = String.valueOf(id);
            db.update("T1", cv, "_ID=?", argArray);
            mDatabase.update("T1", cv, "_ID=?", argArray);
            i++;
            android.os.Trace.endSection();
        }
    }

    /**
     * This test measures a multi-threaded read-write environment where there are 2 readers and
     * 1 writer in the database using WAL journal mode and NORMAL syncMode.
     */
    @Test
    public void testMultithreadedReadWriteWithWalNormal() {
        recreateTestDatabase(SQLiteDatabase.JOURNAL_MODE_WAL, SQLiteDatabase.SYNC_MODE_NORMAL);
        insertT1TestDataSet();

        performMultithreadedReadWriteTest();
    }

    private void performMultithreadedReadWriteTest() {
        int totalBGIterations = 10000;
        // Writer - Fixed iterations to avoid consuming cycles from mainloop benchmark iterations
@@ -555,4 +553,3 @@ public class SQLiteDatabasePerfTest {
        createOrOpenTestDatabase(journalMode, syncMode);
    }
}