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