Search in sources :

Example 6 with DatabaseVersion

use of org.syncany.database.DatabaseVersion in project syncany by syncany.

the class FileSystemActionReconciliatorTest method testFileSystemActionReconDeleteNonExistingFolder.

@Test
public void testFileSystemActionReconDeleteNonExistingFolder() throws Exception {
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    Config testConfigA = clientA.getConfig();
    // - Create first database version
    clientA.createNewFolder("new folder/some subfolder");
    clientA.upWithForceChecksum();
    // Delete this!
    clientA.deleteFile("new folder/some subfolder");
    // - Create new version (delete folder)
    TestSqlDatabase sqlDatabaseA = new TestSqlDatabase(testConfigA);
    PartialFileHistory folderFileHistoryWithLastVersion = sqlDatabaseA.getFileHistoryWithLastVersion("new folder/some subfolder");
    FileVersion deletedFolderVersion = folderFileHistoryWithLastVersion.getLastVersion().clone();
    deletedFolderVersion.setStatus(FileStatus.DELETED);
    deletedFolderVersion.setVersion(deletedFolderVersion.getVersion() + 1);
    PartialFileHistory deletedFolderVersionHistory = new PartialFileHistory(folderFileHistoryWithLastVersion.getFileHistoryId());
    deletedFolderVersionHistory.addFileVersion(deletedFolderVersion);
    DatabaseVersion winnersDatabaseVersion = TestDatabaseUtil.createDatabaseVersion(sqlDatabaseA.getLastDatabaseVersionHeader());
    winnersDatabaseVersion.addFileHistory(deletedFolderVersionHistory);
    // - Create memory database with this version
    MemoryDatabase winnersDatabase = new MemoryDatabase();
    winnersDatabase.addDatabaseVersion(winnersDatabaseVersion);
    // Run! Finally!
    DownOperationResult outDownOperationResult = new DownOperationResult();
    FileSystemActionReconciliator fileSystemActionReconciliator = new FileSystemActionReconciliator(testConfigA, outDownOperationResult.getChangeSet());
    List<FileSystemAction> fileSystemActions = fileSystemActionReconciliator.determineFileSystemActions(winnersDatabase);
    assertNotNull(fileSystemActions);
    assertEquals(0, fileSystemActions.size());
    // Tear down
    clientA.deleteTestData();
}
Also used : Config(org.syncany.config.Config) DownOperationResult(org.syncany.operations.down.DownOperationResult) FileSystemAction(org.syncany.operations.down.actions.FileSystemAction) TestClient(org.syncany.tests.util.TestClient) FileVersion(org.syncany.database.FileVersion) MemoryDatabase(org.syncany.database.MemoryDatabase) TestSqlDatabase(org.syncany.tests.util.TestSqlDatabase) TransferSettings(org.syncany.plugins.transfer.TransferSettings) PartialFileHistory(org.syncany.database.PartialFileHistory) DatabaseVersion(org.syncany.database.DatabaseVersion) FileSystemActionReconciliator(org.syncany.operations.down.FileSystemActionReconciliator) Test(org.junit.Test)

Example 7 with DatabaseVersion

use of org.syncany.database.DatabaseVersion in project syncany by syncany.

the class MemoryDatabaseCacheTest method testRemoveDatabaseVersion.

@Test
public void testRemoveDatabaseVersion() {
    MemoryDatabase database = new MemoryDatabase();
    // Round 1: Add file history & version
    DatabaseVersion databaseVersion1 = TestDatabaseUtil.createDatabaseVersion();
    // - history 1, version 1
    FileVersion fileVersion1 = TestDatabaseUtil.createFileVersion("file.jpg");
    FileHistoryId idFile1 = FileHistoryId.parseFileId("1111111111111111");
    PartialFileHistory fileHistory1 = new PartialFileHistory(idFile1);
    fileHistory1.addFileVersion(fileVersion1);
    databaseVersion1.addFileHistory(fileHistory1);
    database.addDatabaseVersion(databaseVersion1);
    // - history 1, version 2		
    DatabaseVersion databaseVersion2 = TestDatabaseUtil.createDatabaseVersion(databaseVersion1);
    FileVersion fileVersion2 = TestDatabaseUtil.createFileVersion("file.jpg", fileVersion1);
    FileHistoryId idFile1b = FileHistoryId.parseFileId("1111111111111111");
    PartialFileHistory fileHistory1b = new PartialFileHistory(idFile1b);
    fileHistory1b.addFileVersion(fileVersion2);
    databaseVersion2.addFileHistory(fileHistory1b);
    database.addDatabaseVersion(databaseVersion2);
    // Tests: Database should have 2 versions of file
    assertEquals(2, database.getFileHistory(idFile1).getFileVersions().size());
    assertEquals(2, database.getFileHistory(idFile1b).getFileVersions().size());
    // Round 2: Remove second database version
    database.removeDatabaseVersion(databaseVersion2);
    // Tests: Second version removed, 1 version left
    assertEquals(1, database.getFileHistory(idFile1).getFileVersions().size());
    assertEquals(1, database.getFileHistory(idFile1b).getFileVersions().size());
    assertEquals(fileVersion1, database.getFileHistory(idFile1).getLastVersion());
    // Round 3: Add database version again
    database.addDatabaseVersion(databaseVersion2);
    // Tests: Second version added, 2 versions of file
    assertEquals(2, database.getFileHistory(idFile1).getFileVersions().size());
    assertEquals(2, database.getFileHistory(idFile1b).getFileVersions().size());
    // Round 4: Remove FIRST database version		
    database.removeDatabaseVersion(databaseVersion1);
    // Tests: First version removed, 1 version left
    assertEquals(1, database.getFileHistory(idFile1).getFileVersions().size());
    assertEquals(1, database.getFileHistory(idFile1b).getFileVersions().size());
    assertEquals(fileVersion2, database.getFileHistory(idFile1).getLastVersion());
    // Round 5: Remove second database version		
    database.removeDatabaseVersion(databaseVersion2);
    // Tests: Second version removed, none left
    assertNull(database.getFileHistory(idFile1));
}
Also used : FileHistoryId(org.syncany.database.PartialFileHistory.FileHistoryId) FileVersion(org.syncany.database.FileVersion) MemoryDatabase(org.syncany.database.MemoryDatabase) PartialFileHistory(org.syncany.database.PartialFileHistory) DatabaseVersion(org.syncany.database.DatabaseVersion) Test(org.junit.Test)

Example 8 with DatabaseVersion

use of org.syncany.database.DatabaseVersion in project syncany by syncany.

the class DatabaseVersionDaoTest method testRemoveDirtyDatabaseVersions.

@Test
public void testRemoveDirtyDatabaseVersions() throws Exception {
    // Setup
    Config testConfig = TestConfigUtil.createTestLocalConfig();
    Connection databaseConnection = testConfig.createDatabaseConnection();
    // Run
    TestSqlUtil.runSqlFromResource(databaseConnection, "test.insert.set1.sql");
    ChunkSqlDao chunkDao = new ChunkSqlDao(databaseConnection);
    MultiChunkSqlDao multiChunkDao = new MultiChunkSqlDao(databaseConnection);
    FileVersionSqlDao fileVersionDao = new FileVersionSqlDao(databaseConnection);
    FileHistorySqlDao fileHistoryDao = new FileHistorySqlDao(databaseConnection, fileVersionDao);
    FileContentSqlDao fileContentDao = new FileContentSqlDao(databaseConnection);
    DatabaseVersionSqlDao databaseVersionDao = new DatabaseVersionSqlDao(databaseConnection, chunkDao, fileContentDao, fileVersionDao, fileHistoryDao, multiChunkDao);
    // a. Test before
    List<DatabaseVersion> dirtyDatabaseVersionsBefore = TestCollectionUtil.toList(databaseVersionDao.getDirtyDatabaseVersions());
    assertNotNull(dirtyDatabaseVersionsBefore);
    assertNotNull(chunkDao.getChunk(ChunkChecksum.parseChunkChecksum("beefbeefbeefbeefbeefbeefbeefbeefbeefbeef")));
    assertNotNull(multiChunkDao.getDirtyMultiChunkIds());
    assertEquals(1, multiChunkDao.getDirtyMultiChunkIds().size());
    // b. Add new database version with DIRTY multichunk; remove DIRTY version		
    DatabaseVersion newDatabaseVersion = new DatabaseVersion();
    newDatabaseVersion.setVectorClock(TestDatabaseUtil.createVectorClock("A5,B2"));
    long newDatabaseVersionId = databaseVersionDao.writeDatabaseVersion(newDatabaseVersion);
    databaseVersionDao.removeDirtyDatabaseVersions(newDatabaseVersionId);
    // c. Test after		
    // Database version
    List<DatabaseVersion> dirtyDatabaseVersionsAfter = TestCollectionUtil.toList(databaseVersionDao.getDirtyDatabaseVersions());
    assertNotNull(dirtyDatabaseVersionsAfter);
    assertEquals(0, dirtyDatabaseVersionsAfter.size());
    // Multichunk from dirty version "moved" to new version
    Map<MultiChunkId, MultiChunkEntry> multiChunksA5B2 = multiChunkDao.getMultiChunks(TestDatabaseUtil.createVectorClock("A5,B2"));
    assertNotNull(multiChunksA5B2);
    assertEquals(1, multiChunksA5B2.size());
    assertNotNull(multiChunksA5B2.get(MultiChunkId.parseMultiChunkId("1234567890987654321123456789098765433222")));
    // File version/history/content ARE removed
    assertNull(fileContentDao.getFileContent(FileChecksum.parseFileChecksum("beefbeefbeefbeefbeefbeefbeefbeefbeefbeef"), true));
    // TODO [low] Test file version and file history removal		
    // Chunks and multichunks are NOT removed!
    assertNotNull(chunkDao.getChunk(ChunkChecksum.parseChunkChecksum("beefbeefbeefbeefbeefbeefbeefbeefbeefbeef")));
    assertNotNull(multiChunkDao.getMultiChunks(TestDatabaseUtil.createVectorClock("B1")));
    assertEquals(0, multiChunkDao.getMultiChunks(TestDatabaseUtil.createVectorClock("B1")).size());
    assertNotNull(multiChunkDao.getDirtyMultiChunkIds());
    assertEquals(0, multiChunkDao.getDirtyMultiChunkIds().size());
    // Tear down
    databaseConnection.close();
    TestConfigUtil.deleteTestLocalConfigAndData(testConfig);
}
Also used : MultiChunkId(org.syncany.database.MultiChunkEntry.MultiChunkId) Config(org.syncany.config.Config) Connection(java.sql.Connection) DatabaseVersionSqlDao(org.syncany.database.dao.DatabaseVersionSqlDao) MultiChunkSqlDao(org.syncany.database.dao.MultiChunkSqlDao) ChunkSqlDao(org.syncany.database.dao.ChunkSqlDao) MultiChunkSqlDao(org.syncany.database.dao.MultiChunkSqlDao) FileVersionSqlDao(org.syncany.database.dao.FileVersionSqlDao) FileContentSqlDao(org.syncany.database.dao.FileContentSqlDao) MultiChunkEntry(org.syncany.database.MultiChunkEntry) FileHistorySqlDao(org.syncany.database.dao.FileHistorySqlDao) DatabaseVersion(org.syncany.database.DatabaseVersion) Test(org.junit.Test)

Example 9 with DatabaseVersion

use of org.syncany.database.DatabaseVersion in project syncany by syncany.

the class DatabaseVersionDaoTest method testMarkDatabaseVersionDirty.

@Test
public void testMarkDatabaseVersionDirty() throws Exception {
    // Setup
    Config testConfig = TestConfigUtil.createTestLocalConfig();
    Connection databaseConnection = testConfig.createDatabaseConnection();
    // Run
    TestSqlUtil.runSqlFromResource(databaseConnection, "test.insert.set2.sql");
    ChunkSqlDao chunkDao = new ChunkSqlDao(databaseConnection);
    MultiChunkSqlDao multiChunkDao = new MultiChunkSqlDao(databaseConnection);
    FileVersionSqlDao fileVersionDao = new FileVersionSqlDao(databaseConnection);
    FileHistorySqlDao fileHistoryDao = new FileHistorySqlDao(databaseConnection, fileVersionDao);
    FileContentSqlDao fileContentDao = new FileContentSqlDao(databaseConnection);
    DatabaseVersionSqlDao databaseVersionDao = new DatabaseVersionSqlDao(databaseConnection, chunkDao, fileContentDao, fileVersionDao, fileHistoryDao, multiChunkDao);
    databaseVersionDao.markDatabaseVersionDirty(TestDatabaseUtil.createVectorClock("A48"));
    databaseVersionDao.markDatabaseVersionDirty(TestDatabaseUtil.createVectorClock("A49"));
    databaseVersionDao.markDatabaseVersionDirty(TestDatabaseUtil.createVectorClock("A50"));
    List<DatabaseVersion> dirtyDatabaseVersions = TestCollectionUtil.toList(databaseVersionDao.getDirtyDatabaseVersions());
    // Test
    assertNotNull(dirtyDatabaseVersions);
    assertEquals(3, dirtyDatabaseVersions.size());
    assertEquals("(A48)", dirtyDatabaseVersions.get(0).getVectorClock().toString());
    assertEquals("(A49)", dirtyDatabaseVersions.get(1).getVectorClock().toString());
    assertEquals("(A50)", dirtyDatabaseVersions.get(2).getVectorClock().toString());
    // Tear down
    databaseConnection.close();
    TestConfigUtil.deleteTestLocalConfigAndData(testConfig);
}
Also used : ChunkSqlDao(org.syncany.database.dao.ChunkSqlDao) MultiChunkSqlDao(org.syncany.database.dao.MultiChunkSqlDao) Config(org.syncany.config.Config) FileVersionSqlDao(org.syncany.database.dao.FileVersionSqlDao) FileContentSqlDao(org.syncany.database.dao.FileContentSqlDao) Connection(java.sql.Connection) DatabaseVersionSqlDao(org.syncany.database.dao.DatabaseVersionSqlDao) MultiChunkSqlDao(org.syncany.database.dao.MultiChunkSqlDao) FileHistorySqlDao(org.syncany.database.dao.FileHistorySqlDao) DatabaseVersion(org.syncany.database.DatabaseVersion) Test(org.junit.Test)

Example 10 with DatabaseVersion

use of org.syncany.database.DatabaseVersion in project syncany by syncany.

the class XmlDatabaseDaoTest method testWriteAndReadFileHistoryAndFileVersion.

@Test
public void testWriteAndReadFileHistoryAndFileVersion() throws IOException {
    // Prepare
    MemoryDatabase newDatabase = new MemoryDatabase();
    DatabaseVersion newDatabaseVersion = createDatabaseVersion();
    // Create directories (no content!)
    // File A
    PartialFileHistory fileHistoryA = new PartialFileHistory(FileHistoryId.secureRandomFileId());
    newDatabaseVersion.addFileHistory(fileHistoryA);
    FileVersion versionA1 = new FileVersion();
    versionA1.setVersion(1L);
    versionA1.setType(FileType.FOLDER);
    versionA1.setPath("Pictures/2013/New York Folder");
    versionA1.setStatus(FileStatus.NEW);
    versionA1.setSize(0L);
    versionA1.setLastModified(new Date());
    fileHistoryA.addFileVersion(versionA1);
    FileVersion versionA2 = new FileVersion();
    versionA2.setVersion(2L);
    versionA2.setType(FileType.FOLDER);
    versionA2.setPath("Pictures/2013/New York");
    versionA2.setStatus(FileStatus.RENAMED);
    versionA2.setSize(0L);
    versionA2.setLastModified(new Date());
    fileHistoryA.addFileVersion(versionA2);
    // File B
    PartialFileHistory fileHistoryB = new PartialFileHistory(FileHistoryId.secureRandomFileId());
    newDatabaseVersion.addFileHistory(fileHistoryB);
    FileVersion versionB1 = new FileVersion();
    versionB1.setVersion(1L);
    versionB1.setType(FileType.FOLDER);
    versionB1.setPath("Pictures/2013/Egypt Folder");
    versionB1.setStatus(FileStatus.NEW);
    versionB1.setSize(0L);
    versionB1.setLastModified(new Date());
    fileHistoryB.addFileVersion(versionB1);
    FileVersion versionB2 = new FileVersion();
    versionB2.setVersion(2L);
    versionB2.setType(FileType.FOLDER);
    versionB2.setPath("Pictures/2013/Egypt");
    versionB2.setStatus(FileStatus.RENAMED);
    versionB2.setSize(0L);
    versionB2.setLastModified(new Date());
    fileHistoryB.addFileVersion(versionB2);
    // Add database version
    newDatabase.addDatabaseVersion(newDatabaseVersion);
    // Write database to disk, read it again, and compare them
    MemoryDatabase loadedDatabase = writeReadAndCompareDatabase(newDatabase);
    // File histories
    PartialFileHistory loadedFileHistoryA = loadedDatabase.getFileHistory(fileHistoryA.getFileHistoryId());
    PartialFileHistory loadedFileHistoryB = loadedDatabase.getFileHistory(fileHistoryB.getFileHistoryId());
    assertEquals("File history not found in database loaded.", fileHistoryA, loadedFileHistoryA);
    assertEquals("File history not found in database loaded.", fileHistoryB, loadedFileHistoryB);
    assertArrayEquals("File versions differ in loaded database.", fileHistoryA.getFileVersions().values().toArray(), loadedFileHistoryA.getFileVersions().values().toArray());
    assertArrayEquals("File versions differ in loaded database.", fileHistoryB.getFileVersions().values().toArray(), loadedFileHistoryB.getFileVersions().values().toArray());
}
Also used : FileVersion(org.syncany.database.FileVersion) MemoryDatabase(org.syncany.database.MemoryDatabase) PartialFileHistory(org.syncany.database.PartialFileHistory) Date(java.util.Date) DatabaseVersion(org.syncany.database.DatabaseVersion) Test(org.junit.Test)

Aggregations

DatabaseVersion (org.syncany.database.DatabaseVersion)43 Test (org.junit.Test)22 MemoryDatabase (org.syncany.database.MemoryDatabase)20 MultiChunkEntry (org.syncany.database.MultiChunkEntry)12 PartialFileHistory (org.syncany.database.PartialFileHistory)12 ChunkEntry (org.syncany.database.ChunkEntry)11 FileVersion (org.syncany.database.FileVersion)10 ChunkChecksum (org.syncany.database.ChunkEntry.ChunkChecksum)9 ArrayList (java.util.ArrayList)8 FileHistoryId (org.syncany.database.PartialFileHistory.FileHistoryId)8 File (java.io.File)7 Config (org.syncany.config.Config)7 MultiChunkId (org.syncany.database.MultiChunkEntry.MultiChunkId)6 ChunkSqlDao (org.syncany.database.dao.ChunkSqlDao)6 DatabaseVersionSqlDao (org.syncany.database.dao.DatabaseVersionSqlDao)6 FileContentSqlDao (org.syncany.database.dao.FileContentSqlDao)6 FileHistorySqlDao (org.syncany.database.dao.FileHistorySqlDao)6 FileVersionSqlDao (org.syncany.database.dao.FileVersionSqlDao)6 MultiChunkSqlDao (org.syncany.database.dao.MultiChunkSqlDao)6 DatabaseRemoteFile (org.syncany.plugins.transfer.files.DatabaseRemoteFile)6