Search in sources :

Example 16 with CleanupOperationResult

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

the class CleanupOperationTest method testCleanupNoChangeBecauseDirty.

@Test
public void testCleanupNoChangeBecauseDirty() throws Exception {
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    CleanupOperationOptions removeOldCleanupOperationOptions = new CleanupOperationOptions();
    removeOldCleanupOperationOptions.setRemoveOldVersions(true);
    StatusOperationOptions forceChecksumStatusOperationOptions = new StatusOperationOptions();
    forceChecksumStatusOperationOptions.setForceChecksum(true);
    UpOperationOptions noCleanupAndForceUpOperationOptions = new UpOperationOptions();
    noCleanupAndForceUpOperationOptions.setForceUploadEnabled(true);
    noCleanupAndForceUpOperationOptions.setStatusOptions(forceChecksumStatusOperationOptions);
    // 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: Change file.jpg (first step in creating a conflict)
    clientA.changeFile("file.jpg");
    clientA.up(noCleanupAndForceUpOperationOptions);
    // B: Change file.jpg (second step in creating a conflict)
    clientB.changeFile("file.jpg");
    // << creates conflict
    clientB.up(noCleanupAndForceUpOperationOptions);
    // B: Sync down (creates a local conflict file and marks local changes as DRITY)
    // << creates DIRTY database entries
    clientB.down();
    // B: Cleanup
    CleanupOperationResult cleanupOperationResult = clientB.cleanup(removeOldCleanupOperationOptions);
    assertEquals(CleanupResultCode.NOK_DIRTY_LOCAL, 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) UpOperationOptions(org.syncany.operations.up.UpOperationOptions) StatusOperationOptions(org.syncany.operations.status.StatusOperationOptions) Test(org.junit.Test)

Example 17 with CleanupOperationResult

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

the class Issue316ScenarioTest method testIssue316CleanupThenDeleteFile.

@Test
public void testIssue316CleanupThenDeleteFile() throws Exception {
    /*
		 * This is a test for issue #316. It creates a situation in which a 'down'
		 * fails after a cleanup. In that first down, the local database is deleted 
		 * entirely, so that all databases are downloaded again, so all remote file
		 * versions are compared to "null". In this bug, comparing a deleted file version
		 * to a local existing file failed, because this case was thought to not happen
		 * ever.  
		 */
    // Setup
    UnreliableLocalTransferSettings testConnection = TestConfigUtil.createTestUnreliableLocalConnection(Arrays.asList(new String[] { // << 3 retries!
    "rel=(5|6|7) .+download.+multichunk" }));
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    java.sql.Connection databaseConnectionB = clientB.getConfig().createDatabaseConnection();
    CleanupOperationOptions cleanupOptionsKeepOne = new CleanupOperationOptions();
    cleanupOptionsKeepOne.setMaxDatabaseFiles(1);
    cleanupOptionsKeepOne.setForce(true);
    clientA.createNewFile("Kazam_screencast_00010.mp4");
    clientA.upWithForceChecksum();
    clientB.down();
    assertTrue(clientB.getLocalFile("Kazam_screencast_00010.mp4").exists());
    clientA.createNewFile("SomeFileTOIncreaseTheDatabaseFileCount");
    clientA.upWithForceChecksum();
    CleanupOperationResult cleanupResult = clientA.cleanup(cleanupOptionsKeepOne);
    assertEquals(CleanupResultCode.OK, cleanupResult.getResultCode());
    clientA.deleteFile("Kazam_screencast_00010.mp4");
    clientA.upWithForceChecksum();
    // First 'down' of client B after the cleanup. 
    // This fails AFTER the local database was wiped.
    boolean downFailedAtB = false;
    try {
        clientB.down();
    } catch (Exception e) {
        downFailedAtB = true;
    }
    assertTrue("Down operation should have failed.", downFailedAtB);
    assertEquals("0", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionB));
    assertEquals("0", TestSqlUtil.runSqlSelect("select count(*) from fileversion", databaseConnectionB));
    assertEquals("0", TestSqlUtil.runSqlSelect("select count(*) from known_databases", databaseConnectionB));
    // Second 'down' of client B; This should delete the file 'Kazam_screencast_00010.mp4',
    // because it matches the checksum of the 'DELETED' entry
    clientB.down();
    assertConflictingFileNotExists("Kazam_screencast_00010.mp4", clientB.getLocalFiles());
    assertFalse(clientB.getLocalFile("Kazam_screencast_00010.mp4").exists());
    // Tear down
    clientB.deleteTestData();
    clientA.deleteTestData();
}
Also used : CleanupOperationResult(org.syncany.operations.cleanup.CleanupOperationResult) 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