Search in sources :

Example 16 with FileVersion

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

the class GetFileHistoryFolderRequestHandler method handleRequest.

@Override
public Response handleRequest(FolderRequest request) {
    GetFileHistoryFolderRequest concreteRequest = (GetFileHistoryFolderRequest) request;
    FileHistoryId fileHistoryId = FileHistoryId.parseFileId(concreteRequest.getFileHistoryId());
    List<FileVersion> fileHistory = localDatabase.getFileHistory(fileHistoryId);
    return new GetFileHistoryFolderResponse(concreteRequest.getId(), concreteRequest.getRoot(), fileHistory);
}
Also used : FileHistoryId(org.syncany.database.PartialFileHistory.FileHistoryId) FileVersion(org.syncany.database.FileVersion)

Example 17 with FileVersion

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

the class DatabaseVersionDaoTest method testNonEmptyDatabaseVersionHeaders.

@Test
public void testNonEmptyDatabaseVersionHeaders() 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);
    List<DatabaseVersionHeader> databaseVersionHeaders = databaseVersionDao.getNonEmptyDatabaseVersionHeaders();
    Collection<String> databaseVersionHeaderStrings = databaseVersionHeaders.stream().map(dbv -> dbv.toString()).collect(Collectors.toCollection(ArrayList::new));
    // Test
    assertNotNull(databaseVersionHeaders);
    assertEquals(6, databaseVersionHeaders.size());
    assertTrue(CollectionUtil.containsExactly(Arrays.asList(new String[] { "A/(A1)/T=1388589969000", "A/(A2)/T=1388676369000", "A/(A3)/T=1388762769000", "A/(A4)/T=1388849289000", "A/(A5)/T=1388935689000", "B/(B1)/T=1388849289000" }), databaseVersionHeaderStrings));
    TestSqlUtil.runSql("DELETE FROM fileversion WHERE databaseversion_id = 0", databaseConnection);
    // Tear down
    databaseConnection.close();
    TestConfigUtil.deleteTestLocalConfigAndData(testConfig);
}
Also used : ChunkSqlDao(org.syncany.database.dao.ChunkSqlDao) Arrays(java.util.Arrays) ChunkChecksum(org.syncany.database.ChunkEntry.ChunkChecksum) FileHistorySqlDao(org.syncany.database.dao.FileHistorySqlDao) Connection(java.sql.Connection) Date(java.util.Date) TestDatabaseUtil(org.syncany.tests.util.TestDatabaseUtil) MultiChunkId(org.syncany.database.MultiChunkEntry.MultiChunkId) ChunkEntry(org.syncany.database.ChunkEntry) ArrayList(java.util.ArrayList) FileType(org.syncany.database.FileVersion.FileType) TestConfigUtil(org.syncany.tests.util.TestConfigUtil) FileChecksum(org.syncany.database.FileContent.FileChecksum) MultiChunkSqlDao(org.syncany.database.dao.MultiChunkSqlDao) CollectionUtil(org.syncany.util.CollectionUtil) Map(java.util.Map) FileVersion(org.syncany.database.FileVersion) FileStatus(org.syncany.database.FileVersion.FileStatus) TestSqlUtil(org.syncany.tests.util.TestSqlUtil) DatabaseVersion(org.syncany.database.DatabaseVersion) DatabaseBranch(org.syncany.operations.down.DatabaseBranch) MultiChunkEntry(org.syncany.database.MultiChunkEntry) Iterator(java.util.Iterator) TestCollectionUtil(org.syncany.tests.util.TestCollectionUtil) Assert.assertNotNull(org.junit.Assert.assertNotNull) Collection(java.util.Collection) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Collectors(java.util.stream.Collectors) FileContentSqlDao(org.syncany.database.dao.FileContentSqlDao) FileVersionSqlDao(org.syncany.database.dao.FileVersionSqlDao) List(java.util.List) Config(org.syncany.config.Config) Assert.assertNull(org.junit.Assert.assertNull) FileHistoryId(org.syncany.database.PartialFileHistory.FileHistoryId) DatabaseVersionSqlDao(org.syncany.database.dao.DatabaseVersionSqlDao) PartialFileHistory(org.syncany.database.PartialFileHistory) FileContent(org.syncany.database.FileContent) Assert.assertEquals(org.junit.Assert.assertEquals) DatabaseVersionHeader(org.syncany.database.DatabaseVersionHeader) 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) DatabaseVersionHeader(org.syncany.database.DatabaseVersionHeader) FileHistorySqlDao(org.syncany.database.dao.FileHistorySqlDao) Test(org.junit.Test)

Example 18 with FileVersion

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

the class FileVersionDaoTest method testFileVersionGetCurrentFileTree.

@Test
public void testFileVersionGetCurrentFileTree() throws Exception {
    // Setup
    Config testConfig = TestConfigUtil.createTestLocalConfig();
    Connection databaseConnection = testConfig.createDatabaseConnection();
    // Run
    TestSqlUtil.runSqlFromResource(databaseConnection, "test.insert.set2.sql");
    FileVersionSqlDao fileVersionDao = new FileVersionSqlDao(databaseConnection);
    Map<String, FileVersion> currentFileTree = fileVersionDao.getCurrentFileTree();
    // Test
    assertEquals(50, currentFileTree.size());
    assertNotNull(currentFileTree.get("file1"));
    assertNotNull(currentFileTree.get("file1").getChecksum());
    assertEquals("fe83f217d464f6fdfa5b2b1f87fe3a1a47371196", currentFileTree.get("file1").getChecksum().toString());
    // Tear down
    databaseConnection.close();
    TestConfigUtil.deleteTestLocalConfigAndData(testConfig);
}
Also used : Config(org.syncany.config.Config) FileVersionSqlDao(org.syncany.database.dao.FileVersionSqlDao) FileVersion(org.syncany.database.FileVersion) Connection(java.sql.Connection) Test(org.junit.Test)

Example 19 with FileVersion

use of org.syncany.database.FileVersion 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 20 with FileVersion

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

the class FileSystemActionComparatorTest method createFileVersion.

private FileVersion createFileVersion(String path, FileType type, FileVersion basedOnFileVersion) {
    if (basedOnFileVersion == null) {
        FileVersion fileVersion = new FileVersion();
        fileVersion.setPath(path);
        fileVersion.setType(type);
        fileVersion.setVersion(1L);
        return fileVersion;
    } else {
        FileVersion fileVersion = basedOnFileVersion.clone();
        fileVersion.setPath(path);
        fileVersion.setType(type);
        fileVersion.setVersion(basedOnFileVersion.getVersion() + 1);
        return fileVersion;
    }
}
Also used : FileVersion(org.syncany.database.FileVersion)

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