Search in sources :

Example 16 with CleanupOperationOptions

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

the class CleanupMergeDatabaseFilesScenarioTest method testIssue58_4.

@Test
public void testIssue58_4() throws Exception {
    // Test for https://github.com/syncany/syncany/issues/58#issuecomment-43472118
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    TestClient clientC = new TestClient("C", testConnection);
    CleanupOperationOptions cleanupOptionsKeep1 = new CleanupOperationOptions();
    cleanupOptionsKeep1.setRemoveOldVersions(true);
    StatusOperationOptions statusOptionsForceChecksum = new StatusOperationOptions();
    statusOptionsForceChecksum.setForceChecksum(true);
    UpOperationOptions upNoCleanupForceChecksum = new UpOperationOptions();
    upNoCleanupForceChecksum.setStatusOptions(statusOptionsForceChecksum);
    UpOperationOptions upWithCleanupKeep1ForceChecksum = new UpOperationOptions();
    upWithCleanupKeep1ForceChecksum.setStatusOptions(statusOptionsForceChecksum);
    clientB.createNewFile("fileB");
    clientB.up(upNoCleanupForceChecksum);
    clientA.down();
    TestFileUtil.copyFile(clientB.getLocalFile("fileB"), clientA.getLocalFile("fileBcopy"));
    clientA.up(upNoCleanupForceChecksum);
    for (int i = 0; i < 30; i++) {
        clientB.down();
        clientB.changeFile("fileB");
        clientB.up(upNoCleanupForceChecksum);
    }
    FileUtils.copyDirectory(testConnection.getPath(), new File(testConnection.getPath() + "_1_before_cleanup"));
    FileUtils.copyDirectory(clientB.getConfig().getDatabaseDir(), new File(clientB.getConfig().getAppDir(), "1_before_cleanup"));
    CleanupOperationOptions cleanupMergeAndRemoveOldFiles = new CleanupOperationOptions();
    cleanupMergeAndRemoveOldFiles.setRemoveOldVersions(true);
    clientB.cleanup(cleanupMergeAndRemoveOldFiles);
    FileUtils.copyDirectory(testConnection.getPath(), new File(testConnection.getPath() + "_2_after_cleanup"));
    FileUtils.copyDirectory(clientB.getConfig().getDatabaseDir(), new File(clientB.getConfig().getAppDir(), "2_after_cleanup"));
    // <<< "Cannot determine file content for checksum X"
    clientC.down();
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
    clientC.deleteTestData();
    FileUtils.deleteDirectory(new File(testConnection.getPath() + "_1_before_cleanup"));
    FileUtils.deleteDirectory(new File(clientB.getConfig().getAppDir(), "1_before_cleanup"));
    FileUtils.deleteDirectory(new File(testConnection.getPath() + "_2_after_cleanup"));
    FileUtils.deleteDirectory(new File(clientB.getConfig().getAppDir(), "2_after_cleanup"));
}
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) StatusOperationOptions(org.syncany.operations.status.StatusOperationOptions) File(java.io.File) Test(org.junit.Test)

Example 17 with CleanupOperationOptions

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

the class CleanupInterruptedTest method testUnreliableCleanup_Test1_oldVersionRemoval.

@Test
public void testUnreliableCleanup_Test1_oldVersionRemoval() throws Exception {
    // Setup
    UnreliableLocalTransferSettings testConnection = TestConfigUtil.createTestUnreliableLocalConnection(Arrays.asList(new String[] { // << 3 retries!!
    "rel=(11|12|13).+upload.+database" }));
    TestClient clientA = new TestClient("A", testConnection);
    clientA.createNewFile("file");
    clientA.up();
    clientA.changeFile("file");
    clientA.upWithForceChecksum();
    CleanupOperationOptions cleanupOptions = new CleanupOperationOptions();
    cleanupOptions.setMinKeepSeconds(0);
    boolean cleanupFailed = false;
    try {
        clientA.cleanup(cleanupOptions);
    } catch (StorageException e) {
        cleanupFailed = true;
    }
    assertTrue(cleanupFailed);
    TransferManager transferManagerA = TransferManagerFactory.build(clientA.getConfig()).withFeature(TransactionAware.class).asDefault();
    assertEquals(2, transferManagerA.list(MultichunkRemoteFile.class).size());
    assertEquals(1, new File(testConnection.getPath(), "multichunks").list().length);
    assertEquals(2, transferManagerA.list(DatabaseRemoteFile.class).size());
    assertEquals(0, new File(testConnection.getPath(), "databases").list().length);
    assertEquals(1, transferManagerA.list(TransactionRemoteFile.class).size());
    assertEquals(1, new File(testConnection.getPath(), "transactions").list().length);
    assertEquals(1, transferManagerA.list(ActionRemoteFile.class).size());
    assertEquals(1, new File(testConnection.getPath(), "actions").list().length);
    clientA.cleanup(cleanupOptions);
    assertEquals(1, transferManagerA.list(MultichunkRemoteFile.class).size());
    assertEquals(1, new File(testConnection.getPath(), "multichunks").list().length);
    assertEquals(1, transferManagerA.list(DatabaseRemoteFile.class).size());
    assertEquals(1, new File(testConnection.getPath(), "databases").list(new FilenameFilter() {

        public boolean accept(File dir, String name) {
            return name.startsWith("database-");
        }
    }).length);
    assertEquals(0, transferManagerA.list(TransactionRemoteFile.class).size());
    assertEquals(0, new File(testConnection.getPath(), "transactions").list().length);
    assertEquals(0, transferManagerA.list(ActionRemoteFile.class).size());
    assertEquals(0, new File(testConnection.getPath(), "actions").list().length);
    clientA.deleteTestData();
}
Also used : TransferManager(org.syncany.plugins.transfer.TransferManager) FilenameFilter(java.io.FilenameFilter) TransactionAware(org.syncany.plugins.transfer.features.TransactionAware) UnreliableLocalTransferSettings(org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) CleanupOperationOptions(org.syncany.operations.cleanup.CleanupOperationOptions) StorageException(org.syncany.plugins.transfer.StorageException) RemoteFile(org.syncany.plugins.transfer.files.RemoteFile) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) TempRemoteFile(org.syncany.plugins.transfer.files.TempRemoteFile) ActionRemoteFile(org.syncany.plugins.transfer.files.ActionRemoteFile) TransactionRemoteFile(org.syncany.plugins.transfer.files.TransactionRemoteFile) File(java.io.File) MultichunkRemoteFile(org.syncany.plugins.transfer.files.MultichunkRemoteFile) Test(org.junit.Test)

Example 18 with CleanupOperationOptions

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

the class CleanupInterruptedTest method testUnreliableCleanup_failBlocksOtherClients.

@Test
public void testUnreliableCleanup_failBlocksOtherClients() throws Exception {
    // Setup
    UnreliableLocalTransferSettings testConnection = TestConfigUtil.createTestUnreliableLocalConnection(Arrays.asList(new String[] { // << 3 retries!!
    "rel=(12|13|14).+upload.+database" }));
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    clientA.createNewFile("file");
    clientA.up();
    clientA.changeFile("file");
    clientA.upWithForceChecksum();
    clientB.down();
    CleanupOperationOptions cleanupOptions = new CleanupOperationOptions();
    cleanupOptions.setMinKeepSeconds(0);
    boolean cleanupFailed = false;
    try {
        clientA.cleanup(cleanupOptions);
    } catch (StorageException e) {
        cleanupFailed = true;
    }
    assertTrue(cleanupFailed);
    // Pretend time has passed by deleting the action file:
    TestFileUtil.deleteFile(new File(testConnection.getPath(), "/actions/").listFiles()[0]);
    CleanupOperationResult cleanupResult = clientB.cleanup(cleanupOptions);
    assertEquals(CleanupResultCode.NOK_REPO_BLOCKED, cleanupResult.getResultCode());
    clientB.createNewFile("file2");
    UpOperationResult upResult = clientB.up();
    assertEquals(UpResultCode.NOK_REPO_BLOCKED, upResult.getResultCode());
    clientA.deleteTestData();
    clientB.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) StorageException(org.syncany.plugins.transfer.StorageException) RemoteFile(org.syncany.plugins.transfer.files.RemoteFile) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) TempRemoteFile(org.syncany.plugins.transfer.files.TempRemoteFile) ActionRemoteFile(org.syncany.plugins.transfer.files.ActionRemoteFile) TransactionRemoteFile(org.syncany.plugins.transfer.files.TransactionRemoteFile) File(java.io.File) MultichunkRemoteFile(org.syncany.plugins.transfer.files.MultichunkRemoteFile) UpOperationResult(org.syncany.operations.up.UpOperationResult) Test(org.junit.Test)

Example 19 with CleanupOperationOptions

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

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

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