Search in sources :

Example 41 with FileVersion

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

the class LogOperation method createLightweightDatabaseVersion.

private LightweightDatabaseVersion createLightweightDatabaseVersion(DatabaseVersion databaseVersion) {
    // Create changeset
    ChangeSet changedFiles = new ChangeSet();
    for (PartialFileHistory fileHistory : databaseVersion.getFileHistories()) {
        FileVersion fileVersion = fileHistory.getLastVersion();
        switch(fileVersion.getStatus()) {
            case NEW:
                changedFiles.getNewFiles().add(fileVersion.getPath());
                break;
            case CHANGED:
            case RENAMED:
                changedFiles.getChangedFiles().add(fileVersion.getPath());
                break;
            case DELETED:
                changedFiles.getDeletedFiles().add(fileVersion.getPath());
                break;
        }
    }
    // Create lightweight database version
    LightweightDatabaseVersion lightweightDatabaseVersion = new LightweightDatabaseVersion();
    lightweightDatabaseVersion.setClient(databaseVersion.getHeader().getClient());
    lightweightDatabaseVersion.setDate(databaseVersion.getHeader().getDate());
    lightweightDatabaseVersion.setChangeSet(changedFiles);
    return lightweightDatabaseVersion;
}
Also used : FileVersion(org.syncany.database.FileVersion) ChangeSet(org.syncany.operations.ChangeSet) PartialFileHistory(org.syncany.database.PartialFileHistory)

Example 42 with FileVersion

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

the class UpOperationTest method compareFileVersionsAgainstOriginalFiles.

private void compareFileVersionsAgainstOriginalFiles(List<File> originalFiles, List<FileVersion> localFileVersions) throws Exception {
    int toFind = originalFiles.size();
    for (File originalFile : originalFiles) {
        String originalFileName = originalFile.getName();
        for (FileVersion fileVersion : localFileVersions) {
            String fileVersionFileName = fileVersion.getName();
            if (fileVersionFileName.equals(originalFileName)) {
                toFind--;
            }
        }
    }
    assertEquals(0, toFind);
}
Also used : FileVersion(org.syncany.database.FileVersion) File(java.io.File)

Example 43 with FileVersion

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

the class UpOperationTest method testUploadLocalDatabase.

@Test
public void testUploadLocalDatabase() throws Exception {
    int fileSize = 1230 * 1024;
    int fileAmount = 3;
    List<File> originalFiles = TestFileUtil.createRandomFilesInDirectory(testConfig.getLocalDir(), fileSize, fileAmount);
    // Run!
    AbstractTransferOperation op = new UpOperation(testConfig);
    op.execute();
    // Get databases (for comparison)
    LocalTransferSettings localConnection = (LocalTransferSettings) testConfig.getConnection();
    File localDatabaseDir = testConfig.getDatabaseDir();
    File remoteDatabaseFile = new File(localConnection.getPath() + "/databases/database-" + testConfig.getMachineName() + "-0000000001");
    assertNotNull(localDatabaseDir.listFiles());
    assertTrue(localDatabaseDir.listFiles().length > 0);
    assertTrue(remoteDatabaseFile.exists());
    // - Memory database
    DatabaseXmlSerializer dDAO = new DatabaseXmlSerializer(testConfig.getTransformer());
    MemoryDatabase remoteDatabase = new MemoryDatabase();
    dDAO.load(remoteDatabase, remoteDatabaseFile, null, null, DatabaseReadType.FULL);
    DatabaseVersion remoteDatabaseVersion = remoteDatabase.getLastDatabaseVersion();
    // - Sql Database
    SqlDatabase localDatabase = new SqlDatabase(testConfig);
    Map<FileHistoryId, PartialFileHistory> localFileHistories = localDatabase.getFileHistoriesWithFileVersions();
    // Compare!
    assertEquals(localDatabase.getLastDatabaseVersionHeader(), remoteDatabaseVersion.getHeader());
    assertEquals(localFileHistories.size(), fileAmount);
    assertEquals(localDatabase.getFileHistoriesWithFileVersions().size(), remoteDatabaseVersion.getFileHistories().size());
    Collection<PartialFileHistory> remoteFileHistories = remoteDatabaseVersion.getFileHistories();
    List<FileVersion> remoteFileVersions = new ArrayList<FileVersion>();
    List<FileVersion> localFileVersions = new ArrayList<FileVersion>();
    for (PartialFileHistory partialFileHistory : remoteFileHistories) {
        remoteFileVersions.add(partialFileHistory.getLastVersion());
        assertNotNull(localFileHistories.get(partialFileHistory.getFileHistoryId()));
    }
    for (PartialFileHistory partialFileHistory : localFileHistories.values()) {
        localFileVersions.add(partialFileHistory.getLastVersion());
    }
    assertTrue(CollectionUtil.containsExactly(localFileVersions, remoteFileVersions));
    compareFileVersionsAgainstOriginalFiles(originalFiles, localFileVersions);
    compareFileVersionsAgainstOriginalFiles(originalFiles, remoteFileVersions);
}
Also used : FileHistoryId(org.syncany.database.PartialFileHistory.FileHistoryId) ArrayList(java.util.ArrayList) DatabaseXmlSerializer(org.syncany.database.dao.DatabaseXmlSerializer) PartialFileHistory(org.syncany.database.PartialFileHistory) AbstractTransferOperation(org.syncany.operations.AbstractTransferOperation) UpOperation(org.syncany.operations.up.UpOperation) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) FileVersion(org.syncany.database.FileVersion) MemoryDatabase(org.syncany.database.MemoryDatabase) SqlDatabase(org.syncany.database.SqlDatabase) File(java.io.File) DatabaseVersion(org.syncany.database.DatabaseVersion) Test(org.junit.Test)

Example 44 with FileVersion

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

the class PartialFileHistoryTest method testFileHistoryClone.

@Test
public void testFileHistoryClone() {
    FileVersion fileVersion1 = new FileVersion();
    fileVersion1.setVersion(1L);
    fileVersion1.setPath("/somepath");
    FileVersion fileVersion2 = new FileVersion();
    fileVersion2.setVersion(2L);
    fileVersion2.setPath("/somepath");
    PartialFileHistory fileHistory = new PartialFileHistory(FileHistoryId.parseFileId("1234"));
    fileHistory.addFileVersion(fileVersion1);
    fileHistory.addFileVersion(fileVersion2);
    PartialFileHistory fileHistoryClone = fileHistory.clone();
    assertEquals(fileHistory, fileHistoryClone);
    assertEquals(fileHistory.getFileVersions().size(), fileHistoryClone.getFileVersions().size());
    assertEquals(fileHistory.getFileVersions(), fileHistoryClone.getFileVersions());
    FileVersion fileVersion3 = new FileVersion();
    fileVersion3.setVersion(3L);
    fileVersion3.setPath("/somepath");
    fileHistoryClone.addFileVersion(fileVersion3);
    assertEquals(fileHistory.getFileVersions().size() + 1, fileHistoryClone.getFileVersions().size());
}
Also used : FileVersion(org.syncany.database.FileVersion) PartialFileHistory(org.syncany.database.PartialFileHistory) Test(org.junit.Test)

Example 45 with FileVersion

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

the class PartialFileHistoryTest method testFileHistoryGetVersionsNonEmpty.

@Test
public void testFileHistoryGetVersionsNonEmpty() {
    FileVersion fileVersion = new FileVersion();
    fileVersion.setVersion(5L);
    fileVersion.setPath("/somepath");
    PartialFileHistory fileHistory = new PartialFileHistory(FileHistoryId.parseFileId("1234"));
    fileHistory.addFileVersion(fileVersion);
    assertNotNull(fileHistory.getLastVersion());
    assertNotNull(fileHistory.getFileVersions());
    assertEquals(1, fileHistory.getFileVersions().size());
    assertEquals(fileVersion, fileHistory.getLastVersion());
    assertNull(fileHistory.getFileVersions().get(1L));
    assertNull(fileHistory.getFileVersion(1L));
    assertEquals(fileVersion, fileHistory.getFileVersions().get(5L));
    assertEquals(fileVersion, fileHistory.getFileVersion(5L));
}
Also used : FileVersion(org.syncany.database.FileVersion) PartialFileHistory(org.syncany.database.PartialFileHistory) Test(org.junit.Test)

Aggregations

FileVersion (org.syncany.database.FileVersion)52 PartialFileHistory (org.syncany.database.PartialFileHistory)25 FileHistoryId (org.syncany.database.PartialFileHistory.FileHistoryId)23 Test (org.junit.Test)19 DatabaseVersion (org.syncany.database.DatabaseVersion)12 ArrayList (java.util.ArrayList)10 Date (java.util.Date)10 FileChecksum (org.syncany.database.FileContent.FileChecksum)8 MemoryDatabase (org.syncany.database.MemoryDatabase)8 PreparedStatement (java.sql.PreparedStatement)7 Config (org.syncany.config.Config)7 File (java.io.File)6 ResultSet (java.sql.ResultSet)6 SQLException (java.sql.SQLException)5 HashMap (java.util.HashMap)5 List (java.util.List)5 FileContent (org.syncany.database.FileContent)5 MultiChunkId (org.syncany.database.MultiChunkEntry.MultiChunkId)5 Connection (java.sql.Connection)4 Map (java.util.Map)4