Search in sources :

Example 1 with DatabaseBranch

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);
}
Also used : ChunkSqlDao(org.syncany.database.dao.ChunkSqlDao) MultiChunkSqlDao(org.syncany.database.dao.MultiChunkSqlDao) Config(org.syncany.config.Config) FileVersionSqlDao(org.syncany.database.dao.FileVersionSqlDao) FileContentSqlDao(org.syncany.database.dao.FileContentSqlDao) Connection(java.sql.Connection) DatabaseVersionSqlDao(org.syncany.database.dao.DatabaseVersionSqlDao) MultiChunkSqlDao(org.syncany.database.dao.MultiChunkSqlDao) DatabaseBranch(org.syncany.operations.down.DatabaseBranch) FileHistorySqlDao(org.syncany.database.dao.FileHistorySqlDao) Test(org.junit.Test)

Example 2 with DatabaseBranch

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);
}
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 3 with DatabaseBranch

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

Example 4 with DatabaseBranch

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;
}
Also used : DatabaseBranch(org.syncany.operations.down.DatabaseBranch) DatabaseVersionHeader(org.syncany.database.DatabaseVersionHeader)

Example 5 with DatabaseBranch

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);
}
Also used : ChunkSqlDao(org.syncany.database.dao.ChunkSqlDao) MultiChunkSqlDao(org.syncany.database.dao.MultiChunkSqlDao) Config(org.syncany.config.Config) FileVersionSqlDao(org.syncany.database.dao.FileVersionSqlDao) FileContentSqlDao(org.syncany.database.dao.FileContentSqlDao) Connection(java.sql.Connection) DatabaseVersionSqlDao(org.syncany.database.dao.DatabaseVersionSqlDao) MultiChunkSqlDao(org.syncany.database.dao.MultiChunkSqlDao) DatabaseBranch(org.syncany.operations.down.DatabaseBranch) FileHistorySqlDao(org.syncany.database.dao.FileHistorySqlDao) Test(org.junit.Test)

Aggregations

DatabaseBranch (org.syncany.operations.down.DatabaseBranch)5 DatabaseVersionHeader (org.syncany.database.DatabaseVersionHeader)3 Connection (java.sql.Connection)2 Test (org.junit.Test)2 Config (org.syncany.config.Config)2 ChunkSqlDao (org.syncany.database.dao.ChunkSqlDao)2 DatabaseVersionSqlDao (org.syncany.database.dao.DatabaseVersionSqlDao)2 FileContentSqlDao (org.syncany.database.dao.FileContentSqlDao)2 FileHistorySqlDao (org.syncany.database.dao.FileHistorySqlDao)2 FileVersionSqlDao (org.syncany.database.dao.FileVersionSqlDao)2 MultiChunkSqlDao (org.syncany.database.dao.MultiChunkSqlDao)2 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 AbstractMap (java.util.AbstractMap)1 Date (java.util.Date)1 DatabaseBranches (org.syncany.operations.down.DatabaseBranches)1 DatabaseReconciliator (org.syncany.operations.down.DatabaseReconciliator)1