use of org.syncany.operations.up.UpOperationOptions in project syncany by syncany.
the class SplitSyncUpOperationTest method setUp.
@Before
public void setUp() throws Exception {
testConfig = TestConfigUtil.createTestLocalConfig();
opOptions = new UpOperationOptions();
}
use of org.syncany.operations.up.UpOperationOptions in project syncany by syncany.
the class UpCommand method execute.
@Override
public int execute(String[] operationArgs) throws Exception {
UpOperationOptions operationOptions = parseOptions(operationArgs);
UpOperationResult operationResult = new UpOperation(config, operationOptions).execute();
printResults(operationResult);
return 0;
}
use of org.syncany.operations.up.UpOperationOptions in project syncany by syncany.
the class UpCommand method parseOptions.
@Override
public UpOperationOptions parseOptions(String[] operationArgs) throws Exception {
UpOperationOptions operationOptions = new UpOperationOptions();
OptionParser parser = new OptionParser();
parser.allowsUnrecognizedOptions();
OptionSpec<Void> optionForceUpload = parser.acceptsAll(asList("F", "force-upload"));
OptionSpec<Void> optionNoResumeUpload = parser.acceptsAll(asList("R", "no-resume"));
OptionSet options = parser.parse(operationArgs);
// status [<args>]
operationOptions.setStatusOptions(parseStatusOptions(operationArgs));
// -F, --force-upload
operationOptions.setForceUploadEnabled(options.has(optionForceUpload));
// -R, --no-resume
operationOptions.setResume(!options.has(optionNoResumeUpload));
return operationOptions;
}
use of org.syncany.operations.up.UpOperationOptions 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);
}
use of org.syncany.operations.up.UpOperationOptions in project syncany by syncany.
the class CleanupOperationTest method testCleanupAfterFailedUpOperation.
@Test
public void testCleanupAfterFailedUpOperation() throws Exception {
// Setup
UnreliableLocalTransferSettings testConnection = TestConfigUtil.createTestUnreliableLocalConnection(Arrays.asList(new String[] { // << 3 retries!
"rel=[456].+upload.+multichunk" }));
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
StatusOperationOptions forceChecksumStatusOperationOptions = new StatusOperationOptions();
forceChecksumStatusOperationOptions.setForceChecksum(true);
UpOperationOptions noCleanupAndForceUpOperationOptions = new UpOperationOptions();
noCleanupAndForceUpOperationOptions.setForceUploadEnabled(true);
noCleanupAndForceUpOperationOptions.setStatusOptions(forceChecksumStatusOperationOptions);
// Run
// 1. Call A.up(); this fails AFTER the first multichunk
clientA.createNewFile("A-file1", 5 * 1024 * 1024);
boolean operationFailed = false;
try {
clientA.up();
} catch (Exception e) {
// That is supposed to happen!
operationFailed = true;
}
File repoMultiChunkDir = new File(testConnection.getPath() + "/multichunks");
File repoActionsDir = new File(testConnection.getPath() + "/actions");
assertTrue(operationFailed);
// Atomic operation, so multichunk is not yet present at location
assertEquals(0, repoMultiChunkDir.listFiles().length);
assertEquals(1, repoActionsDir.listFiles().length);
// 2. Call A.cleanup(); this does not run, because there are local changes
CleanupOperationResult cleanupOperationResultA = clientA.cleanup();
assertEquals(CleanupResultCode.NOK_LOCAL_CHANGES, cleanupOperationResultA.getResultCode());
// 3. Call B.cleanup(); this does not run, because of the leftover 'action' file
CleanupOperationResult cleanupOperationResultB = clientB.cleanup();
assertEquals(CleanupResultCode.NOK_OTHER_OPERATIONS_RUNNING, cleanupOperationResultB.getResultCode());
// 4. Call B.down(); this does not deliver any results, because no databases have been uploaded
DownOperationResult downOperationResult = clientB.down();
assertEquals(DownResultCode.OK_NO_REMOTE_CHANGES, downOperationResult.getResultCode());
// 5. Call 'up' again, this uploads previously crashed stuff, and then runs cleanup.
// The cleanup then removes the old multichunk and the old action files.
UpOperationResult secondUpResult = clientA.up();
assertEquals(UpResultCode.OK_CHANGES_UPLOADED, secondUpResult.getResultCode());
assertEquals(2, repoMultiChunkDir.listFiles().length);
assertEquals(0, repoActionsDir.listFiles().length);
// 6. Call 'cleanup' manually (Nothing happens, since transaction was cleaned on second up)
CleanupOperationResult cleanupOperationResult = clientA.cleanup();
assertEquals(CleanupOperationResult.CleanupResultCode.OK_NOTHING_DONE, cleanupOperationResult.getResultCode());
assertEquals(0, cleanupOperationResult.getRemovedMultiChunksCount());
assertEquals(0, repoActionsDir.listFiles().length);
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
}
Aggregations