Search in sources :

Example 1 with DatabaseBranches

use of org.syncany.operations.down.DatabaseBranches 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 2 with DatabaseBranches

use of org.syncany.operations.down.DatabaseBranches 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 3 with DatabaseBranches

use of org.syncany.operations.down.DatabaseBranches 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 4 with DatabaseBranches

use of org.syncany.operations.down.DatabaseBranches 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 5 with DatabaseBranches

use of org.syncany.operations.down.DatabaseBranches 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" // "A/(A2,C4)/T=9",     // new from here -> first conflicting, wins
    // 
    // "A/(A3,C4)/T=10",    // same as in A
    // "B/(A4,B1,C4)/T=12", // second conflict, loses = winners loser
    // "B/(A4,B2,C4)/T=15"
    }));
    // / 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)

Aggregations

DatabaseVersionHeader (org.syncany.database.DatabaseVersionHeader)14 DatabaseBranches (org.syncany.operations.down.DatabaseBranches)14 Test (org.junit.Test)13 AbstractMap (java.util.AbstractMap)1 DatabaseBranch (org.syncany.operations.down.DatabaseBranch)1 DatabaseReconciliator (org.syncany.operations.down.DatabaseReconciliator)1