Search in sources :

Example 6 with StatusOperation

use of org.syncany.operations.status.StatusOperation 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 7 with StatusOperation

use of org.syncany.operations.status.StatusOperation 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)

Aggregations

StatusOperation (org.syncany.operations.status.StatusOperation)7 ChangeSet (org.syncany.operations.ChangeSet)5 File (java.io.File)4 Test (org.junit.Test)4 Config (org.syncany.config.Config)4 UpOperation (org.syncany.operations.up.UpOperation)4 StatusOperationResult (org.syncany.operations.status.StatusOperationResult)3 StatusOperationOptions (org.syncany.operations.status.StatusOperationOptions)2 LsRemoteOperation (org.syncany.operations.ls_remote.LsRemoteOperation)1 LsRemoteOperationResult (org.syncany.operations.ls_remote.LsRemoteOperationResult)1 UpOperationOptions (org.syncany.operations.up.UpOperationOptions)1 DatabaseRemoteFile (org.syncany.plugins.transfer.files.DatabaseRemoteFile)1