Search in sources :

Example 11 with DatabaseVersionHeader

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

the class DatabaseReconciliatorTest method testWinnersWinner.

@Test
public void testWinnersWinner() throws Exception {
    Logging.init();
    System.out.println("Winners winner test");
    System.out.println("----------------");
    /// Input data ///
    String localMachineName = "B";
    DatabaseVersionHeader currentLocalVersion = TestDatabaseUtil.createFromString("A/(A1,C4)/T=8");
    DatabaseBranches allBranches = new DatabaseBranches();
    // A
    allBranches.put("A", TestDatabaseUtil.createBranch(new String[] { // last common
    "A/(A1,C4)/T=8", // first conflicting, wins
    "A/(A2,C4)/T=9", // same as in B
    "A/(A3,C4)/T=10", // second conflict, wins, winners winner
    "A/(A4,C4)/T=11", // <<---- WINNERS WINNERS LAST DBV
    "A/(A5,C4)/T=15" }));
    // B
    allBranches.put("B", TestDatabaseUtil.createBranch(new String[] { // second conflict, loses = winners loser
    "B/(A3,B1,C4)/T=12", "B/(A3,B2,C4)/T=14" }));
    // C
    allBranches.put("C", TestDatabaseUtil.createBranch(new String[] { "C/(C1)/T=1", "C/(C2)/T=2", "C/(C3)/T=3", "C/(C4)/T=4", // first conflicting, loses
    "C/(A1,C5)/T=10" }));
    /// Expected results ///
    TestResult expectedTestResult = new TestResult();
    expectedTestResult.winnersLastDatabaseVersionHeader = TestDatabaseUtil.createMapWithMachineKey(new String[] { "A", "A/(A5,C4)/T=15" }).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 12 with DatabaseVersionHeader

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

the class DatabaseReconciliatorTest method testWinningBranch.

@Test
public void testWinningBranch() throws Exception {
    System.out.println("Winners winner test");
    System.out.println("----------------");
    /// Input data ///
    String localMachineName = "D";
    DatabaseVersionHeader currentLocalVersion = TestDatabaseUtil.createFromString("A/(A1,C4)/T=8");
    DatabaseBranches allBranches = new DatabaseBranches();
    // A
    allBranches.put("A", TestDatabaseUtil.createBranch(new String[] { // first conflicting, wins
    "A/(A2,C4)/T=9", // same as in B
    "A/(A3,C4)/T=10", // second conflict, wins, winners winner
    "A/(A4,C4)/T=11", // <<---- WINNERS WINNERS LAST DBV
    "A/(A5,B1,C4)/T=14" }));
    // B
    allBranches.put("B", TestDatabaseUtil.createBranch(new String[] { // second conflict, loses = winners loser
    "B/(A4,B1,C4)/T=12", "B/(A4,B2,C4)/T=15" }));
    // C
    allBranches.put("C", TestDatabaseUtil.createBranch(new String[] { // first conflicting, loses
    "C/(A1,C5)/T=10" }));
    allBranches.put("D", TestDatabaseUtil.createBranch(new String[] { "C/(C1)/T=1", "C/(C2)/T=2", "C/(C3)/T=3", "C/(C4)/T=4", // last common - current DBV in B!
    "A/(A1,C4)/T=8" }));
    /// Expected results ///
    TestResult expectedTestResult = new TestResult();
    expectedTestResult.winnersLastDatabaseVersionHeader = TestDatabaseUtil.createMapWithMachineKey(new String[] { "A", "A/(A5,B1,C4)/T=14" }).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 13 with DatabaseVersionHeader

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

the class DatabaseReconciliatorTest method testUpdateDetectorConflict5AtMachineA.

@Test
public void testUpdateDetectorConflict5AtMachineA() throws Exception {
    System.out.println("CONFLICT 5");
    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", "A/(A4,C4)/T=11", "A/(A5,C4)/T=12", "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[] { // db-c-5
    "C/(A3,C5)/T=13", "C/(A3,C6)/T=14", // db-c-7
    "C/(A3,C7)/T=15", // db-c-8
    "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)

Example 14 with DatabaseVersionHeader

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

the class DatabaseReconciliatorTest method testUpdateDetectorConflict4AtMachineB.

@Test
public void testUpdateDetectorConflict4AtMachineB() throws Exception {
    System.out.println("CONFLICT 4");
    System.out.println("----------------");
    /// Input data ///
    String localMachineName = "B";
    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[] { "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/(A3,B2,C4)/T=16", "B/(A3,B3,C4)/T=17", "B/(A3,B4,C4)/T=18", "B/(A3,B5,C4)/T=20" }));
    // C
    allBranches.put("C", TestDatabaseUtil.createBranch(new String[] { // db-c-5
    "C/(A3,C5)/T=13", "C/(A3,C6)/T=14", // db-c-7
    "C/(A3,C7)/T=15", // db-c-8
    "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)

Example 15 with DatabaseVersionHeader

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

the class DatabaseVersionSqlDao method getLocalDatabaseBranch.

public DatabaseBranch getLocalDatabaseBranch() {
    DatabaseBranch databaseBranch = new DatabaseBranch();
    try (PreparedStatement preparedStatement = getStatement("databaseversion.select.master.getLocalDatabaseBranch.sql")) {
        try (ResultSet resultSet = preparedStatement.executeQuery()) {
            DatabaseVersionHeader currentDatabaseVersionHeader = null;
            int currentDatabaseVersionHeaderId = -1;
            while (resultSet.next()) {
                int databaseVersionHeaderId = resultSet.getInt("id");
                // Row does NOT belong to the current database version
                if (currentDatabaseVersionHeader == null || currentDatabaseVersionHeaderId != databaseVersionHeaderId) {
                    // Add to database branch
                    if (currentDatabaseVersionHeader != null) {
                        databaseBranch.add(currentDatabaseVersionHeader);
                    }
                    // Make a new database version header
                    currentDatabaseVersionHeader = new DatabaseVersionHeader();
                    currentDatabaseVersionHeader.setClient(resultSet.getString("client"));
                    currentDatabaseVersionHeader.setDate(new Date(resultSet.getTimestamp("localtime").getTime()));
                    currentDatabaseVersionHeaderId = databaseVersionHeaderId;
                }
                currentDatabaseVersionHeader.getVectorClock().setClock(resultSet.getString("vc_client"), resultSet.getLong("vc_logicaltime"));
            }
            // Add to database branch
            if (currentDatabaseVersionHeader != null) {
                databaseBranch.add(currentDatabaseVersionHeader);
            }
            return databaseBranch;
        }
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DatabaseBranch(org.syncany.operations.down.DatabaseBranch) DatabaseVersionHeader(org.syncany.database.DatabaseVersionHeader) Date(java.util.Date)

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