Search in sources :

Example 41 with DatabaseVersion

use of org.syncany.database.DatabaseVersion in project syncany by syncany.

the class UpOperationTest method testUploadLocalDatabase.

@Test
public void testUploadLocalDatabase() throws Exception {
    int fileSize = 1230 * 1024;
    int fileAmount = 3;
    List<File> originalFiles = TestFileUtil.createRandomFilesInDirectory(testConfig.getLocalDir(), fileSize, fileAmount);
    // Run!
    AbstractTransferOperation op = new UpOperation(testConfig);
    op.execute();
    // Get databases (for comparison)
    LocalTransferSettings localConnection = (LocalTransferSettings) testConfig.getConnection();
    File localDatabaseDir = testConfig.getDatabaseDir();
    File remoteDatabaseFile = new File(localConnection.getPath() + "/databases/database-" + testConfig.getMachineName() + "-0000000001");
    assertNotNull(localDatabaseDir.listFiles());
    assertTrue(localDatabaseDir.listFiles().length > 0);
    assertTrue(remoteDatabaseFile.exists());
    // - Memory database
    DatabaseXmlSerializer dDAO = new DatabaseXmlSerializer(testConfig.getTransformer());
    MemoryDatabase remoteDatabase = new MemoryDatabase();
    dDAO.load(remoteDatabase, remoteDatabaseFile, null, null, DatabaseReadType.FULL);
    DatabaseVersion remoteDatabaseVersion = remoteDatabase.getLastDatabaseVersion();
    // - Sql Database
    SqlDatabase localDatabase = new SqlDatabase(testConfig);
    Map<FileHistoryId, PartialFileHistory> localFileHistories = localDatabase.getFileHistoriesWithFileVersions();
    // Compare!
    assertEquals(localDatabase.getLastDatabaseVersionHeader(), remoteDatabaseVersion.getHeader());
    assertEquals(localFileHistories.size(), fileAmount);
    assertEquals(localDatabase.getFileHistoriesWithFileVersions().size(), remoteDatabaseVersion.getFileHistories().size());
    Collection<PartialFileHistory> remoteFileHistories = remoteDatabaseVersion.getFileHistories();
    List<FileVersion> remoteFileVersions = new ArrayList<FileVersion>();
    List<FileVersion> localFileVersions = new ArrayList<FileVersion>();
    for (PartialFileHistory partialFileHistory : remoteFileHistories) {
        remoteFileVersions.add(partialFileHistory.getLastVersion());
        assertNotNull(localFileHistories.get(partialFileHistory.getFileHistoryId()));
    }
    for (PartialFileHistory partialFileHistory : localFileHistories.values()) {
        localFileVersions.add(partialFileHistory.getLastVersion());
    }
    assertTrue(CollectionUtil.containsExactly(localFileVersions, remoteFileVersions));
    compareFileVersionsAgainstOriginalFiles(originalFiles, localFileVersions);
    compareFileVersionsAgainstOriginalFiles(originalFiles, remoteFileVersions);
}
Also used : FileHistoryId(org.syncany.database.PartialFileHistory.FileHistoryId) ArrayList(java.util.ArrayList) DatabaseXmlSerializer(org.syncany.database.dao.DatabaseXmlSerializer) PartialFileHistory(org.syncany.database.PartialFileHistory) AbstractTransferOperation(org.syncany.operations.AbstractTransferOperation) UpOperation(org.syncany.operations.up.UpOperation) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) FileVersion(org.syncany.database.FileVersion) MemoryDatabase(org.syncany.database.MemoryDatabase) SqlDatabase(org.syncany.database.SqlDatabase) File(java.io.File) DatabaseVersion(org.syncany.database.DatabaseVersion) Test(org.junit.Test)

Example 42 with DatabaseVersion

use of org.syncany.database.DatabaseVersion 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)

Example 43 with DatabaseVersion

use of org.syncany.database.DatabaseVersion in project syncany by syncany.

the class TestDatabaseUtil method createDatabaseVersion.

public static DatabaseVersion createDatabaseVersion(DatabaseVersionHeader basedOnDatabaseVersionHeader, Date date) {
    VectorClock vectorClock = (basedOnDatabaseVersionHeader != null) ? basedOnDatabaseVersionHeader.getVectorClock().clone() : new VectorClock();
    vectorClock.incrementClock("someclient");
    DatabaseVersion databaseVersion = new DatabaseVersion();
    databaseVersion.setClient("someclient");
    databaseVersion.setTimestamp(date);
    databaseVersion.setVectorClock(vectorClock);
    return databaseVersion;
}
Also used : VectorClock(org.syncany.database.VectorClock) DatabaseVersion(org.syncany.database.DatabaseVersion)

Aggregations

DatabaseVersion (org.syncany.database.DatabaseVersion)43 Test (org.junit.Test)22 MemoryDatabase (org.syncany.database.MemoryDatabase)20 MultiChunkEntry (org.syncany.database.MultiChunkEntry)12 PartialFileHistory (org.syncany.database.PartialFileHistory)12 ChunkEntry (org.syncany.database.ChunkEntry)11 FileVersion (org.syncany.database.FileVersion)10 ChunkChecksum (org.syncany.database.ChunkEntry.ChunkChecksum)9 ArrayList (java.util.ArrayList)8 FileHistoryId (org.syncany.database.PartialFileHistory.FileHistoryId)8 File (java.io.File)7 Config (org.syncany.config.Config)7 MultiChunkId (org.syncany.database.MultiChunkEntry.MultiChunkId)6 ChunkSqlDao (org.syncany.database.dao.ChunkSqlDao)6 DatabaseVersionSqlDao (org.syncany.database.dao.DatabaseVersionSqlDao)6 FileContentSqlDao (org.syncany.database.dao.FileContentSqlDao)6 FileHistorySqlDao (org.syncany.database.dao.FileHistorySqlDao)6 FileVersionSqlDao (org.syncany.database.dao.FileVersionSqlDao)6 MultiChunkSqlDao (org.syncany.database.dao.MultiChunkSqlDao)6 DatabaseRemoteFile (org.syncany.plugins.transfer.files.DatabaseRemoteFile)6