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