Search in sources :

Example 26 with DatabaseVersionHeader

use of org.syncany.database.DatabaseVersionHeader 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 27 with DatabaseVersionHeader

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

the class DatabaseReconciliatorTest method testUpdateDetectorConflict1AtMachineB.

@Test
public void testUpdateDetectorConflict1AtMachineB() throws Exception {
    System.out.println("CONFLICT 1");
    System.out.println("----------------");
    /// Input data ///
    String localMachineName = "B";
    DatabaseVersionHeader currentLocalVersion = null;
    DatabaseBranches allBranches = new DatabaseBranches();
    // A
    allBranches.put("A", TestDatabaseUtil.createBranch(new String[] { "A/(A1,C4)/T=8", "A/(A2,C4)/T=9", "A/(A3,C4)/T=10" }));
    // B
    allBranches.put("B", TestDatabaseUtil.createBranch(new String[] { "C/(C1)/T=1", "C/(C2)/T=2", "C/(C3)/T=3", "B/(B1,C3)/T=7" }));
    // C
    allBranches.put("C", TestDatabaseUtil.createBranch(new String[] { "C/(C4)/T=5" }));
    /// Expected results ///
    TestResult expectedTestResult = new TestResult();
    expectedTestResult.winnersLastDatabaseVersionHeader = TestDatabaseUtil.createMapWithMachineKey(new String[] { "A", "A/(A3,C4)/T=10" }).firstEntry();
    /// Perform test ///
    testFromMachinePerspective(localMachineName, currentLocalVersion, allBranches, expectedTestResult);
}
Also used : DatabaseVersionHeader(org.syncany.database.DatabaseVersionHeader) DatabaseBranches(org.syncany.operations.down.DatabaseBranches) Test(org.junit.Test)

Example 28 with DatabaseVersionHeader

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

the class DatabaseReconciliatorTest method testOneLocalVersionDetermineLastCommon.

@Test
public void testOneLocalVersionDetermineLastCommon() throws Exception {
    /* Scenario: The local machine ("C") has only one local database version
		 */
    /// Input data ///
    String localMachineName = "C";
    DatabaseVersionHeader currentLocalVersion = TestDatabaseUtil.createFromString("A/(A1)/T=1376074225169");
    DatabaseBranches allBranches = new DatabaseBranches();
    allBranches.put("A", TestDatabaseUtil.createBranch(new String[] { "A/(A1)/T=1376074225169", "A/(A2)/T=1376074225230" }));
    allBranches.put("C", TestDatabaseUtil.createBranch(new String[] { "A/(A1)/T=1376074225169" }));
    /// Expected results ///
    TestResult expectedTestResult = new TestResult();
    expectedTestResult.winnersLastDatabaseVersionHeader = TestDatabaseUtil.createMapWithMachineKey(new String[] { "A", "A/(A2)/T=1376074225230" }).firstEntry();
    /// Perform test ///
    testFromMachinePerspective(localMachineName, currentLocalVersion, allBranches, expectedTestResult);
}
Also used : DatabaseVersionHeader(org.syncany.database.DatabaseVersionHeader) DatabaseBranches(org.syncany.operations.down.DatabaseBranches) Test(org.junit.Test)

Example 29 with DatabaseVersionHeader

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

the class DatabaseReconciliatorTest method testUpdateDetectorConflict3AtMachineC.

@Test
public void testUpdateDetectorConflict3AtMachineC() throws Exception {
    System.out.println("CONFLICT 3");
    System.out.println("----------------");
    /// Input data ///
    String localMachineName = "C";
    DatabaseVersionHeader currentLocalVersion = null;
    DatabaseBranches allBranches = new DatabaseBranches();
    // A
    allBranches.put("A", TestDatabaseUtil.createBranch(new String[] { "A/(A1,C4)/T=8", "A/(A2,C4)/T=9", "A/(A3,C4)/T=10" }));
    // B
    allBranches.put("B", TestDatabaseUtil.createBranch(new String[] { "B/(B1,C3)/T=7" }));
    // C
    allBranches.put("C", TestDatabaseUtil.createBranch(new String[] { "C/(C1)/T=1", "C/(C2)/T=2", "C/(C3)/T=3", "C/(C4)/T=5" }));
    /// Expected results ///x
    TestResult expectedTestResult = new TestResult();
    expectedTestResult.winnersLastDatabaseVersionHeader = TestDatabaseUtil.createMapWithMachineKey(new String[] { "A", "A/(A3,C4)/T=10" }).firstEntry();
    /// Perform test ///
    testFromMachinePerspective(localMachineName, currentLocalVersion, allBranches, expectedTestResult);
}
Also used : DatabaseVersionHeader(org.syncany.database.DatabaseVersionHeader) DatabaseBranches(org.syncany.operations.down.DatabaseBranches) Test(org.junit.Test)

Example 30 with DatabaseVersionHeader

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

the class DatabaseReconciliatorTest method testStitchBranchesIssue226ConflictingVCsInOneBranch.

@Test
public void testStitchBranchesIssue226ConflictingVCsInOneBranch() throws Exception {
    Logging.init();
    /// Input data ///
    String localMachineName = "ZA";
    DatabaseVersionHeader currentLocalVersion = null;
    DatabaseBranches allBranches = new DatabaseBranches();
    // ZA
    allBranches.put("ZA", TestDatabaseUtil.createBranch(new String[] { /*	"WG/(WG2)/T=1417598306794",
					"jR/(WG2,jR1)/T=1417598308654",
					"WG/(WG3,jR1)/T=1417598309554",
					"oq/(WG3,jR1,oq2)/T=1417598310488",
					"WG/(WG4,jR1,oq2)/T=1417598311995",
					"oq/(WG4,jR1,oq3)/T=1417598313779",
					"jR/(WG4,jR2,oq3)/T=1417598314162",*/
    "ZA/(WG4,ZA1,jR2,oq3)/T=1417598314796", "ZA/(WG4,ZA2,jR2,oq3)/T=1417598316388" }));
    // WG
    allBranches.put("WG", TestDatabaseUtil.createBranch(new String[] { "WG/(WG5,ZA2,jR2,oq3)/T=1417598319102", "WG/(WG6,ZA2,jR5,oq4)/T=1417598321850" }));
    // jR
    allBranches.put("jR", TestDatabaseUtil.createBranch(new String[] { "jR/(WG5,ZA2,jR4,oq3)/T=1417598319954", "jR/(WG5,ZA2,jR5,oq4)/T=1417598320743" }));
    // oq
    allBranches.put("oq", TestDatabaseUtil.createBranch(new String[] { "oq/(WG5,ZA2,jR2,oq4)/T=1417598319900" }));
    /// Expected results ///
    TestResult expectedTestResult = new TestResult();
    expectedTestResult.winnersLastDatabaseVersionHeader = TestDatabaseUtil.createMapWithMachineKey(new String[] { "WG", "WG/(WG6,ZA2,jR5,oq4)/T=1417598321850" }).firstEntry();
    /// Perform test ///
    testFromMachinePerspective(localMachineName, currentLocalVersion, allBranches, expectedTestResult);
}
Also used : DatabaseVersionHeader(org.syncany.database.DatabaseVersionHeader) DatabaseBranches(org.syncany.operations.down.DatabaseBranches) Test(org.junit.Test)

Aggregations

DatabaseVersionHeader (org.syncany.database.DatabaseVersionHeader)33 Test (org.junit.Test)17 DatabaseBranches (org.syncany.operations.down.DatabaseBranches)14 File (java.io.File)4 Date (java.util.Date)4 VectorClock (org.syncany.database.VectorClock)4 PreparedStatement (java.sql.PreparedStatement)3 DatabaseVersion (org.syncany.database.DatabaseVersion)3 MultiChunkEntry (org.syncany.database.MultiChunkEntry)3 DatabaseBranch (org.syncany.operations.down.DatabaseBranch)3 DatabaseRemoteFile (org.syncany.plugins.transfer.files.DatabaseRemoteFile)3 IOException (java.io.IOException)2 Connection (java.sql.Connection)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Config (org.syncany.config.Config)2 ChunkEntry (org.syncany.database.ChunkEntry)2 FileContent (org.syncany.database.FileContent)2 MemoryDatabase (org.syncany.database.MemoryDatabase)2 MultiChunkId (org.syncany.database.MultiChunkEntry.MultiChunkId)2