Search in sources :

Example 11 with PartialFileHistory

use of org.syncany.database.PartialFileHistory 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 12 with PartialFileHistory

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

the class PartialFileHistoryTest method testFileHistoryAddFileVersionInvalidVersionNull.

@Test(expected = IllegalArgumentException.class)
public void testFileHistoryAddFileVersionInvalidVersionNull() {
    PartialFileHistory fileHistory = new PartialFileHistory(FileHistoryId.parseFileId("1234"));
    fileHistory.addFileVersion(new FileVersion());
}
Also used : FileVersion(org.syncany.database.FileVersion) PartialFileHistory(org.syncany.database.PartialFileHistory) Test(org.junit.Test)

Example 13 with PartialFileHistory

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

the class PartialFileHistoryTest method testFileHistoryAddFileVersionInvalidNull.

@Test(expected = IllegalArgumentException.class)
public void testFileHistoryAddFileVersionInvalidNull() {
    PartialFileHistory fileHistory = new PartialFileHistory(FileHistoryId.parseFileId("1234"));
    fileHistory.addFileVersion(null);
}
Also used : PartialFileHistory(org.syncany.database.PartialFileHistory) Test(org.junit.Test)

Example 14 with PartialFileHistory

use of org.syncany.database.PartialFileHistory 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)

Example 15 with PartialFileHistory

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

the class Indexer method createFileHistoryForDeletion.

private PartialFileHistory createFileHistoryForDeletion(PartialFileHistory fileHistory, FileVersion lastLocalVersion) {
    PartialFileHistory deletedFileHistory = new PartialFileHistory(fileHistory.getFileHistoryId());
    FileVersion deletedVersion = lastLocalVersion.clone();
    deletedVersion.setStatus(FileStatus.DELETED);
    deletedVersion.setVersion(fileHistory.getLastVersion().getVersion() + 1);
    deletedVersion.setUpdated(new Date());
    deletedFileHistory.addFileVersion(deletedVersion);
    return deletedFileHistory;
}
Also used : FileVersion(org.syncany.database.FileVersion) PartialFileHistory(org.syncany.database.PartialFileHistory) Date(java.util.Date)

Aggregations

PartialFileHistory (org.syncany.database.PartialFileHistory)31 FileVersion (org.syncany.database.FileVersion)23 Test (org.junit.Test)17 DatabaseVersion (org.syncany.database.DatabaseVersion)12 FileHistoryId (org.syncany.database.PartialFileHistory.FileHistoryId)12 MemoryDatabase (org.syncany.database.MemoryDatabase)8 PreparedStatement (java.sql.PreparedStatement)5 SQLException (java.sql.SQLException)5 ResultSet (java.sql.ResultSet)4 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 File (java.io.File)3 Config (org.syncany.config.Config)3 ChunkEntry (org.syncany.database.ChunkEntry)3 FileContent (org.syncany.database.FileContent)3 FileChecksum (org.syncany.database.FileContent.FileChecksum)3 MultiChunkEntry (org.syncany.database.MultiChunkEntry)3 MultiChunkId (org.syncany.database.MultiChunkEntry.MultiChunkId)3 TransferSettings (org.syncany.plugins.transfer.TransferSettings)3 TestClient (org.syncany.tests.util.TestClient)3