Search in sources :

Example 31 with CleanupOperationOptions

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

Example 32 with CleanupOperationOptions

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

the class Issue429ScenarioTest method performAction.

public static void performAction(TestClient client, int choice) throws Exception {
    switch(choice) {
        case 0:
            logger.log(Level.INFO, "0. Creating file with content");
            if (!client.getLocalFile(client.getConfig().getDisplayName()).exists()) {
                client.createFileWithContent(client.getConfig().getDisplayName(), "content");
            }
            break;
        case 1:
            logger.log(Level.INFO, "1. Deleting my file.");
            client.deleteFile(client.getConfig().getDisplayName());
            break;
        case 2:
            logger.log(Level.INFO, "2. Deleting all files");
            for (String file : client.getLocalFiles().keySet()) {
                client.deleteFile(file);
            }
            break;
        case 3:
            logger.log(Level.INFO, "3. Performing Up");
            client.upWithForceChecksum();
            break;
        case 4:
            logger.log(Level.INFO, "4. Performing Down");
            client.down();
            break;
        case 5:
            logger.log(Level.INFO, "5. Performing Cleanup");
            CleanupOperationOptions options = new CleanupOperationOptions();
            options.setForce(true);
            client.cleanup(options);
            break;
        case 6:
            logger.log(Level.INFO, "6. Syncing.");
            client.sync();
            break;
        case 7:
            logger.log(Level.INFO, "7. Creating file with content (2)");
            if (!client.getLocalFile(client.getConfig().getDisplayName() + "2").exists()) {
                client.createFileWithContent(client.getConfig().getDisplayName() + "2", "content");
            }
            break;
        default:
            break;
    }
}
Also used : CleanupOperationOptions(org.syncany.operations.cleanup.CleanupOperationOptions)

Example 33 with CleanupOperationOptions

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

the class Issue143ScenarioTest method testChangeAttributes.

@Test
public void testChangeAttributes() throws Exception {
    // Setup 
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    java.sql.Connection databaseConnectionA = clientA.getConfig().createDatabaseConnection();
    TestClient clientB = new TestClient("B", testConnection);
    CleanupOperationOptions cleanupOptions = new CleanupOperationOptions();
    cleanupOptions.setMinSecondsBetweenCleanups(0);
    cleanupOptions.setMinKeepSeconds(0);
    // Scenario, see
    // https://github.com/syncany/syncany/issues/143#issuecomment-50964685
    // Run 
    clientA.createNewFile("file1.jpg");
    clientA.upWithForceChecksum();
    assertEquals("1", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));
    TestFileUtil.copyFile(clientA.getLocalFile("file1.jpg"), clientA.getLocalFile("file1 (copy).jpg"));
    clientA.upWithForceChecksum();
    assertEquals("2", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));
    clientA.deleteFile("file1 (copy).jpg");
    clientA.upWithForceChecksum();
    assertEquals("3", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));
    // Database versions of deleted file are removed
    clientA.cleanup(cleanupOptions);
    assertEquals("1", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));
    TestFileUtil.copyFile(clientA.getLocalFile("file1.jpg"), clientA.getLocalFile("file1 (copy).jpg"));
    clientA.upWithForceChecksum();
    assertEquals("2", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));
    clientA.deleteFile("file1.jpg");
    clientA.upWithForceChecksum();
    assertEquals("3", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));
    // Database version of deleted file is removed
    clientA.cleanup(cleanupOptions);
    assertEquals("2", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));
    // <<<< This creates the exception in #143
    clientB.down();
    // integrity constraint violation: foreign key no parent; SYS_FK_10173 table: FILEVERSION
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : TestClient(org.syncany.tests.util.TestClient) CleanupOperationOptions(org.syncany.operations.cleanup.CleanupOperationOptions) TransferSettings(org.syncany.plugins.transfer.TransferSettings) Test(org.junit.Test)

Example 34 with CleanupOperationOptions

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

the class Issue247ScenarioTest method testIssue247.

@Test
public void testIssue247() throws Exception {
    // Setup 
    File tempDir = TestFileUtil.createTempDirectoryInSystemTemp();
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient clientDzHome = new TestClient("Dz", testConnection);
    TestClient clientUxWork = new TestClient("Ux", testConnection);
    UpOperationOptions upOptionsWithForce = new UpOperationOptions();
    upOptionsWithForce.setForceUploadEnabled(true);
    // home -- generate some database versions so that the cleanup/merge will have something to merge		
    clientDzHome.createNewFile("someotherfile0.xml");
    clientDzHome.upWithForceChecksum();
    for (int i = 0; i < 30; i++) {
        clientDzHome.changeFile("someotherfile0.xml");
        clientDzHome.upWithForceChecksum();
    }
    // home
    // <<<<< This is the file/checksum causing the issue
    clientDzHome.createNewFile("config.xml");
    clientDzHome.upWithForceChecksum();
    // Make a copy (for later)		
    TestFileUtil.copyFile(clientDzHome.getLocalFile("config.xml"), new File(tempDir, "config.xml"));
    // work
    clientUxWork.down();
    clientUxWork.changeFile("config.xml");
    clientUxWork.upWithForceChecksum();
    clientUxWork.createNewFile("someotherfile1.xml");
    clientUxWork.upWithForceChecksum();
    clientUxWork.createNewFile("someotherfile2.xml");
    clientUxWork.upWithForceChecksum();
    clientUxWork.createNewFile("someotherfile3.xml");
    clientUxWork.upWithForceChecksum();
    // home
    clientDzHome.down();
    clientDzHome.changeFile("config.xml");
    clientDzHome.upWithForceChecksum();
    clientDzHome.changeFile("config.xml");
    clientDzHome.upWithForceChecksum();
    // work
    clientUxWork.down();
    CleanupOperationOptions cleanupOptions = new CleanupOperationOptions();
    clientUxWork.cleanup(cleanupOptions);
    // home
    clientDzHome.down();
    // Recreate problematic config.xml/checksum
    clientDzHome.deleteFile("config.xml");
    TestFileUtil.copyFile(new File(tempDir, "config.xml"), clientDzHome.getLocalFile("config.xml"));
    clientDzHome.upWithForceChecksum();
    // work
    clientUxWork.down();
    // Tear down
    TestFileUtil.deleteDirectory(tempDir);
    clientUxWork.deleteTestData();
    clientDzHome.deleteTestData();
}
Also used : LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) CleanupOperationOptions(org.syncany.operations.cleanup.CleanupOperationOptions) UpOperationOptions(org.syncany.operations.up.UpOperationOptions) File(java.io.File) Test(org.junit.Test)

Aggregations

CleanupOperationOptions (org.syncany.operations.cleanup.CleanupOperationOptions)34 Test (org.junit.Test)31 TestClient (org.syncany.tests.util.TestClient)31 LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)21 UnreliableLocalTransferSettings (org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings)18 CleanupOperationResult (org.syncany.operations.cleanup.CleanupOperationResult)14 File (java.io.File)11 StatusOperationOptions (org.syncany.operations.status.StatusOperationOptions)8 UpOperationOptions (org.syncany.operations.up.UpOperationOptions)8 FilenameFilter (java.io.FilenameFilter)5 TimeUnit (org.syncany.operations.cleanup.CleanupOperationOptions.TimeUnit)5 DatabaseRemoteFile (org.syncany.plugins.transfer.files.DatabaseRemoteFile)5 ActionRemoteFile (org.syncany.plugins.transfer.files.ActionRemoteFile)4 MultichunkRemoteFile (org.syncany.plugins.transfer.files.MultichunkRemoteFile)4 RemoteFile (org.syncany.plugins.transfer.files.RemoteFile)4 TempRemoteFile (org.syncany.plugins.transfer.files.TempRemoteFile)4 TransactionRemoteFile (org.syncany.plugins.transfer.files.TransactionRemoteFile)4 StorageException (org.syncany.plugins.transfer.StorageException)3 TransferManager (org.syncany.plugins.transfer.TransferManager)3 TransferSettings (org.syncany.plugins.transfer.TransferSettings)3