use of org.syncany.operations.down.DatabaseBranch in project syncany by syncany.
the class DatabaseVersionDaoTest method testGetLocalDatabaseBranch1.
@Test
public void testGetLocalDatabaseBranch1() 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);
DatabaseBranch localDatabaseBranch = databaseVersionDao.getLocalDatabaseBranch();
// Test
assertNotNull(localDatabaseBranch);
assertEquals(11, localDatabaseBranch.size());
assertEquals(11, localDatabaseBranch.getAll().size());
assertEquals(TestDatabaseUtil.createBranch(new String[] { "A/(A1)/T=1389977166000", "A/(A2)/T=1389977199000", "A/(A3)/T=1389977203000", "A/(A4)/T=1389977207000", "A/(A5)/T=1389977214000", "A/(A6)/T=1389977222000", "B/(A6,B1)/T=1389977233000", "A/(A7,B1)/T=1389977234000", "B/(A7,B2)/T=1389977258000", "B/(A7,B3)/T=1389977264000", "A/(A8,B3)/T=1389977288000" }), localDatabaseBranch);
// Tear down
databaseConnection.close();
TestConfigUtil.deleteTestLocalConfigAndData(testConfig);
}
use of org.syncany.operations.down.DatabaseBranch 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.operations.down.DatabaseBranch 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);
}
}
use of org.syncany.operations.down.DatabaseBranch in project syncany by syncany.
the class TestDatabaseUtil method createBranch.
public static DatabaseBranch createBranch(String[] databaseVersionHeaderStrings) throws Exception {
DatabaseBranch branch = new DatabaseBranch();
for (String databaseVersionHeaderString : databaseVersionHeaderStrings) {
DatabaseVersionHeader databaseVersionHeader = createFromString(databaseVersionHeaderString);
branch.add(databaseVersionHeader);
}
return branch;
}
use of org.syncany.operations.down.DatabaseBranch in project syncany by syncany.
the class DatabaseVersionDaoTest method testGetLocalDatabaseBranch2.
@Test
public void testGetLocalDatabaseBranch2() throws Exception {
// Setup
Config testConfig = TestConfigUtil.createTestLocalConfig();
Connection databaseConnection = testConfig.createDatabaseConnection();
// Run
TestSqlUtil.runSqlFromResource(databaseConnection, "test.insert.set1.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);
DatabaseBranch localDatabaseBranch = databaseVersionDao.getLocalDatabaseBranch();
// Test
assertNotNull(localDatabaseBranch);
assertEquals(5, localDatabaseBranch.size());
assertEquals(5, localDatabaseBranch.getAll().size());
assertEquals(TestDatabaseUtil.createBranch(new String[] { "A/(A1)/T=1388589969000", "A/(A2)/T=1388676369000", // Note: Does NOT contain B1 (because: DIRTY!)
"A/(A3)/T=1388762769000", "A/(A4)/T=1388849289000", "A/(A5)/T=1388935689000" }), localDatabaseBranch);
// Tear down
databaseConnection.close();
TestConfigUtil.deleteTestLocalConfigAndData(testConfig);
}
Aggregations