Search in sources :

Example 11 with FileHistorySqlDao

use of org.syncany.database.dao.FileHistorySqlDao in project syncany by syncany.

the class DatabaseVersionDaoTest method testPersistDatabaseVersion.

@Test
public void testPersistDatabaseVersion() 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. Capture database version header (now)
    DatabaseVersionHeader lastDatabaseVersionHeaderBefore = databaseVersionDao.getLastDatabaseVersionHeader();
    // b. Add new database header (with one file history)
    DatabaseVersion newDatabaseVersion = new DatabaseVersion();
    DatabaseVersionHeader newDatabaseVersionHeader = new DatabaseVersionHeader();
    newDatabaseVersionHeader.setClient("C");
    newDatabaseVersionHeader.setDate(new Date(1489977288000L));
    newDatabaseVersionHeader.setVectorClock(TestDatabaseUtil.createVectorClock("A5,C1"));
    newDatabaseVersion.setHeader(newDatabaseVersionHeader);
    PartialFileHistory newFileHistory = new PartialFileHistory(FileHistoryId.secureRandomFileId());
    FileVersion newFileVersion = new FileVersion();
    newFileVersion.setVersion(1L);
    newFileVersion.setPath("newfile");
    newFileVersion.setChecksum(FileChecksum.parseFileChecksum("aaaaaaaaaaaaaaaaaaaaab2b263ffa4cc48e282f"));
    newFileVersion.setLinkTarget(null);
    newFileVersion.setPosixPermissions("rwxrwxrwx");
    newFileVersion.setDosAttributes(null);
    newFileVersion.setStatus(FileStatus.NEW);
    newFileVersion.setLastModified(new Date());
    newFileVersion.setUpdated(new Date());
    newFileVersion.setSize(1L);
    newFileVersion.setType(FileType.FILE);
    newFileHistory.addFileVersion(newFileVersion);
    newDatabaseVersion.addFileHistory(newFileHistory);
    ChunkEntry newChunkEntry = new ChunkEntry(ChunkChecksum.parseChunkChecksum("aaaaaaaaaaaaaaaaaaaaab2b263ffa4cc48e282f"), 1);
    newDatabaseVersion.addChunk(newChunkEntry);
    MultiChunkEntry newMultiChunkEntry = new MultiChunkEntry(MultiChunkId.parseMultiChunkId("1234567890987654321234567876543456555555"), 10);
    newMultiChunkEntry.addChunk(newChunkEntry.getChecksum());
    newDatabaseVersion.addMultiChunk(newMultiChunkEntry);
    FileContent newFileContent = new FileContent();
    newFileContent.setChecksum(FileChecksum.parseFileChecksum("aaaaaaaaaaaaaaaaaaaaab2b263ffa4cc48e282f"));
    newFileContent.setSize(1L);
    newFileContent.addChunk(newChunkEntry.getChecksum());
    newDatabaseVersion.addFileContent(newFileContent);
    // c. Persist database version
    databaseVersionDao.writeDatabaseVersion(newDatabaseVersion);
    // d. Capture new last database version header
    DatabaseVersionHeader lastDatabaseVersionHeaderAfter = databaseVersionDao.getLastDatabaseVersionHeader();
    // Test
    assertNotNull(lastDatabaseVersionHeaderBefore);
    assertEquals("A/(A5)/T=1388935689000", lastDatabaseVersionHeaderBefore.toString());
    assertNotNull(lastDatabaseVersionHeaderAfter);
    assertEquals("C/(A5,C1)/T=1489977288000", lastDatabaseVersionHeaderAfter.toString());
    assertEquals(newDatabaseVersionHeader.getVectorClock(), lastDatabaseVersionHeaderAfter.getVectorClock());
    assertEquals(newChunkEntry, chunkDao.getChunk(ChunkChecksum.parseChunkChecksum("aaaaaaaaaaaaaaaaaaaaab2b263ffa4cc48e282f")));
    assertEquals(newFileContent, fileContentDao.getFileContent(FileChecksum.parseFileChecksum("aaaaaaaaaaaaaaaaaaaaab2b263ffa4cc48e282f"), true));
    Map<MultiChunkId, MultiChunkEntry> multiChunkIds = multiChunkDao.getMultiChunks(newDatabaseVersionHeader.getVectorClock());
    assertNotNull(multiChunkIds);
    assertEquals(1, multiChunkIds.size());
    MultiChunkEntry actualNewMultiChunkEntry = multiChunkIds.get(MultiChunkId.parseMultiChunkId("1234567890987654321234567876543456555555"));
    assertNotNull(actualNewMultiChunkEntry);
    assertEquals(newMultiChunkEntry.getId(), actualNewMultiChunkEntry.getId());
    // 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) Date(java.util.Date) PartialFileHistory(org.syncany.database.PartialFileHistory) FileContent(org.syncany.database.FileContent) ChunkSqlDao(org.syncany.database.dao.ChunkSqlDao) MultiChunkSqlDao(org.syncany.database.dao.MultiChunkSqlDao) FileVersionSqlDao(org.syncany.database.dao.FileVersionSqlDao) ChunkEntry(org.syncany.database.ChunkEntry) MultiChunkEntry(org.syncany.database.MultiChunkEntry) FileContentSqlDao(org.syncany.database.dao.FileContentSqlDao) FileVersion(org.syncany.database.FileVersion) DatabaseVersionHeader(org.syncany.database.DatabaseVersionHeader) MultiChunkEntry(org.syncany.database.MultiChunkEntry) FileHistorySqlDao(org.syncany.database.dao.FileHistorySqlDao) DatabaseVersion(org.syncany.database.DatabaseVersion) Test(org.junit.Test)

Example 12 with FileHistorySqlDao

use of org.syncany.database.dao.FileHistorySqlDao in project syncany by syncany.

the class DatabaseVersionDaoTest method testGetMaxDirtyVectorClock.

@Test
public void testGetMaxDirtyVectorClock() 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);
    Long maxDirtyVectorClockA = databaseVersionDao.getMaxDirtyVectorClock("A");
    Long maxDirtyVectorClockB = databaseVersionDao.getMaxDirtyVectorClock("B");
    // Test
    assertNull(maxDirtyVectorClockA);
    assertNotNull(maxDirtyVectorClockB);
    assertEquals(1, (long) maxDirtyVectorClockB);
    // 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) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)12 Config (org.syncany.config.Config)12 ChunkSqlDao (org.syncany.database.dao.ChunkSqlDao)12 DatabaseVersionSqlDao (org.syncany.database.dao.DatabaseVersionSqlDao)12 FileContentSqlDao (org.syncany.database.dao.FileContentSqlDao)12 FileHistorySqlDao (org.syncany.database.dao.FileHistorySqlDao)12 FileVersionSqlDao (org.syncany.database.dao.FileVersionSqlDao)12 MultiChunkSqlDao (org.syncany.database.dao.MultiChunkSqlDao)12 Connection (java.sql.Connection)11 DatabaseVersion (org.syncany.database.DatabaseVersion)8 DatabaseVersionHeader (org.syncany.database.DatabaseVersionHeader)4 MultiChunkEntry (org.syncany.database.MultiChunkEntry)4 MultiChunkId (org.syncany.database.MultiChunkEntry.MultiChunkId)4 PartialFileHistory (org.syncany.database.PartialFileHistory)4 DatabaseBranch (org.syncany.operations.down.DatabaseBranch)4 Date (java.util.Date)3 ChunkEntry (org.syncany.database.ChunkEntry)3 FileContent (org.syncany.database.FileContent)3 FileVersion (org.syncany.database.FileVersion)3 ArrayList (java.util.ArrayList)2