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);
}
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);
}
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);
}
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);
}
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);
}
}
Aggregations