Search in sources :

Example 26 with PartialFileHistory

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

the class MemoryDatabaseCacheTest method testContentChecksumCache.

@Test
public void testContentChecksumCache() throws IOException {
    MemoryDatabase database = new MemoryDatabase();
    // Round 1: Add file history & version
    DatabaseVersion databaseVersion1 = TestDatabaseUtil.createDatabaseVersion();
    // - history 1, version 1
    FileVersion fileVersion1 = TestDatabaseUtil.createFileVersion("samechecksum1.jpg");
    fileVersion1.setChecksum(new FileChecksum(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }));
    FileHistoryId idFile1 = FileHistoryId.parseFileId("1111111111111111");
    PartialFileHistory fileHistory1 = new PartialFileHistory(idFile1);
    fileHistory1.addFileVersion(fileVersion1);
    databaseVersion1.addFileHistory(fileHistory1);
    database.addDatabaseVersion(databaseVersion1);
    assertNotNull(database.getFileHistories(new FileChecksum(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 })));
    assertEquals(1, database.getFileHistories(new FileChecksum(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 })).size());
    // Round 2: Add two other versions with same checksum to new database version
    DatabaseVersion databaseVersion2 = TestDatabaseUtil.createDatabaseVersion(databaseVersion1);
    // - history 1, version 2
    FileVersion fileVersion11 = TestDatabaseUtil.createFileVersion("samechecksum2-renamed.jpg", fileVersion1);
    // same checksum!
    fileVersion11.setChecksum(new FileChecksum(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }));
    fileVersion11.setStatus(FileStatus.RENAMED);
    FileHistoryId idFile11 = FileHistoryId.parseFileId("1111111111111111");
    // same ID as above
    PartialFileHistory fileHistory11 = new PartialFileHistory(idFile11);
    fileHistory11.addFileVersion(fileVersion11);
    databaseVersion2.addFileHistory(fileHistory11);
    // - history 2, version 1
    FileVersion fileVersion2 = TestDatabaseUtil.createFileVersion("samechecksum2.jpg");
    // same checksum!
    fileVersion2.setChecksum(new FileChecksum(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }));
    // different ID
    FileHistoryId idFile2 = FileHistoryId.parseFileId("1111111122222222");
    PartialFileHistory fileHistory2 = new PartialFileHistory(idFile2);
    fileHistory2.addFileVersion(fileVersion2);
    databaseVersion2.addFileHistory(fileHistory2);
    // - history 3, version 1
    FileVersion fileVersion3 = TestDatabaseUtil.createFileVersion("samechecksum3.jpg");
    // same checksum!
    fileVersion3.setChecksum(new FileChecksum(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }));
    // different ID
    FileHistoryId idFile3 = FileHistoryId.parseFileId("aaaaaaaa22222222");
    // different ID
    PartialFileHistory fileHistory3 = new PartialFileHistory(idFile3);
    fileHistory3.addFileVersion(fileVersion3);
    databaseVersion2.addFileHistory(fileHistory3);
    database.addDatabaseVersion(databaseVersion2);
    assertNotNull(database.getFileHistories(new FileChecksum(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 })));
    assertEquals(3, database.getFileHistories(new FileChecksum(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 })).size());
}
Also used : FileHistoryId(org.syncany.database.PartialFileHistory.FileHistoryId) FileVersion(org.syncany.database.FileVersion) MemoryDatabase(org.syncany.database.MemoryDatabase) FileChecksum(org.syncany.database.FileContent.FileChecksum) PartialFileHistory(org.syncany.database.PartialFileHistory) DatabaseVersion(org.syncany.database.DatabaseVersion) Test(org.junit.Test)

Example 27 with PartialFileHistory

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

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

Example 29 with PartialFileHistory

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

the class PartialFileHistoryTest method testFileHistoryInitEmpty.

@Test
public void testFileHistoryInitEmpty() {
    PartialFileHistory fileHistory = new PartialFileHistory(FileHistoryId.parseFileId("1234"));
    assertEquals(FileHistoryId.parseFileId("1234"), fileHistory.getFileHistoryId());
    assertNotSame(FileHistoryId.parseFileId("9999"), fileHistory.getFileHistoryId());
    assertNull(fileHistory.getLastVersion());
    assertNotNull(fileHistory.toString());
    assertTrue(fileHistory.toString().contains("1234"));
    assertNotNull(fileHistory.getFileVersions());
    assertEquals(0, fileHistory.getFileVersions().size());
}
Also used : PartialFileHistory(org.syncany.database.PartialFileHistory) Test(org.junit.Test)

Example 30 with PartialFileHistory

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

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