- Timestamp:
- 28/06/2009 20:33:34 (3 years ago)
- Location:
- box/trunk/test/backupstore
- Files:
-
- 2 edited
-
testbackupstore.cpp (modified) (19 diffs)
-
testfiles/bbstored.conf (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
box/trunk/test/backupstore/testbackupstore.cpp
r2535 r2542 37 37 #include "BackupStoreAccountDatabase.h" 38 38 #include "BackupStoreRefCountDatabase.h" 39 #include "BackupStoreAccounts.h" 40 #include "HousekeepStoreAccount.h" 39 41 40 42 #include "MemLeakFindOn.h" … … 473 475 } 474 476 477 std::vector<uint32_t> ExpectedRefCounts; 478 479 void 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 475 488 void create_file_in_dir(std::string name, std::string source, int64_t parentId, 476 489 BackupProtocolClient &protocol, BackupStoreRefCountDatabase& rRefCount) … … 490 503 TEST_EQUAL(objectId, rRefCount.GetLastObjectIDUsed()); 491 504 TEST_EQUAL(1, rRefCount.GetRefCount(objectId)) 505 set_refcount(objectId, 1); 492 506 } 493 507 … … 510 524 printf("Create subdirs, depth = %d, dirid = %llx\n", depth, subdirid); 511 525 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));517 526 TEST_EQUAL(subdirid, rRefCount.GetLastObjectIDUsed()); 518 527 TEST_EQUAL(1, rRefCount.GetRefCount(subdirid)) 528 set_refcount(subdirid, 1); 519 529 520 530 // Put more directories in it, if we haven't gone down too far … … 635 645 // Get a connection 636 646 SocketStreamTLS connReadOnly; 637 connReadOnly.Open(context, Socket::TypeINET, hostname, BOX_PORT_BBSTORED); 647 connReadOnly.Open(context, Socket::TypeINET, hostname, 648 BOX_PORT_BBSTORED_TEST); 638 649 BackupProtocolClient protocolReadOnly(connReadOnly); 639 650 … … 797 808 TEST_THAT(store1objid == 2); 798 809 } 810 set_refcount(store1objid, 1); 799 811 // And retrieve it 800 812 { … … 903 915 init_context(rContext); 904 916 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); 906 919 return conn; 907 920 } … … 923 936 924 937 return protocol; 938 } 939 940 void 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 */); 925 949 } 926 950 … … 958 982 { 959 983 SocketStreamTLS conn; 960 conn.Open(context, Socket::TypeINET, hostname, BOX_PORT_BBSTORED); 984 conn.Open(context, Socket::TypeINET, hostname, 985 BOX_PORT_BBSTORED_TEST); 961 986 BackupProtocolClient protocol(conn); 962 987 std::auto_ptr<BackupProtocolClientVersion> serverVersion(protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION)); … … 974 999 // Open a new connection which is read only 975 1000 SocketStreamTLS connReadOnly; 976 connReadOnly.Open(context, Socket::TypeINET, hostname, BOX_PORT_BBSTORED); 1001 connReadOnly.Open(context, Socket::TypeINET, hostname, 1002 BOX_PORT_BBSTORED_TEST); 977 1003 BackupProtocolClient protocolReadOnly(connReadOnly); 978 1004 … … 1022 1048 uploads[t].mod_time = modtime; 1023 1049 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())); 1024 1054 } 1025 1055 … … 1142 1172 patchedID = stored->GetObjectID(); 1143 1173 } 1174 1175 set_refcount(patchedID, 1); 1176 1144 1177 // Then download it to check it's OK 1145 1178 std::auto_ptr<BackupProtocolClientSuccess> getFile(protocol.QueryGetFile(BackupProtocolClientListDirectory::RootDirectory, patchedID)); … … 1163 1196 TEST_THAT(subdirid == maxID + 1); 1164 1197 } 1198 1199 set_refcount(subdirid, 1); 1200 1165 1201 // Stick a file in it 1166 1202 int64_t subdirfileid = 0; … … 1179 1215 subdirfileid = stored->GetObjectID(); 1180 1216 } 1217 1218 set_refcount(subdirfileid, 1); 1181 1219 1182 1220 printf("\n==== Checking upload using read-only connection\n"); … … 1402 1440 subsubfileid = stored->GetObjectID(); 1403 1441 } 1442 1443 set_refcount(subsubdirid, 1); 1444 set_refcount(subsubfileid, 1); 1404 1445 1405 1446 // Query names -- test that invalid stuff returns not found OK … … 1760 1801 // Open a connection to the server 1761 1802 SocketStreamTLS conn; 1762 conn.Open(context, Socket::TypeINET, "localhost", BOX_PORT_BBSTORED); 1803 conn.Open(context, Socket::TypeINET, "localhost", 1804 BOX_PORT_BBSTORED_TEST); 1763 1805 1764 1806 // Make a protocol … … 1806 1848 TEST_EQUAL(0, ::unlink("testfiles/0_0/backup/01234567/refcount.db.rfw")); 1807 1849 1808 // Context1809 1850 TLSContext context; 1810 1851 std::auto_ptr<SocketStreamTLS> conn = open_conn("localhost", … … 1812 1853 test_server_login(*conn)->QueryFinished(); 1813 1854 1814 apReferences = BackupStoreRefCountDatabase::Load( 1815 apAccounts->GetEntry(0x1234567), true); 1855 BackupStoreAccountDatabase::Entry account = 1856 apAccounts->GetEntry(0x1234567); 1857 apReferences = BackupStoreRefCountDatabase::Load(account, true); 1816 1858 TEST_EQUAL(0, apReferences->GetLastObjectIDUsed()); 1817 1859 1818 1860 TEST_THAT(ServerIsAlive(pid)); 1819 1861 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 1820 1873 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 } 1821 1905 1822 1906 // Test the deletion of objects by the housekeeping system … … 1887 1971 // Open a connection to the server 1888 1972 SocketStreamTLS conn; 1889 conn.Open(context, Socket::TypeINET, "localhost", BOX_PORT_BBSTORED); 1973 conn.Open(context, Socket::TypeINET, "localhost", 1974 BOX_PORT_BBSTORED_TEST); 1890 1975 1891 1976 // Make a protocol -
box/trunk/test/backupstore/testfiles/bbstored.conf
r217 r2542 10 10 { 11 11 PidFile = testfiles/bbstored.pid 12 ListenAddresses = inet:localhost 12 ListenAddresses = inet:localhost:22011 13 13 CertificateFile = testfiles/serverCerts.pem 14 14 PrivateKeyFile = testfiles/serverPrivKey.pem
Note: See TracChangeset
for help on using the changeset viewer.
