~jamesh/mediascanner2/bug-1489489

« back to all changes in this revision

Viewing changes to test/test_mediastore.cc

  • Committer: CI Train Bot
  • Author(s): James Henstridge
  • Date: 2016-02-25 01:53:12 UTC
  • mfrom: (320.1.6 batch-updates)
  • Revision ID: ci-train-bot@canonical.com-20160225015312-d8d0kqt7qlqfhd2r
Add an API for batching multiple MediaStore updates into a single transaction.  Use this new API during the initial directory scan during start up.
Approved by: Michi Henning

Show diffs side-by-side

added added

removed removed

Lines of Context:
1320
1320
    }
1321
1321
}
1322
1322
 
 
1323
TEST_F(MediaStoreTest, transaction) {
 
1324
    MediaStore store(":memory:", MS_READ_WRITE);
 
1325
 
 
1326
    // Run a transaction without committing: file not added.
 
1327
    {
 
1328
        MediaStoreTransaction txn = store.beginTransaction();
 
1329
        store.insert(MediaFileBuilder("/one.mp3").setType(AudioMedia));
 
1330
    }
 
1331
    EXPECT_EQ(0, store.size());
 
1332
    EXPECT_THROW(store.lookup("/one.mp3"), std::runtime_error);
 
1333
 
 
1334
    // Commit two files in a transaction, then one file in a second
 
1335
    // transaction, and leave the last uncommitted.
 
1336
    {
 
1337
        MediaStoreTransaction txn = store.beginTransaction();
 
1338
        store.insert(MediaFileBuilder("/one.mp3").setType(AudioMedia));
 
1339
        store.insert(MediaFileBuilder("/two.mp3").setType(AudioMedia));
 
1340
        txn.commit();
 
1341
        store.insert(MediaFileBuilder("/three.mp3").setType(AudioMedia));
 
1342
        txn.commit();
 
1343
        store.insert(MediaFileBuilder("/four.mp3").setType(AudioMedia));
 
1344
    }
 
1345
    EXPECT_EQ(3, store.size());
 
1346
    store.lookup("/one.mp3");
 
1347
    store.lookup("/two.mp3");
 
1348
    store.lookup("/three.mp3");
 
1349
    EXPECT_THROW(store.lookup("/four.mp3"), std::runtime_error);
 
1350
}
 
1351
 
1323
1352
int main(int argc, char **argv) {
1324
1353
    ::testing::InitGoogleTest(&argc, argv);
1325
1354
    return RUN_ALL_TESTS();