Search in sources :

Example 6 with UpOperationOptions

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();
}
Also used : UpOperationOptions(org.syncany.operations.up.UpOperationOptions) Before(org.junit.Before)

Example 7 with 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;
}
Also used : UpOperation(org.syncany.operations.up.UpOperation) UpOperationOptions(org.syncany.operations.up.UpOperationOptions) UpOperationResult(org.syncany.operations.up.UpOperationResult)

Example 8 with UpOperationOptions

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;
}
Also used : UpOperationOptions(org.syncany.operations.up.UpOperationOptions) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser)

Example 9 with UpOperationOptions

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);
}
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 10 with UpOperationOptions

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();
}
Also used : CleanupOperationResult(org.syncany.operations.cleanup.CleanupOperationResult) DownOperationResult(org.syncany.operations.down.DownOperationResult) UnreliableLocalTransferSettings(org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) UpOperationOptions(org.syncany.operations.up.UpOperationOptions) StatusOperationOptions(org.syncany.operations.status.StatusOperationOptions) File(java.io.File) UpOperationResult(org.syncany.operations.up.UpOperationResult) Test(org.junit.Test)

Aggregations

UpOperationOptions (org.syncany.operations.up.UpOperationOptions)29 Test (org.junit.Test)25 TestClient (org.syncany.tests.util.TestClient)23 File (java.io.File)16 LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)14 StatusOperationOptions (org.syncany.operations.status.StatusOperationOptions)10 CleanupOperationOptions (org.syncany.operations.cleanup.CleanupOperationOptions)8 UnreliableLocalTransferSettings (org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings)7 DownOperationResult (org.syncany.operations.down.DownOperationResult)6 FilenameFilter (java.io.FilenameFilter)4 UpOperationResult (org.syncany.operations.up.UpOperationResult)4 StorageException (org.syncany.plugins.transfer.StorageException)4 TransferSettings (org.syncany.plugins.transfer.TransferSettings)4 Config (org.syncany.config.Config)3 UpOperation (org.syncany.operations.up.UpOperation)3 Persister (org.simpleframework.xml.core.Persister)2 ChangeSet (org.syncany.operations.ChangeSet)2 CleanupOperationResult (org.syncany.operations.cleanup.CleanupOperationResult)2 TransferManager (org.syncany.plugins.transfer.TransferManager)2 TransactionAware (org.syncany.plugins.transfer.features.TransactionAware)2