Search in sources :

Example 6 with DatabaseVersionHeader

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

the class DatabaseVersionDaoTest method testGetLastDatabaseVersionHeader1.

@Test
public void testGetLastDatabaseVersionHeader1() throws Exception {
    // Setup
    Config testConfig = TestConfigUtil.createTestLocalConfig();
    Connection databaseConnection = testConfig.createDatabaseConnection();
    // Run
    TestSqlUtil.runSqlFromResource(databaseConnection, "test.insert.set3.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);
    DatabaseVersionHeader lastDatabaseVersionHeader = databaseVersionDao.getLastDatabaseVersionHeader();
    // Test
    assertNotNull(lastDatabaseVersionHeader);
    assertEquals("(A8,B3)", lastDatabaseVersionHeader.getVectorClock().toString());
    assertEquals("A/(A8,B3)/T=1389977288000", lastDatabaseVersionHeader.toString());
    // 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) DatabaseVersionHeader(org.syncany.database.DatabaseVersionHeader) FileHistorySqlDao(org.syncany.database.dao.FileHistorySqlDao) Test(org.junit.Test)

Example 7 with DatabaseVersionHeader

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

the class UpOperation method findNewVectorClock.

/**
	 * Finds the next vector clock
	 *
	 * <p>There are two causes for not having a previous vector clock:
	 * <ul>
	 *   <li>This is the initial version
	 *   <li>A cleanup has wiped *all* database versions
	 * </ul>
	 *
	 * In the latter case, the method looks at the previous database version numbers
	 * to determine a new vector clock
	 */
private VectorClock findNewVectorClock() {
    // Get last vector clock
    DatabaseVersionHeader lastDatabaseVersionHeader = localDatabase.getLastDatabaseVersionHeader();
    VectorClock lastVectorClock = (lastDatabaseVersionHeader != null) ? lastDatabaseVersionHeader.getVectorClock() : new VectorClock();
    logger.log(Level.INFO, "Last vector clock was: " + lastVectorClock);
    boolean noPreviousVectorClock = lastVectorClock.isEmpty();
    if (noPreviousVectorClock) {
        lastVectorClock = localDatabase.getHighestKnownDatabaseFilenameNumbers();
    }
    VectorClock newVectorClock = lastVectorClock.clone();
    Long lastLocalValue = lastVectorClock.getClock(config.getMachineName());
    Long lastDirtyLocalValue = localDatabase.getMaxDirtyVectorClock(config.getMachineName());
    Long newLocalValue = null;
    if (lastDirtyLocalValue != null) {
        newLocalValue = lastDirtyLocalValue + 1;
    } else {
        if (lastLocalValue != null) {
            newLocalValue = lastLocalValue + 1;
        } else {
            newLocalValue = 1L;
        }
    }
    newVectorClock.setClock(config.getMachineName(), newLocalValue);
    return newVectorClock;
}
Also used : VectorClock(org.syncany.database.VectorClock) DatabaseVersionHeader(org.syncany.database.DatabaseVersionHeader)

Example 8 with DatabaseVersionHeader

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

the class DatabaseReconciliatorTest method testUpdateDetectorConflict2AtMachineA.

@Test
public void testUpdateDetectorConflict2AtMachineA() throws Exception {
    System.out.println("CONFLICT 2");
    System.out.println("----------------");
    /// Input data ///
    String localMachineName = "A";
    DatabaseVersionHeader currentLocalVersion = null;
    DatabaseBranches allBranches = new DatabaseBranches();
    // A
    allBranches.put("A", TestDatabaseUtil.createBranch(new String[] { "C/(C1)/T=1", "C/(C2)/T=2", "C/(C3)/T=3", "C/(C4)/T=5", "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" }));
    /// 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 9 with DatabaseVersionHeader

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

the class DatabaseReconciliatorTest method testFromMachinePerspective.

private void testFromMachinePerspective(String localMachineName, DatabaseVersionHeader currentLocalVersion, DatabaseBranches allBranches, TestResult expectedTestResult) throws Exception {
    // Print them all
    System.out.println("testFromMachinePerspective('" + localMachineName + "') with database version headers:");
    printBranches(allBranches);
    System.out.println("----------");
    DatabaseReconciliator databaseReconciliator = new DatabaseReconciliator();
    TestResult actualTestResult = new TestResult();
    // Get 'local' branch
    DatabaseBranch localBranch = allBranches.getBranch(localMachineName);
    // Get all the other ones (clone 'all', and remove local)
    DatabaseBranches unstitchedRemoteBranches = allBranches.clone();
    unstitchedRemoteBranches.remove(localMachineName);
    System.out.println("Unstitched Branches (from remote):");
    System.out.println("##################################");
    printBranches(unstitchedRemoteBranches);
    System.out.println();
    System.out.println("Unstitched Local Branch (client '" + localMachineName + "'):");
    System.out.println("##################################");
    printBranch(localBranch);
    System.out.println();
    Entry<String, DatabaseBranch> winnersBranch = databaseReconciliator.findWinnerBranch(allBranches);
    System.out.println("Winners Branch (winner is " + winnersBranch.getKey() + "):");
    System.out.println("##################################");
    printBranch(winnersBranch.getValue());
    System.out.println();
    actualTestResult.winnersLastDatabaseVersionHeader = new AbstractMap.SimpleEntry<String, DatabaseVersionHeader>(winnersBranch.getKey(), winnersBranch.getValue().getLast());
    System.out.println("Actual winnersLastDatabaseVersionHeader = " + actualTestResult.winnersLastDatabaseVersionHeader);
    System.out.println("Expect winnersLastDatabaseVersionHeader = " + expectedTestResult.winnersLastDatabaseVersionHeader);
    assertEquals("Different winners winners last version expected", expectedTestResult.winnersLastDatabaseVersionHeader, actualTestResult.winnersLastDatabaseVersionHeader);
}
Also used : AbstractMap(java.util.AbstractMap) DatabaseReconciliator(org.syncany.operations.down.DatabaseReconciliator) DatabaseBranch(org.syncany.operations.down.DatabaseBranch) DatabaseVersionHeader(org.syncany.database.DatabaseVersionHeader) DatabaseBranches(org.syncany.operations.down.DatabaseBranches)

Example 10 with DatabaseVersionHeader

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

the class DatabaseReconciliatorTest method testUpdateDetectorConflict6AtMachineC.

@Test
public void testUpdateDetectorConflict6AtMachineC() throws Exception {
    System.out.println("CONFLICT 6");
    System.out.println("----------------");
    /// Input data ///
    String localMachineName = "C";
    DatabaseVersionHeader currentLocalVersion = null;
    DatabaseBranches allBranches = new DatabaseBranches();
    // A
    allBranches.put("A", TestDatabaseUtil.createBranch(new String[] { "A/(A4,C4)/T=11", // db-a-5
    "A/(A5,C4)/T=12", // db-a-6
    "A/(A6,C4)/T=19" }));
    // B
    allBranches.put("B", TestDatabaseUtil.createBranch(new String[] { "B/(A3,B2,C4)/T=16", "B/(A3,B3,C4)/T=17", // db-b-4
    "B/(A3,B4,C4)/T=18", // db-b-5
    "B/(A3,B5,C4)/T=20" }));
    // C
    allBranches.put("C", TestDatabaseUtil.createBranch(new String[] { "C/(C1)/T=1", "C/(C2)/T=2", "C/(C3)/T=3", "C/(C4)/T=5", "A/(A1,C4)/T=8", "A/(A2,C4)/T=9", "A/(A3,C4)/T=10", "C/(A3,C5)/T=13", "C/(A3,C6)/T=14", "C/(A3,C7)/T=15", "C/(A3,C8)/T=21" }));
    /// Expected results ///
    TestResult expectedTestResult = new TestResult();
    expectedTestResult.winnersLastDatabaseVersionHeader = TestDatabaseUtil.createMapWithMachineKey(new String[] { "A", "A/(A6,C4)/T=19" }).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