Search in sources :

Example 6 with CleanupOperationResult

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

the class CleanupOperationTest method testCleanupNoChanges.

@Test
public void testCleanupNoChanges() 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.setPurgeFileVersionSettings(new TreeMap<Long, TimeUnit>());
    // 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();
    // B: Cleanup
    CleanupOperationResult cleanupOperationResult = clientB.cleanup(options);
    assertEquals(CleanupResultCode.OK_NOTHING_DONE, 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) TimeUnit(org.syncany.operations.cleanup.CleanupOperationOptions.TimeUnit) Test(org.junit.Test)

Example 7 with CleanupOperationResult

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

the class CleanupOperationTest method testEasyCleanup.

@Test
public void testEasyCleanup() 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
    // These two files' chunks will be in one multichunk
    clientA.createNewFile("someotherfile.jpg");
    // Only one of the chunks will be needed after cleanup!
    clientA.createNewFile("file.jpg");
    // The multichunk will be 50% useless
    for (int i = 1; i <= 4; i++) {
        clientA.changeFile("file.jpg");
        clientA.upWithForceChecksum();
    }
    clientA.createNewFile("otherfile.txt");
    for (int i = 1; i <= 3; i++) {
        clientA.changeFile("otherfile.txt");
        clientA.upWithForceChecksum();
    }
    clientA.createNewFile("deletedfile.txt");
    for (int i = 1; i <= 3; i++) {
        clientA.changeFile("deletedfile.txt");
        clientA.upWithForceChecksum();
    }
    clientA.deleteFile("deletedfile.txt");
    clientA.upWithForceChecksum();
    java.sql.Connection databaseConnectionA = DatabaseConnectionFactory.createConnection(clientA.getDatabaseFile(), false);
    assertEquals("12", TestSqlUtil.runSqlSelect("select count(*) from fileversion", databaseConnectionA));
    assertEquals("11", TestSqlUtil.runSqlSelect("select count(*) from chunk", databaseConnectionA));
    assertEquals("10", TestSqlUtil.runSqlSelect("select count(*) from multichunk", databaseConnectionA));
    assertEquals("11", TestSqlUtil.runSqlSelect("select count(*) from filecontent", databaseConnectionA));
    assertEquals("4", TestSqlUtil.runSqlSelect("select count(distinct id) from filehistory", databaseConnectionA));
    // B: Sync down by other client
    clientB.down();
    java.sql.Connection databaseConnectionB = DatabaseConnectionFactory.createConnection(clientB.getDatabaseFile(), false);
    assertEquals("12", TestSqlUtil.runSqlSelect("select count(*) from fileversion", databaseConnectionB));
    assertEquals("11", TestSqlUtil.runSqlSelect("select count(*) from chunk", databaseConnectionB));
    assertEquals("10", TestSqlUtil.runSqlSelect("select count(*) from multichunk", databaseConnectionB));
    assertEquals("11", TestSqlUtil.runSqlSelect("select count(*) from filecontent", databaseConnectionB));
    assertEquals("4", TestSqlUtil.runSqlSelect("select count(distinct id) from filehistory", databaseConnectionB));
    // A: Cleanup this mess (except for two) <<<< This is the interesting part!!! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    CleanupOperationResult cleanupOperationResult = clientA.cleanup(options);
    assertEquals(CleanupResultCode.OK, cleanupOperationResult.getResultCode());
    assertEquals(11, cleanupOperationResult.getMergedDatabaseFilesCount());
    assertEquals(7, cleanupOperationResult.getRemovedMultiChunksCount());
    assertEquals(4, cleanupOperationResult.getRemovedOldVersionsCount());
    // 1 version for "file.jpg", 1 versions for "otherfile.txt" and 1 version for "someotherfile.jpg"
    assertEquals("3", TestSqlUtil.runSqlSelect("select count(*) from fileversion", databaseConnectionA));
    // 4
    assertEquals("4", TestSqlUtil.runSqlSelect("select sum(version) from fileversion where path='file.jpg'", databaseConnectionA));
    // 3
    assertEquals("3", TestSqlUtil.runSqlSelect("select sum(version) from fileversion where path='otherfile.txt'", databaseConnectionA));
    assertEquals("1", TestSqlUtil.runSqlSelect("select sum(version) from fileversion where path='someotherfile.jpg'", databaseConnectionA));
    // 3 chunks remain; one was obsolete so we removed it!
    assertEquals("3", TestSqlUtil.runSqlSelect("select count(*) from chunk", databaseConnectionA));
    // 3 chunks in 3 multichunks
    assertEquals("3", TestSqlUtil.runSqlSelect("select count(*) from multichunk", databaseConnectionA));
    assertEquals("3", TestSqlUtil.runSqlSelect("select count(*) from filecontent", databaseConnectionA));
    assertEquals("3", TestSqlUtil.runSqlSelect("select count(distinct id) from filehistory", databaseConnectionA));
    // Test the repo
    assertEquals(3, new File(testConnection.getPath() + "/multichunks/").list().length);
    assertEquals(1, new File(testConnection.getPath() + "/databases/").list(new FilenameFilter() {

        public boolean accept(File dir, String name) {
            return name.startsWith("database-");
        }
    }).length);
    // B: Sync down cleanup
    clientB.down();
    TestAssertUtil.assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : CleanupOperationResult(org.syncany.operations.cleanup.CleanupOperationResult) FilenameFilter(java.io.FilenameFilter) 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) File(java.io.File) Test(org.junit.Test)

Example 8 with CleanupOperationResult

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

the class CleanupInterruptedTest method testUnreliableCleanup_Test2_databaseFileMerge.

@Test
public void testUnreliableCleanup_Test2_databaseFileMerge() 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.setMaxDatabaseFiles(1);
    cleanupOptions.setPurgeFileVersionSettings(new TreeMap<Long, TimeUnit>());
    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(2, new File(testConnection.getPath(), "multichunks").list().length);
    // Note that the list here differs from the actual files, because the transaction fails
    // while deletions have been done
    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);
    File tempDir = TestFileUtil.createTempDirectoryInSystemTemp();
    File tempFile = File.createTempFile("multichunk", "", tempDir);
    for (RemoteFile remoteFile : transferManagerA.list(DatabaseRemoteFile.class).values()) {
        transferManagerA.download(remoteFile, tempFile);
        assertTrue(tempFile.exists());
        tempFile.delete();
    }
    // Cleanup should have merged the two files.
    CleanupOperationResult result = clientA.cleanup(cleanupOptions);
    assertEquals(CleanupResultCode.OK, result.getResultCode());
    assertEquals(2, result.getMergedDatabaseFilesCount());
    assertEquals(2, transferManagerA.list(MultichunkRemoteFile.class).size());
    assertEquals(2, 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) CleanupOperationResult(org.syncany.operations.cleanup.CleanupOperationResult) CleanupOperationOptions(org.syncany.operations.cleanup.CleanupOperationOptions) FilenameFilter(java.io.FilenameFilter) TransactionAware(org.syncany.plugins.transfer.features.TransactionAware) UnreliableLocalTransferSettings(org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) TimeUnit(org.syncany.operations.cleanup.CleanupOperationOptions.TimeUnit) 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) 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) MultichunkRemoteFile(org.syncany.plugins.transfer.files.MultichunkRemoteFile) Test(org.junit.Test)

Example 9 with CleanupOperationResult

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

the class CleanupInterruptedTest method testUnreliableCleanup_Test3_unreferencedTempFiles.

@Test
public void testUnreliableCleanup_Test3_unreferencedTempFiles() throws Exception {
    // Setup
    UnreliableLocalTransferSettings testConnection = TestConfigUtil.createTestUnreliableLocalConnection(Arrays.asList(new String[] { // << 3 retries!!
    "rel=[678].+delete.+temp" }));
    TestClient clientA = new TestClient("A", testConnection);
    clientA.createNewFile("file");
    clientA.up();
    clientA.changeFile("file");
    clientA.upWithForceChecksum();
    CleanupOperationOptions cleanupOptions = new CleanupOperationOptions();
    cleanupOptions.setMinSecondsBetweenCleanups(0);
    cleanupOptions.setMinKeepSeconds(0);
    clientA.cleanup(cleanupOptions);
    TransferManager transferManagerA = TransferManagerFactory.build(clientA.getConfig()).withFeature(TransactionAware.class).asDefault();
    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);
    // One deletion failed
    assertEquals(1, transferManagerA.list(TempRemoteFile.class).size());
    assertEquals(1, new File(testConnection.getPath(), "temporary").list().length);
    // Change something to trigger cleanup
    clientA.changeFile("file");
    clientA.up();
    CleanupOperationResult result = clientA.cleanup(cleanupOptions);
    // Functional cleanup results in removal of action file and unreferenced files
    assertEquals(0, transferManagerA.list(ActionRemoteFile.class).size());
    assertEquals(0, new File(testConnection.getPath(), "actions").list().length);
    assertEquals(0, transferManagerA.list(TempRemoteFile.class).size());
    assertEquals(0, new File(testConnection.getPath(), "temporary").list().length);
    clientA.deleteTestData();
}
Also used : TransferManager(org.syncany.plugins.transfer.TransferManager) FilenameFilter(java.io.FilenameFilter) CleanupOperationResult(org.syncany.operations.cleanup.CleanupOperationResult) 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) 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 10 with CleanupOperationResult

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

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