Search in sources :

Example 11 with FileContentSqlDao

use of org.syncany.database.dao.FileContentSqlDao in project syncany by syncany.

the class DatabaseVersionDaoTest method testGetMaxDirtyVectorClock.

@Test
public void testGetMaxDirtyVectorClock() 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);
    Long maxDirtyVectorClockA = databaseVersionDao.getMaxDirtyVectorClock("A");
    Long maxDirtyVectorClockB = databaseVersionDao.getMaxDirtyVectorClock("B");
    // Test
    assertNull(maxDirtyVectorClockA);
    assertNotNull(maxDirtyVectorClockB);
    assertEquals(1, (long) maxDirtyVectorClockB);
    // 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) FileHistorySqlDao(org.syncany.database.dao.FileHistorySqlDao) Test(org.junit.Test)

Example 12 with FileContentSqlDao

use of org.syncany.database.dao.FileContentSqlDao in project syncany by syncany.

the class DirtyDatabaseScenarioTest method testDirtyDatabase.

@Test
public void testDirtyDatabase() throws Exception {
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    // Run
    UpOperationOptions upOptionsForceEnabled = new UpOperationOptions();
    upOptionsForceEnabled.setForceUploadEnabled(true);
    clientA.createNewFile("A-file1.jpg", 50 * 1024);
    clientA.up(upOptionsForceEnabled);
    clientB.createNewFile("A-file1.jpg", 51 * 1024);
    clientB.up(upOptionsForceEnabled);
    // This creates a dirty database
    clientB.down();
    // Test (for dirty database existence)
    Config configB = clientB.getConfig();
    java.sql.Connection databaseConnectionB = configB.createDatabaseConnection();
    ChunkSqlDao chunkDao = new ChunkSqlDao(databaseConnectionB);
    MultiChunkSqlDao multiChunkDao = new MultiChunkSqlDao(databaseConnectionB);
    FileVersionSqlDao fileVersionDao = new FileVersionSqlDao(databaseConnectionB);
    FileHistorySqlDao fileHistoryDao = new FileHistorySqlDao(databaseConnectionB, fileVersionDao);
    FileContentSqlDao fileContentDao = new FileContentSqlDao(databaseConnectionB);
    DatabaseVersionSqlDao databaseVersionDao = new DatabaseVersionSqlDao(databaseConnectionB, chunkDao, fileContentDao, fileVersionDao, fileHistoryDao, multiChunkDao);
    Iterator<DatabaseVersion> databaseVersionsDirtyB = databaseVersionDao.getDirtyDatabaseVersions();
    List<DatabaseVersion> databaseVersionsDirtyListB = TestCollectionUtil.toList(databaseVersionsDirtyB);
    assertEquals(1, databaseVersionsDirtyListB.size());
    DatabaseVersion dirtyDatabaseVersionB = databaseVersionsDirtyListB.get(0);
    assertNotNull(dirtyDatabaseVersionB);
    assertEquals(1, dirtyDatabaseVersionB.getFileHistories().size());
    PartialFileHistory fileHistoryFile1B = dirtyDatabaseVersionB.getFileHistories().iterator().next();
    assertNotNull(fileHistoryFile1B);
    assertEquals(1, fileHistoryFile1B.getFileVersions().size());
    assertEquals("A-file1.jpg", fileHistoryFile1B.getLastVersion().getPath());
    assertFileEquals(clientA.getLocalFile("A-file1.jpg"), clientB.getLocalFile("A-file1.jpg"));
    assertConflictingFileExists("A-file1.jpg", clientB.getLocalFilesExcludeLockedAndNoRead());
    // Run (part 2)
    // This deletes the dirty database file
    clientB.up();
    Iterator<DatabaseVersion> databaseVersionsDirtyB2 = databaseVersionDao.getDirtyDatabaseVersions();
    List<DatabaseVersion> databaseVersionsDirtyListB2 = TestCollectionUtil.toList(databaseVersionsDirtyB2);
    assertEquals(0, databaseVersionsDirtyListB2.size());
    // Run (part 3)
    // This pulls down the conflicting file
    clientA.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
    assertConflictingFileExists("A-file1.jpg", clientA.getLocalFilesExcludeLockedAndNoRead());
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : Config(org.syncany.config.Config) DatabaseVersionSqlDao(org.syncany.database.dao.DatabaseVersionSqlDao) TransferSettings(org.syncany.plugins.transfer.TransferSettings) UpOperationOptions(org.syncany.operations.up.UpOperationOptions) MultiChunkSqlDao(org.syncany.database.dao.MultiChunkSqlDao) PartialFileHistory(org.syncany.database.PartialFileHistory) ChunkSqlDao(org.syncany.database.dao.ChunkSqlDao) MultiChunkSqlDao(org.syncany.database.dao.MultiChunkSqlDao) FileVersionSqlDao(org.syncany.database.dao.FileVersionSqlDao) TestClient(org.syncany.tests.util.TestClient) FileContentSqlDao(org.syncany.database.dao.FileContentSqlDao) FileHistorySqlDao(org.syncany.database.dao.FileHistorySqlDao) DatabaseVersion(org.syncany.database.DatabaseVersion) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)12 Config (org.syncany.config.Config)12 FileContentSqlDao (org.syncany.database.dao.FileContentSqlDao)12 Connection (java.sql.Connection)11 ChunkSqlDao (org.syncany.database.dao.ChunkSqlDao)10 DatabaseVersionSqlDao (org.syncany.database.dao.DatabaseVersionSqlDao)10 FileHistorySqlDao (org.syncany.database.dao.FileHistorySqlDao)10 FileVersionSqlDao (org.syncany.database.dao.FileVersionSqlDao)10 MultiChunkSqlDao (org.syncany.database.dao.MultiChunkSqlDao)10 DatabaseVersion (org.syncany.database.DatabaseVersion)6 FileContent (org.syncany.database.FileContent)3 DatabaseVersionHeader (org.syncany.database.DatabaseVersionHeader)2 MultiChunkEntry (org.syncany.database.MultiChunkEntry)2 MultiChunkId (org.syncany.database.MultiChunkEntry.MultiChunkId)2 PartialFileHistory (org.syncany.database.PartialFileHistory)2 DatabaseBranch (org.syncany.operations.down.DatabaseBranch)2 Date (java.util.Date)1 ChunkEntry (org.syncany.database.ChunkEntry)1 FileChecksum (org.syncany.database.FileContent.FileChecksum)1 FileVersion (org.syncany.database.FileVersion)1