Search in sources :

Example 6 with CleanupOperationOptions

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

the class CleanupOperationTest method testCleanupMaxDatabaseFiles.

@Test
public void testCleanupMaxDatabaseFiles() throws Exception {
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    CleanupOperationOptions options = new CleanupOperationOptions();
    options.setMinSecondsBetweenCleanups(0);
    options.setPurgeFileVersionSettings(new TreeMap<Long, TimeUnit>());
    options.setRemoveOldVersions(true);
    options.setMaxDatabaseFiles(3);
    // Run
    // A: Create some file versions
    clientA.createNewFile("file.jpg");
    for (int i = 1; i <= 4; i++) {
        clientA.changeFile("file.jpg");
        clientA.upWithForceChecksum();
    }
    // B: Cleanup
    CleanupOperationResult cleanupOperationResult = clientA.cleanup(options);
    assertEquals(CleanupResultCode.OK, cleanupOperationResult.getResultCode());
    assertEquals(4, cleanupOperationResult.getMergedDatabaseFilesCount());
    assertEquals(0, cleanupOperationResult.getRemovedMultiChunksCount());
    assertEquals(0, cleanupOperationResult.getRemovedOldVersionsCount());
    TestClient clientB = new TestClient("B", testConnection);
    clientB.down();
    // B: Create some file versions
    clientB.createNewFile("file-B.jpg");
    for (int i = 1; i <= 6; i++) {
        clientB.changeFile("file-B.jpg");
        clientB.upWithForceChecksum();
    }
    // B: Cleanup (2 clients, so 7 databases is too much)
    cleanupOperationResult = clientB.cleanup(options);
    assertEquals(CleanupResultCode.OK, cleanupOperationResult.getResultCode());
    assertEquals(7, 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 CleanupOperationOptions

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

the class CleanupOperationTest method testQuickDoubleCleanup.

@Test
public void testQuickDoubleCleanup() throws Exception {
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    CleanupOperationOptions options = new CleanupOperationOptions();
    options.setRemoveOldVersions(false);
    options.setRemoveVersionsByInterval(false);
    options.setMinSecondsBetweenCleanups(40000000);
    // Run
    // A: Create some file versions
    clientA.createNewFile("file.jpg");
    for (int i = 1; i <= 16; i++) {
        clientA.changeFile("file.jpg");
        clientA.upWithForceChecksum();
    }
    // B: Cleanup
    CleanupOperationResult cleanupOperationResult = clientA.cleanup(options);
    assertEquals(CleanupResultCode.OK, cleanupOperationResult.getResultCode());
    assertEquals(16, cleanupOperationResult.getMergedDatabaseFilesCount());
    assertEquals(0, cleanupOperationResult.getRemovedMultiChunksCount());
    assertEquals(0, cleanupOperationResult.getRemovedOldVersionsCount());
    for (int i = 1; i <= 15; i++) {
        clientA.changeFile("file.jpg");
        clientA.upWithForceChecksum();
    }
    // Because of minimum timeout, this cleanup should not do anything
    cleanupOperationResult = clientA.cleanup(options);
    assertEquals(CleanupResultCode.NOK_RECENTLY_CLEANED, cleanupOperationResult.getResultCode());
    // When force is on, the cleanup should go through
    options.setForce(true);
    cleanupOperationResult = clientA.cleanup(options);
    assertEquals(CleanupResultCode.OK, cleanupOperationResult.getResultCode());
    assertEquals(16, cleanupOperationResult.getMergedDatabaseFilesCount());
    assertEquals(0, cleanupOperationResult.getRemovedMultiChunksCount());
    assertEquals(0, cleanupOperationResult.getRemovedOldVersionsCount());
    // Tear down
    clientA.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 8 with CleanupOperationOptions

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

the class CleanupOperationTest method testCleanupFailsMidCommit.

@Test
public void testCleanupFailsMidCommit() throws Exception {
    // Setup
    UnreliableLocalTransferSettings testConnection = TestConfigUtil.createTestUnreliableLocalConnection(Arrays.asList(new String[] { // << 3 retries!
    "rel=(13|14|15).+move" }));
    TestClient clientA = new TestClient("A", testConnection);
    java.sql.Connection databaseConnectionA = clientA.getConfig().createDatabaseConnection();
    StatusOperationOptions forceChecksumStatusOperationOptions = new StatusOperationOptions();
    forceChecksumStatusOperationOptions.setForceChecksum(true);
    CleanupOperationOptions options = new CleanupOperationOptions();
    options.setStatusOptions(forceChecksumStatusOperationOptions);
    options.setRemoveOldVersions(true);
    options.setMinKeepSeconds(0);
    options.setMinSecondsBetweenCleanups(40000000);
    options.setForce(true);
    File repoDir = testConnection.getPath();
    File repoMultiChunkDir = new File(testConnection.getPath() + "/multichunks");
    File repoActionsDir = new File(testConnection.getPath() + "/actions");
    File repoDatabasesDir = new File(testConnection.getPath() + "/databases");
    File repoTransactionsDir = new File(testConnection.getPath() + "/transactions");
    File repoTemporaryDir = new File(testConnection.getPath() + "/temporary");
    // Run
    clientA.createNewFile("A-file1", 5 * 1024);
    clientA.up();
    for (int i = 0; i < 5; i++) {
        clientA.changeFile("A-file1");
        clientA.upWithForceChecksum();
    }
    assertEquals(6, repoDatabasesDir.listFiles().length);
    assertEquals(6, repoMultiChunkDir.listFiles().length);
    assertEquals(0, repoActionsDir.listFiles().length);
    assertEquals("6", TestSqlUtil.runSqlSelect("select count(*) from multichunk", databaseConnectionA));
    // Run cleanup, fails mid-move!
    boolean operationFailed = false;
    try {
        clientA.cleanup(options);
    } catch (Exception e) {
        // That is supposed to happen!
        operationFailed = true;
        e.printStackTrace();
    }
    assertTrue(operationFailed);
    assertEquals(1, repoTransactionsDir.listFiles().length);
    assertEquals(0, repoTemporaryDir.listFiles().length);
    assertEquals(6, repoDatabasesDir.listFiles().length);
    assertEquals(6, repoMultiChunkDir.listFiles().length);
    assertEquals("6", TestSqlUtil.runSqlSelect("select count(*) from multichunk", databaseConnectionA));
    // Retry
    clientA.cleanup(options);
    assertEquals(1, repoDatabasesDir.listFiles(new FilenameFilter() {

        public boolean accept(File dir, String name) {
            return name.startsWith("database-");
        }
    }).length);
    assertEquals(1, repoMultiChunkDir.listFiles().length);
    assertEquals(0, repoActionsDir.listFiles().length);
    assertEquals(0, repoDir.list(new FilenameFilter() {

        public boolean accept(File dir, String name) {
            return name.startsWith("transaction-");
        }
    }).length);
    assertEquals(0, repoDir.list(new FilenameFilter() {

        public boolean accept(File dir, String name) {
            return name.startsWith("temp-");
        }
    }).length);
    assertEquals("1", TestSqlUtil.runSqlSelect("select count(*) from multichunk", databaseConnectionA));
    // Tear down
    clientA.deleteTestData();
}
Also used : FilenameFilter(java.io.FilenameFilter) 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) File(java.io.File) Test(org.junit.Test)

Example 9 with CleanupOperationOptions

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

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

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