use of org.syncany.database.PartialFileHistory in project syncany by syncany.
the class DirtyDatabaseScenarioTest method testDirtyDatabase.
@Test
public void testDirtyDatabase() throws Exception {
// Setup
TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
// Run
UpOperationOptions upOptionsForceEnabled = new UpOperationOptions();
upOptionsForceEnabled.setForceUploadEnabled(true);
clientA.createNewFile("A-file1.jpg", 50 * 1024);
clientA.up(upOptionsForceEnabled);
clientB.createNewFile("A-file1.jpg", 51 * 1024);
clientB.up(upOptionsForceEnabled);
// This creates a dirty database
clientB.down();
// Test (for dirty database existence)
Config configB = clientB.getConfig();
java.sql.Connection databaseConnectionB = configB.createDatabaseConnection();
ChunkSqlDao chunkDao = new ChunkSqlDao(databaseConnectionB);
MultiChunkSqlDao multiChunkDao = new MultiChunkSqlDao(databaseConnectionB);
FileVersionSqlDao fileVersionDao = new FileVersionSqlDao(databaseConnectionB);
FileHistorySqlDao fileHistoryDao = new FileHistorySqlDao(databaseConnectionB, fileVersionDao);
FileContentSqlDao fileContentDao = new FileContentSqlDao(databaseConnectionB);
DatabaseVersionSqlDao databaseVersionDao = new DatabaseVersionSqlDao(databaseConnectionB, chunkDao, fileContentDao, fileVersionDao, fileHistoryDao, multiChunkDao);
Iterator<DatabaseVersion> databaseVersionsDirtyB = databaseVersionDao.getDirtyDatabaseVersions();
List<DatabaseVersion> databaseVersionsDirtyListB = TestCollectionUtil.toList(databaseVersionsDirtyB);
assertEquals(1, databaseVersionsDirtyListB.size());
DatabaseVersion dirtyDatabaseVersionB = databaseVersionsDirtyListB.get(0);
assertNotNull(dirtyDatabaseVersionB);
assertEquals(1, dirtyDatabaseVersionB.getFileHistories().size());
PartialFileHistory fileHistoryFile1B = dirtyDatabaseVersionB.getFileHistories().iterator().next();
assertNotNull(fileHistoryFile1B);
assertEquals(1, fileHistoryFile1B.getFileVersions().size());
assertEquals("A-file1.jpg", fileHistoryFile1B.getLastVersion().getPath());
assertFileEquals(clientA.getLocalFile("A-file1.jpg"), clientB.getLocalFile("A-file1.jpg"));
assertConflictingFileExists("A-file1.jpg", clientB.getLocalFilesExcludeLockedAndNoRead());
// Run (part 2)
// This deletes the dirty database file
clientB.up();
Iterator<DatabaseVersion> databaseVersionsDirtyB2 = databaseVersionDao.getDirtyDatabaseVersions();
List<DatabaseVersion> databaseVersionsDirtyListB2 = TestCollectionUtil.toList(databaseVersionsDirtyB2);
assertEquals(0, databaseVersionsDirtyListB2.size());
// Run (part 3)
// This pulls down the conflicting file
clientA.down();
assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
assertConflictingFileExists("A-file1.jpg", clientA.getLocalFilesExcludeLockedAndNoRead());
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
}
Aggregations