Search in sources :

Example 11 with CleanupOperationResult

use of org.syncany.operations.cleanup.CleanupOperationResult in project syncany by syncany.

the class WatchOperation method runSync.

/**
	 * Runs one iteration of the main synchronization loop, containing a {@link DownOperation},
	 * an {@link UpOperation} and (if required), a {@link CleanupOperation}.
	 */
private void runSync() throws Exception {
    if (!syncRunning.get()) {
        syncRunning.set(true);
        syncRequested.set(false);
        logger.log(Level.INFO, "RUNNING SYNC ...");
        fireStartEvent();
        try {
            boolean notifyChanges = false;
            // Run down
            DownOperationResult downResult = new DownOperation(config, options.getDownOptions()).execute();
            if (downResult.getResultCode() == DownResultCode.OK_WITH_REMOTE_CHANGES) {
            // TODO [low] Do something?
            }
            // Run up
            UpOperationResult upOperationResult = new UpOperation(config, options.getUpOptions()).execute();
            if (upOperationResult.getResultCode() == UpResultCode.OK_CHANGES_UPLOADED && upOperationResult.getChangeSet().hasChanges()) {
                upCount.incrementAndGet();
                notifyChanges = true;
            }
            CleanupOperationResult cleanupOperationResult = new CleanupOperation(config, options.getCleanupOptions()).execute();
            if (cleanupOperationResult.getResultCode() == CleanupResultCode.OK) {
                notifyChanges = true;
            }
            // Fire change event if up and/or cleanup
            if (notifyChanges) {
                notifyChanges();
            }
        } finally {
            logger.log(Level.INFO, "SYNC DONE.");
            syncRunning.set(false);
            fireEndEvent();
        }
    } else {
        // Can't do a log message here, because this bit is called thousand
        // of times when file system events occur.
        syncRequested.set(true);
    }
}
Also used : UpOperation(org.syncany.operations.up.UpOperation) CleanupOperationResult(org.syncany.operations.cleanup.CleanupOperationResult) DownOperationResult(org.syncany.operations.down.DownOperationResult) DownOperation(org.syncany.operations.down.DownOperation) CleanupOperation(org.syncany.operations.cleanup.CleanupOperation) UpOperationResult(org.syncany.operations.up.UpOperationResult)

Example 12 with CleanupOperationResult

use of org.syncany.operations.cleanup.CleanupOperationResult in project syncany by syncany.

the class CleanupOperationTest method testCleanupFailsBecauseOfLocalChanges.

@Test
public void testCleanupFailsBecauseOfLocalChanges() throws Exception {
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    StatusOperationOptions statusOptions = new StatusOperationOptions();
    statusOptions.setForceChecksum(true);
    CleanupOperationOptions cleanupOptions = new CleanupOperationOptions();
    cleanupOptions.setStatusOptions(statusOptions);
    cleanupOptions.setRemoveOldVersions(true);
    // Run
    // A: Create some file versions
    clientA.createNewFile("file.jpg");
    for (int i = 1; i <= 4; i++) {
        clientA.changeFile("file.jpg");
        clientA.upWithForceChecksum();
    }
    // B: Sync down, add something
    clientB.down();
    clientB.changeFile("file.jpg");
    CleanupOperationResult cleanupOperationResult = clientB.cleanup(cleanupOptions);
    assertEquals(CleanupResultCode.NOK_LOCAL_CHANGES, cleanupOperationResult.getResultCode());
    assertEquals(0, cleanupOperationResult.getMergedDatabaseFilesCount());
    assertEquals(0, cleanupOperationResult.getRemovedMultiChunksCount());
    assertEquals(0, cleanupOperationResult.getRemovedOldVersionsCount());
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : CleanupOperationResult(org.syncany.operations.cleanup.CleanupOperationResult) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) UnreliableLocalTransferSettings(org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) CleanupOperationOptions(org.syncany.operations.cleanup.CleanupOperationOptions) StatusOperationOptions(org.syncany.operations.status.StatusOperationOptions) Test(org.junit.Test)

Example 13 with CleanupOperationResult

use of org.syncany.operations.cleanup.CleanupOperationResult in project syncany by syncany.

the class CleanupOperationTest method testCleanupManyUpsAfterCleanup.

@Test
public void testCleanupManyUpsAfterCleanup() throws Exception {
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    CleanupOperationOptions options = new CleanupOperationOptions();
    options.setRemoveOldVersions(true);
    options.setMinKeepSeconds(0);
    // Run
    // A: Create some file versions
    clientA.createNewFile("file.jpg");
    for (int i = 1; i <= 4; i++) {
        clientA.changeFile("file.jpg");
        clientA.upWithForceChecksum();
    }
    // B: Sync down
    clientB.down();
    // A: Cleanup
    CleanupOperationResult cleanupOperationResult = clientA.cleanup(options);
    assertEquals(CleanupResultCode.OK, cleanupOperationResult.getResultCode());
    assertEquals(4, cleanupOperationResult.getMergedDatabaseFilesCount());
    assertEquals(3, cleanupOperationResult.getRemovedMultiChunksCount());
    assertEquals(1, cleanupOperationResult.getRemovedOldVersionsCount());
    // A: Continue to upload stuff ! <<<<<<<<<<<<<<<<<<<<<
    for (int i = 1; i <= 4; i++) {
        clientA.changeFile("file.jpg");
        clientA.upWithForceChecksum();
    }
    clientA.createNewFile("file2.jpg");
    for (int i = 1; i <= 4; i++) {
        clientA.changeFile("file2.jpg");
        clientA.upWithForceChecksum();
    }
    // B: Sync down
    clientB.down();
    TestAssertUtil.assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : CleanupOperationResult(org.syncany.operations.cleanup.CleanupOperationResult) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) UnreliableLocalTransferSettings(org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) CleanupOperationOptions(org.syncany.operations.cleanup.CleanupOperationOptions) Test(org.junit.Test)

Example 14 with CleanupOperationResult

use of org.syncany.operations.cleanup.CleanupOperationResult 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)

Example 15 with CleanupOperationResult

use of org.syncany.operations.cleanup.CleanupOperationResult in project syncany by syncany.

the class CleanupOperationTest method testCleanupFailsBecauseOfRemoteChanges.

@Test
public void testCleanupFailsBecauseOfRemoteChanges() throws Exception {
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    CleanupOperationOptions options = new CleanupOperationOptions();
    options.setRemoveOldVersions(true);
    // Run
    // A: Create some file versions
    clientA.createNewFile("file.jpg");
    for (int i = 1; i <= 4; i++) {
        clientA.changeFile("file.jpg");
        clientA.upWithForceChecksum();
    }
    // B: Sync down, add something
    clientB.down();
    // A: Add something
    clientA.changeFile("file.jpg");
    clientA.upWithForceChecksum();
    // B: Cleanup
    CleanupOperationResult cleanupOperationResult = clientB.cleanup(options);
    assertEquals(CleanupResultCode.NOK_REMOTE_CHANGES, cleanupOperationResult.getResultCode());
    assertEquals(0, cleanupOperationResult.getMergedDatabaseFilesCount());
    assertEquals(0, cleanupOperationResult.getRemovedMultiChunksCount());
    assertEquals(0, cleanupOperationResult.getRemovedOldVersionsCount());
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : CleanupOperationResult(org.syncany.operations.cleanup.CleanupOperationResult) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) UnreliableLocalTransferSettings(org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) CleanupOperationOptions(org.syncany.operations.cleanup.CleanupOperationOptions) Test(org.junit.Test)

Aggregations

CleanupOperationResult (org.syncany.operations.cleanup.CleanupOperationResult)17 Test (org.junit.Test)14 CleanupOperationOptions (org.syncany.operations.cleanup.CleanupOperationOptions)14 UnreliableLocalTransferSettings (org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings)14 TestClient (org.syncany.tests.util.TestClient)14 LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)8 File (java.io.File)5 FilenameFilter (java.io.FilenameFilter)3 TimeUnit (org.syncany.operations.cleanup.CleanupOperationOptions.TimeUnit)3 StatusOperationOptions (org.syncany.operations.status.StatusOperationOptions)3 UpOperationResult (org.syncany.operations.up.UpOperationResult)3 ActionRemoteFile (org.syncany.plugins.transfer.files.ActionRemoteFile)3 DatabaseRemoteFile (org.syncany.plugins.transfer.files.DatabaseRemoteFile)3 MultichunkRemoteFile (org.syncany.plugins.transfer.files.MultichunkRemoteFile)3 RemoteFile (org.syncany.plugins.transfer.files.RemoteFile)3 TempRemoteFile (org.syncany.plugins.transfer.files.TempRemoteFile)3 TransactionRemoteFile (org.syncany.plugins.transfer.files.TransactionRemoteFile)3 CleanupOperation (org.syncany.operations.cleanup.CleanupOperation)2 DownOperationResult (org.syncany.operations.down.DownOperationResult)2 UpOperationOptions (org.syncany.operations.up.UpOperationOptions)2