Changeset 2542 for box/trunk


Ignore:
Timestamp:
28/06/2009 20:33:34 (3 years ago)
Author:
chris
Message:

Test that housekeeping can recreate the refcount database if it's
missing.

Location:
box/trunk/test/backupstore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • box/trunk/test/backupstore/testbackupstore.cpp

    r2535 r2542  
    3737#include "BackupStoreAccountDatabase.h" 
    3838#include "BackupStoreRefCountDatabase.h" 
     39#include "BackupStoreAccounts.h" 
     40#include "HousekeepStoreAccount.h" 
    3941 
    4042#include "MemLeakFindOn.h" 
     
    473475} 
    474476 
     477std::vector<uint32_t> ExpectedRefCounts; 
     478 
     479void set_refcount(int64_t ObjectID, uint32_t RefCount = 1) 
     480{ 
     481        if (ExpectedRefCounts.size() <= ObjectID); 
     482        { 
     483                ExpectedRefCounts.resize(ObjectID + 1, 0); 
     484        } 
     485        ExpectedRefCounts[ObjectID] = RefCount; 
     486} 
     487 
    475488void create_file_in_dir(std::string name, std::string source, int64_t parentId, 
    476489        BackupProtocolClient &protocol, BackupStoreRefCountDatabase& rRefCount) 
     
    490503        TEST_EQUAL(objectId, rRefCount.GetLastObjectIDUsed()); 
    491504        TEST_EQUAL(1, rRefCount.GetRefCount(objectId)) 
     505        set_refcount(objectId, 1); 
    492506} 
    493507 
     
    510524        printf("Create subdirs, depth = %d, dirid = %llx\n", depth, subdirid); 
    511525 
    512         std::auto_ptr<BackupStoreAccountDatabase> apAccounts( 
    513                 BackupStoreAccountDatabase::Read("testfiles/accounts.txt")); 
    514         std::auto_ptr<BackupStoreRefCountDatabase> apReferences( 
    515                 BackupStoreRefCountDatabase::Load( 
    516                         apAccounts->GetEntry(0x1234567), true)); 
    517526        TEST_EQUAL(subdirid, rRefCount.GetLastObjectIDUsed()); 
    518527        TEST_EQUAL(1, rRefCount.GetRefCount(subdirid)) 
     528        set_refcount(subdirid, 1); 
    519529         
    520530        // Put more directories in it, if we haven't gone down too far 
     
    635645        // Get a connection 
    636646        SocketStreamTLS connReadOnly; 
    637         connReadOnly.Open(context, Socket::TypeINET, hostname, BOX_PORT_BBSTORED); 
     647        connReadOnly.Open(context, Socket::TypeINET, hostname, 
     648                BOX_PORT_BBSTORED_TEST); 
    638649        BackupProtocolClient protocolReadOnly(connReadOnly); 
    639650 
     
    797808                TEST_THAT(store1objid == 2); 
    798809        } 
     810        set_refcount(store1objid, 1); 
    799811        // And retrieve it 
    800812        { 
     
    903915        init_context(rContext); 
    904916        std::auto_ptr<SocketStreamTLS> conn(new SocketStreamTLS); 
    905         conn->Open(rContext, Socket::TypeINET, hostname, BOX_PORT_BBSTORED); 
     917        conn->Open(rContext, Socket::TypeINET, hostname, 
     918                BOX_PORT_BBSTORED_TEST); 
    906919        return conn; 
    907920} 
     
    923936 
    924937        return protocol; 
     938} 
     939 
     940void run_housekeeping(BackupStoreAccountDatabase::Entry& rAccount) 
     941{ 
     942        std::string rootDir = BackupStoreAccounts::GetAccountRoot(rAccount); 
     943        int discSet = rAccount.GetDiscSet(); 
     944 
     945        // Do housekeeping on this account 
     946        HousekeepStoreAccount housekeeping(rAccount.GetID(), rootDir, 
     947                discSet, NULL); 
     948        housekeeping.DoHousekeeping(true /* keep trying forever */); 
    925949} 
    926950 
     
    958982                { 
    959983                        SocketStreamTLS conn; 
    960                         conn.Open(context, Socket::TypeINET, hostname, BOX_PORT_BBSTORED); 
     984                        conn.Open(context, Socket::TypeINET, hostname, 
     985                                BOX_PORT_BBSTORED_TEST); 
    961986                        BackupProtocolClient protocol(conn); 
    962987                        std::auto_ptr<BackupProtocolClientVersion> serverVersion(protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION)); 
     
    974999                // Open a new connection which is read only 
    9751000                SocketStreamTLS connReadOnly; 
    976                 connReadOnly.Open(context, Socket::TypeINET, hostname, BOX_PORT_BBSTORED); 
     1001                connReadOnly.Open(context, Socket::TypeINET, hostname, 
     1002                        BOX_PORT_BBSTORED_TEST); 
    9771003                BackupProtocolClient protocolReadOnly(connReadOnly); 
    9781004 
     
    10221048                        uploads[t].mod_time = modtime; 
    10231049                        if(maxID < stored->GetObjectID()) maxID = stored->GetObjectID(); 
     1050                        set_refcount(stored->GetObjectID(), 1); 
     1051                        BOX_TRACE("wrote file " << filename << " to server " 
     1052                                "as object " << 
     1053                                BOX_FORMAT_OBJECTID(stored->GetObjectID())); 
    10241054                } 
    10251055 
     
    11421172                                patchedID = stored->GetObjectID(); 
    11431173                        } 
     1174 
     1175                        set_refcount(patchedID, 1); 
     1176 
    11441177                        // Then download it to check it's OK 
    11451178                        std::auto_ptr<BackupProtocolClientSuccess> getFile(protocol.QueryGetFile(BackupProtocolClientListDirectory::RootDirectory, patchedID)); 
     
    11631196                        TEST_THAT(subdirid == maxID + 1); 
    11641197                } 
     1198 
     1199                set_refcount(subdirid, 1); 
     1200 
    11651201                // Stick a file in it 
    11661202                int64_t subdirfileid = 0; 
     
    11791215                        subdirfileid = stored->GetObjectID(); 
    11801216                } 
     1217 
     1218                set_refcount(subdirfileid, 1); 
    11811219 
    11821220                printf("\n==== Checking upload using read-only connection\n"); 
     
    14021440                        subsubfileid = stored->GetObjectID(); 
    14031441                } 
     1442 
     1443                set_refcount(subsubdirid, 1); 
     1444                set_refcount(subsubfileid, 1); 
    14041445 
    14051446                // Query names -- test that invalid stuff returns not found OK 
     
    17601801                        // Open a connection to the server 
    17611802                        SocketStreamTLS conn; 
    1762                         conn.Open(context, Socket::TypeINET, "localhost", BOX_PORT_BBSTORED); 
     1803                        conn.Open(context, Socket::TypeINET, "localhost", 
     1804                                BOX_PORT_BBSTORED_TEST); 
    17631805 
    17641806                        // Make a protocol 
     
    18061848                TEST_EQUAL(0, ::unlink("testfiles/0_0/backup/01234567/refcount.db.rfw")); 
    18071849 
    1808                 // Context 
    18091850                TLSContext context; 
    18101851                std::auto_ptr<SocketStreamTLS> conn = open_conn("localhost", 
     
    18121853                test_server_login(*conn)->QueryFinished(); 
    18131854 
    1814                 apReferences = BackupStoreRefCountDatabase::Load( 
    1815                         apAccounts->GetEntry(0x1234567), true); 
     1855                BackupStoreAccountDatabase::Entry account = 
     1856                        apAccounts->GetEntry(0x1234567); 
     1857                apReferences = BackupStoreRefCountDatabase::Load(account, true); 
    18161858                TEST_EQUAL(0, apReferences->GetLastObjectIDUsed()); 
    18171859 
    18181860                TEST_THAT(ServerIsAlive(pid)); 
    18191861 
     1862                run_housekeeping(account); 
     1863 
     1864                // Check that housekeeping fixed the ref counts 
     1865                TEST_EQUAL(BACKUPSTORE_ROOT_DIRECTORY_ID, 
     1866                        apReferences->GetLastObjectIDUsed()); 
     1867                TEST_EQUAL(1, apReferences->GetRefCount(BACKUPSTORE_ROOT_DIRECTORY_ID)) 
     1868 
     1869                TEST_THAT(ServerIsAlive(pid)); 
     1870 
     1871                set_refcount(BACKUPSTORE_ROOT_DIRECTORY_ID, 1); 
     1872 
    18201873                TEST_THAT(test_server("localhost") == 0); 
     1874 
     1875                // test that all object reference counts have the 
     1876                // expected values 
     1877                TEST_EQUAL(ExpectedRefCounts.size() - 1, 
     1878                        apReferences->GetLastObjectIDUsed()); 
     1879                for (unsigned int i = BACKUPSTORE_ROOT_DIRECTORY_ID; 
     1880                        i < ExpectedRefCounts.size(); i++) 
     1881                { 
     1882                        TEST_EQUAL_LINE(ExpectedRefCounts[i], 
     1883                                apReferences->GetRefCount(i), 
     1884                                "object " << BOX_FORMAT_OBJECTID(i)); 
     1885                } 
     1886 
     1887                // Delete the refcount database again, and let 
     1888                // housekeeping recreate it and fix the ref counts. 
     1889                // This could also happen after upgrade, if a housekeeping 
     1890                // runs before the user logs in. 
     1891                apReferences.reset(); 
     1892                TEST_EQUAL(0, ::unlink("testfiles/0_0/backup/01234567/refcount.db.rfw")); 
     1893                run_housekeeping(account); 
     1894                apReferences = BackupStoreRefCountDatabase::Load(account, true); 
     1895 
     1896                TEST_EQUAL(ExpectedRefCounts.size() - 1, 
     1897                        apReferences->GetLastObjectIDUsed()); 
     1898                for (unsigned int i = BACKUPSTORE_ROOT_DIRECTORY_ID; 
     1899                        i < ExpectedRefCounts.size(); i++) 
     1900                { 
     1901                        TEST_EQUAL_LINE(ExpectedRefCounts[i], 
     1902                                apReferences->GetRefCount(i), 
     1903                                "object " << BOX_FORMAT_OBJECTID(i)); 
     1904                } 
    18211905                 
    18221906                // Test the deletion of objects by the housekeeping system 
     
    18871971                        // Open a connection to the server 
    18881972                        SocketStreamTLS conn; 
    1889                         conn.Open(context, Socket::TypeINET, "localhost", BOX_PORT_BBSTORED); 
     1973                        conn.Open(context, Socket::TypeINET, "localhost", 
     1974                                BOX_PORT_BBSTORED_TEST); 
    18901975 
    18911976                        // Make a protocol 
  • box/trunk/test/backupstore/testfiles/bbstored.conf

    r217 r2542  
    1010{ 
    1111        PidFile = testfiles/bbstored.pid 
    12         ListenAddresses = inet:localhost 
     12        ListenAddresses = inet:localhost:22011 
    1313        CertificateFile = testfiles/serverCerts.pem 
    1414        PrivateKeyFile = testfiles/serverPrivKey.pem 
Note: See TracChangeset for help on using the changeset viewer.