Search in sources :

Example 6 with UpOperation

use of org.syncany.operations.up.UpOperation in project syncany by syncany.

the class LogOperationTest method testLogOperation.

@Test
public void testLogOperation() throws Exception {
    // Setup
    Config config = TestConfigUtil.createTestLocalConfig();
    StatusOperationOptions statusOptions = new StatusOperationOptions();
    statusOptions.setForceChecksum(true);
    UpOperationOptions upOptions = new UpOperationOptions();
    upOptions.setStatusOptions(statusOptions);
    upOptions.setForceUploadEnabled(true);
    // First, do some uploading
    List<File> originalFiles = TestFileUtil.createRandomFilesInDirectory(config.getLocalDir(), 5 * 1024, 5);
    new UpOperation(config, upOptions).execute();
    // And some more
    for (File file : originalFiles) {
        TestFileUtil.changeRandomPartOfBinaryFile(file);
    }
    new UpOperation(config, upOptions).execute();
    // And some more
    for (File file : originalFiles) {
        file.delete();
    }
    new UpOperation(config, upOptions).execute();
    // Then, check the log
    LogOperationOptions logOptions = new LogOperationOptions();
    logOptions.setStartDatabaseVersionIndex(0);
    logOptions.setMaxDatabaseVersionCount(99);
    logOptions.setMaxFileHistoryCount(99);
    List<LightweightDatabaseVersion> databaseVersions = (new LogOperation(config, logOptions).execute()).getDatabaseVersions();
    assertEquals(3, databaseVersions.size());
    assertEquals(5, databaseVersions.get(2).getChangeSet().getNewFiles().size());
    assertEquals(0, databaseVersions.get(2).getChangeSet().getChangedFiles().size());
    assertEquals(0, databaseVersions.get(2).getChangeSet().getDeletedFiles().size());
    assertEquals(0, databaseVersions.get(1).getChangeSet().getNewFiles().size());
    assertEquals(5, databaseVersions.get(1).getChangeSet().getChangedFiles().size());
    assertEquals(0, databaseVersions.get(1).getChangeSet().getDeletedFiles().size());
    assertEquals(0, databaseVersions.get(0).getChangeSet().getNewFiles().size());
    assertEquals(0, databaseVersions.get(0).getChangeSet().getChangedFiles().size());
    assertEquals(5, databaseVersions.get(0).getChangeSet().getDeletedFiles().size());
    // Cleanup
    TestConfigUtil.deleteTestLocalConfigAndData(config);
}
Also used : UpOperation(org.syncany.operations.up.UpOperation) LogOperation(org.syncany.operations.log.LogOperation) Config(org.syncany.config.Config) LightweightDatabaseVersion(org.syncany.operations.log.LightweightDatabaseVersion) UpOperationOptions(org.syncany.operations.up.UpOperationOptions) StatusOperationOptions(org.syncany.operations.status.StatusOperationOptions) File(java.io.File) LogOperationOptions(org.syncany.operations.log.LogOperationOptions) Test(org.junit.Test)

Example 7 with UpOperation

use of org.syncany.operations.up.UpOperation in project syncany by syncany.

the class SplitSyncUpOperationTest method testUploadLocalDatabase.

private void testUploadLocalDatabase(int fileSize, int fileAmount, int expectedTransactions, UpOperationOptions options) throws Exception {
    List<File> originalFiles = TestFileUtil.createRandomFilesInDirectory(testConfig.getLocalDir(), fileSize, fileAmount);
    // Run!
    AbstractTransferOperation op = new UpOperation(testConfig, options);
    UpOperationResult opResult = (UpOperationResult) op.execute();
    // Ensure that the expected number of transactions has been completed to upload the files
    assertNotNull(opResult);
    assertTrue(opResult.getTransactionsCompleted() == expectedTransactions);
    // Get databases (for comparison)
    LocalTransferSettings localConnection = (LocalTransferSettings) testConfig.getConnection();
    File localDatabaseDir = testConfig.getDatabaseDir();
    assertNotNull(localDatabaseDir.listFiles());
    assertTrue(localDatabaseDir.listFiles().length > 0);
    List<File> remoteDatabaseFiles = new ArrayList<>();
    for (int transaction = 1; transaction <= expectedTransactions; transaction++) {
        String databaseVersion = String.format("%010d", transaction);
        File remoteDatabaseFile = new File(localConnection.getPath() + "/databases/database-" + testConfig.getMachineName() + "-" + databaseVersion);
        assertTrue(remoteDatabaseFile.exists());
        remoteDatabaseFiles.add(remoteDatabaseFile);
    }
    // Import remote databases into memory database
    DatabaseXmlSerializer dDAO = new DatabaseXmlSerializer(testConfig.getTransformer());
    MemoryDatabase remoteDatabase = new MemoryDatabase();
    for (File remoteDatabaseFile : remoteDatabaseFiles) {
        dDAO.load(remoteDatabase, remoteDatabaseFile, null, null, DatabaseXmlSerializer.DatabaseReadType.FULL);
    }
    // Open local SQL Database
    SqlDatabase localDatabase = new SqlDatabase(testConfig);
    // Compare!
    assertEquals(localDatabase.getLastDatabaseVersionHeader(), remoteDatabase.getLastDatabaseVersion().getHeader());
    Map<PartialFileHistory.FileHistoryId, PartialFileHistory> localFileHistories = localDatabase.getFileHistoriesWithFileVersions();
    Collection<PartialFileHistory> remoteFileHistories = remoteDatabase.getFileHistories();
    assertEquals(localDatabase.getCurrentFileTree().size(), fileAmount);
    assertEquals(localFileHistories.size(), remoteDatabase.getFileHistories().size());
    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 : ArrayList(java.util.ArrayList) DatabaseXmlSerializer(org.syncany.database.dao.DatabaseXmlSerializer) UpOperationResult(org.syncany.operations.up.UpOperationResult) AbstractTransferOperation(org.syncany.operations.AbstractTransferOperation) UpOperation(org.syncany.operations.up.UpOperation) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) File(java.io.File)

Example 8 with UpOperation

use of org.syncany.operations.up.UpOperation in project syncany by syncany.

the class StatusOperationTest method testStatusOperation.

@Test
public void testStatusOperation() throws Exception {
    // Setup
    Config config = TestConfigUtil.createTestLocalConfig();
    // Add new files 
    List<File> originalFiles = TestFileUtil.createRandomFilesInDirectory(config.getLocalDir(), 500 * 1024, 3);
    // Status
    ChangeSet changeSet = (new StatusOperation(config).execute()).getChangeSet();
    assertEquals(changeSet.getNewFiles().size(), originalFiles.size());
    assertEquals(changeSet.getChangedFiles().size(), 0);
    assertEquals(changeSet.getDeletedFiles().size(), 0);
    // Up
    new UpOperation(config).execute();
    // Status
    changeSet = (new StatusOperation(config).execute()).getChangeSet();
    assertEquals(changeSet.getNewFiles().size(), 0);
    assertEquals(changeSet.getChangedFiles().size(), 0);
    assertEquals(changeSet.getDeletedFiles().size(), 0);
    // Change all files, run 'status'
    // TODO [low] StatusOperation relies on file modified time and size, any other methods?
    Thread.sleep(2000);
    for (File file : originalFiles) {
        TestFileUtil.changeRandomPartOfBinaryFile(file);
    }
    changeSet = (new StatusOperation(config).execute()).getChangeSet();
    assertEquals(changeSet.getNewFiles().size(), 0);
    assertEquals(changeSet.getChangedFiles().size(), originalFiles.size());
    assertEquals(changeSet.getDeletedFiles().size(), 0);
    // Up
    new UpOperation(config).execute();
    // Delete all files, run 'status' again
    for (File file : originalFiles) {
        TestFileUtil.deleteFile(file);
    }
    changeSet = (new StatusOperation(config).execute()).getChangeSet();
    assertEquals(changeSet.getNewFiles().size(), 0);
    assertEquals(changeSet.getChangedFiles().size(), 0);
    assertEquals(changeSet.getDeletedFiles().size(), originalFiles.size());
    // Cleanup
    TestConfigUtil.deleteTestLocalConfigAndData(config);
}
Also used : UpOperation(org.syncany.operations.up.UpOperation) StatusOperation(org.syncany.operations.status.StatusOperation) Config(org.syncany.config.Config) File(java.io.File) ChangeSet(org.syncany.operations.ChangeSet) Test(org.junit.Test)

Example 9 with UpOperation

use of org.syncany.operations.up.UpOperation in project syncany by syncany.

the class StatusOperationTest method testVeryRecentFileModificationWithoutSizeOrModifiedDateChange.

@Test
public void testVeryRecentFileModificationWithoutSizeOrModifiedDateChange() throws Exception {
    // Setup
    Config config = TestConfigUtil.createTestLocalConfig();
    File testFile = TestFileUtil.createRandomFileInDirectory(config.getLocalDir(), 40);
    StatusOperationOptions statusOptions = new StatusOperationOptions();
    statusOptions.setForceChecksum(true);
    UpOperationOptions syncUpOptions = new UpOperationOptions();
    syncUpOptions.setStatusOptions(statusOptions);
    // Perform 'up' and immediately change test file
    // IMPORTANT: Do NOT sleep to enforce checksum-based comparison in 'status'
    new UpOperation(config, syncUpOptions).execute();
    TestFileUtil.changeRandomPartOfBinaryFile(testFile);
    // Run 'status', this should run a checksum-based file comparison
    ChangeSet changeSet = (new StatusOperation(config, statusOptions).execute()).getChangeSet();
    assertEquals(changeSet.getChangedFiles().size(), 1);
    // Cleanup 
    TestConfigUtil.deleteTestLocalConfigAndData(config);
}
Also used : UpOperation(org.syncany.operations.up.UpOperation) StatusOperation(org.syncany.operations.status.StatusOperation) Config(org.syncany.config.Config) UpOperationOptions(org.syncany.operations.up.UpOperationOptions) File(java.io.File) StatusOperationOptions(org.syncany.operations.status.StatusOperationOptions) ChangeSet(org.syncany.operations.ChangeSet) Test(org.junit.Test)

Example 10 with UpOperation

use of org.syncany.operations.up.UpOperation 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)

Aggregations

UpOperation (org.syncany.operations.up.UpOperation)10 File (java.io.File)7 Test (org.junit.Test)7 Config (org.syncany.config.Config)6 ChangeSet (org.syncany.operations.ChangeSet)4 StatusOperation (org.syncany.operations.status.StatusOperation)4 UpOperationOptions (org.syncany.operations.up.UpOperationOptions)3 UpOperationResult (org.syncany.operations.up.UpOperationResult)3 ArrayList (java.util.ArrayList)2 DatabaseXmlSerializer (org.syncany.database.dao.DatabaseXmlSerializer)2 AbstractTransferOperation (org.syncany.operations.AbstractTransferOperation)2 DownOperation (org.syncany.operations.down.DownOperation)2 StatusOperationOptions (org.syncany.operations.status.StatusOperationOptions)2 LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)2 DatabaseVersion (org.syncany.database.DatabaseVersion)1 FileVersion (org.syncany.database.FileVersion)1 MemoryDatabase (org.syncany.database.MemoryDatabase)1 PartialFileHistory (org.syncany.database.PartialFileHistory)1 FileHistoryId (org.syncany.database.PartialFileHistory.FileHistoryId)1 SqlDatabase (org.syncany.database.SqlDatabase)1