Search in sources :

Example 6 with MultiChunkSqlDao

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

the class MultiChunkDaoTest method testGetMultiChunksByDatabaseVersion1.

@Test
public void testGetMultiChunksByDatabaseVersion1() throws Exception {
    // Setup
    Config testConfig = TestConfigUtil.createTestLocalConfig();
    Connection databaseConnection = testConfig.createDatabaseConnection();
    // Run
    TestSqlUtil.runSqlFromResource(databaseConnection, "test.insert.set3.sql");
    MultiChunkSqlDao multiChunkDao = new MultiChunkSqlDao(databaseConnection);
    Map<MultiChunkId, MultiChunkEntry> multiChunksA6 = multiChunkDao.getMultiChunks(TestDatabaseUtil.createVectorClock("A6"));
    Map<MultiChunkId, MultiChunkEntry> multiChunksA7B2 = multiChunkDao.getMultiChunks(TestDatabaseUtil.createVectorClock("A7,B2"));
    // Test
    // - Database version "A6"
    assertNotNull(multiChunksA6);
    assertEquals(1, multiChunksA6.size());
    MultiChunkEntry multiChunkInA6 = multiChunksA6.get(MultiChunkId.parseMultiChunkId("9302d8b104023627f655fa7745927fdeb3df674b"));
    assertNotNull(multiChunkInA6);
    assertEquals("9302d8b104023627f655fa7745927fdeb3df674b", multiChunkInA6.getId().toString());
    assertTrue(CollectionUtil.containsExactly(multiChunkInA6.getChunks(), ChunkChecksum.parseChunkChecksum("24a39e00d6156804e27f7c0987d00903da8e6682")));
    // - Database version "A8,B3"		
    assertNotNull(multiChunksA7B2);
    assertEquals(1, multiChunksA7B2.size());
    MultiChunkEntry multiChunkInA7B2 = multiChunksA7B2.get(MultiChunkId.parseMultiChunkId("51aaca5c1280b1cf95cff8a3266a6bb44b482ad4"));
    assertEquals("51aaca5c1280b1cf95cff8a3266a6bb44b482ad4", multiChunkInA7B2.getId().toString());
    assertTrue(CollectionUtil.containsExactly(multiChunkInA7B2.getChunks(), ChunkChecksum.parseChunkChecksum("0fecbac8ac8a5f8b7aa12b2741a4ef5db88c5dea"), ChunkChecksum.parseChunkChecksum("38a18897e94a901b833e750e8604d9616a02ca84"), ChunkChecksum.parseChunkChecksum("47dded182d31799267f12eb9864cdc11127b3352"), ChunkChecksum.parseChunkChecksum("5abe80d7dd96369a3e53993cd69279400ec740bd"), ChunkChecksum.parseChunkChecksum("5f0b34374821423f69bf2231210245ccf0302df0"), ChunkChecksum.parseChunkChecksum("615fba8c2281d5bee891eb092a252d235c237457"), ChunkChecksum.parseChunkChecksum("8ed8d50a6e9da3197bd665bc3a1f229ebcde9b42"), ChunkChecksum.parseChunkChecksum("9974b55a79994b4bfe007983539ca21b2679ba35"), ChunkChecksum.parseChunkChecksum("a301a81d5a4f427d04791b89bfd7798eda6bd013"), ChunkChecksum.parseChunkChecksum("a7405a0bada0035ed52a1a44a4d381b78dc59d19"), ChunkChecksum.parseChunkChecksum("ab85720d3f31bd08ca1cd25dcd8a490e5f00783b"), ChunkChecksum.parseChunkChecksum("b0223d9770a5c0d7e22ac3d2706c4c9858cf42a9"), ChunkChecksum.parseChunkChecksum("b310c0eedcd03238888c6abb3e3398633139ecc5"), ChunkChecksum.parseChunkChecksum("f15eace568ea3c324ecd3d01b67e692bbf8a2f1b")));
    // Tear down
    databaseConnection.close();
    TestConfigUtil.deleteTestLocalConfigAndData(testConfig);
}
Also used : MultiChunkId(org.syncany.database.MultiChunkEntry.MultiChunkId) Config(org.syncany.config.Config) Connection(java.sql.Connection) MultiChunkSqlDao(org.syncany.database.dao.MultiChunkSqlDao) MultiChunkEntry(org.syncany.database.MultiChunkEntry) Test(org.junit.Test)

Example 7 with MultiChunkSqlDao

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

the class MultiChunkDaoTest method testGetMultiChunkId.

@Test
public void testGetMultiChunkId() throws Exception {
    // Setup
    Config testConfig = TestConfigUtil.createTestLocalConfig();
    Connection databaseConnection = testConfig.createDatabaseConnection();
    // Run
    TestSqlUtil.runSqlFromResource(databaseConnection, "test.insert.set3.sql");
    MultiChunkSqlDao multiChunkDao = new MultiChunkSqlDao(databaseConnection);
    MultiChunkId multiChunkId1 = multiChunkDao.getMultiChunkId(ChunkChecksum.parseChunkChecksum("eba69a8e359ce3258520138a50ed9860127ab6e0"));
    MultiChunkId multiChunkId2 = multiChunkDao.getMultiChunkId(ChunkChecksum.parseChunkChecksum("0fecbac8ac8a5f8b7aa12b2741a4ef5db88c5dea"));
    MultiChunkId multiChunkId3 = multiChunkDao.getMultiChunkId(ChunkChecksum.parseChunkChecksum("38a18897e94a901b833e750e8604d9616a02ca84"));
    MultiChunkId multiChunkIdNonExistent = multiChunkDao.getMultiChunkId(ChunkChecksum.parseChunkChecksum("beefbeefbeefbeefbeefbeefbeefbeefbeefbeef"));
    // Test
    assertNotNull(multiChunkId1);
    assertEquals("0d79eed3fd8ac866b5872ea3f3f079c46dd15ac9", multiChunkId1.toString());
    assertNotNull(multiChunkId2);
    assertEquals("51aaca5c1280b1cf95cff8a3266a6bb44b482ad4", multiChunkId2.toString());
    assertNotNull(multiChunkId3);
    assertEquals("51aaca5c1280b1cf95cff8a3266a6bb44b482ad4", multiChunkId3.toString());
    assertEquals(multiChunkId2, multiChunkId3);
    assertNull(multiChunkIdNonExistent);
    // Tear down
    databaseConnection.close();
    TestConfigUtil.deleteTestLocalConfigAndData(testConfig);
}
Also used : MultiChunkId(org.syncany.database.MultiChunkEntry.MultiChunkId) Config(org.syncany.config.Config) Connection(java.sql.Connection) MultiChunkSqlDao(org.syncany.database.dao.MultiChunkSqlDao) Test(org.junit.Test)

Example 8 with MultiChunkSqlDao

use of org.syncany.database.dao.MultiChunkSqlDao 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 9 with MultiChunkSqlDao

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

the class DatabaseVersionDaoTest method testGetLocalDatabaseBranch2.

@Test
public void testGetLocalDatabaseBranch2() 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);
    DatabaseBranch localDatabaseBranch = databaseVersionDao.getLocalDatabaseBranch();
    // Test
    assertNotNull(localDatabaseBranch);
    assertEquals(5, localDatabaseBranch.size());
    assertEquals(5, localDatabaseBranch.getAll().size());
    assertEquals(TestDatabaseUtil.createBranch(new String[] { "A/(A1)/T=1388589969000", "A/(A2)/T=1388676369000", // Note: Does NOT contain B1 (because: DIRTY!)
    "A/(A3)/T=1388762769000", "A/(A4)/T=1388849289000", "A/(A5)/T=1388935689000" }), localDatabaseBranch);
    // 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) DatabaseBranch(org.syncany.operations.down.DatabaseBranch) FileHistorySqlDao(org.syncany.database.dao.FileHistorySqlDao) Test(org.junit.Test)

Example 10 with MultiChunkSqlDao

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

the class DatabaseVersionDaoTest method testGetDatabaseVersionsTo.

@Test
public void testGetDatabaseVersionsTo() 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);
    Iterator<DatabaseVersion> databaseVersionsToA2 = databaseVersionDao.getDatabaseVersionsTo("A", 2);
    Iterator<DatabaseVersion> databaseVersionsToA5 = databaseVersionDao.getDatabaseVersionsTo("A", 5);
    // B1 is DIRTY !
    Iterator<DatabaseVersion> databaseVersionsToB1 = databaseVersionDao.getDatabaseVersionsTo("B", 1);
    List<DatabaseVersion> databaseVersionsToA2List = TestCollectionUtil.toList(databaseVersionsToA2);
    List<DatabaseVersion> databaseVersionsToA5List = TestCollectionUtil.toList(databaseVersionsToA5);
    List<DatabaseVersion> databaseVersionsToB1List = TestCollectionUtil.toList(databaseVersionsToB1);
    // Test
    assertNotNull(databaseVersionsToA2);
    assertEquals(2, databaseVersionsToA2List.size());
    assertEquals("(A1)", databaseVersionsToA2List.get(0).getHeader().getVectorClock().toString());
    assertEquals("(A2)", databaseVersionsToA2List.get(1).getHeader().getVectorClock().toString());
    assertNotNull(databaseVersionsToA5);
    assertEquals(5, databaseVersionsToA5List.size());
    assertEquals("(A1)", databaseVersionsToA5List.get(0).getHeader().getVectorClock().toString());
    assertEquals("(A2)", databaseVersionsToA5List.get(1).getHeader().getVectorClock().toString());
    assertEquals("(A3)", databaseVersionsToA5List.get(2).getHeader().getVectorClock().toString());
    assertEquals("(A4)", databaseVersionsToA5List.get(3).getHeader().getVectorClock().toString());
    assertEquals("(A5)", databaseVersionsToA5List.get(4).getHeader().getVectorClock().toString());
    assertNotNull(databaseVersionsToB1);
    assertEquals(0, databaseVersionsToB1List.size());
    // 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) DatabaseVersion(org.syncany.database.DatabaseVersion) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)16 Config (org.syncany.config.Config)16 MultiChunkSqlDao (org.syncany.database.dao.MultiChunkSqlDao)16 Connection (java.sql.Connection)15 ChunkSqlDao (org.syncany.database.dao.ChunkSqlDao)10 DatabaseVersionSqlDao (org.syncany.database.dao.DatabaseVersionSqlDao)10 FileContentSqlDao (org.syncany.database.dao.FileContentSqlDao)10 FileHistorySqlDao (org.syncany.database.dao.FileHistorySqlDao)10 FileVersionSqlDao (org.syncany.database.dao.FileVersionSqlDao)10 MultiChunkId (org.syncany.database.MultiChunkEntry.MultiChunkId)8 DatabaseVersion (org.syncany.database.DatabaseVersion)6 MultiChunkEntry (org.syncany.database.MultiChunkEntry)4 DatabaseVersionHeader (org.syncany.database.DatabaseVersionHeader)2 PartialFileHistory (org.syncany.database.PartialFileHistory)2 DatabaseBranch (org.syncany.operations.down.DatabaseBranch)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 ChunkEntry (org.syncany.database.ChunkEntry)1 ChunkChecksum (org.syncany.database.ChunkEntry.ChunkChecksum)1 FileContent (org.syncany.database.FileContent)1