Search in sources :

Example 21 with CleanupOperationOptions

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

the class CleanupOperationTest method testCleanupFailsBecauseOfRemoteChanges.

@Test
public void testCleanupFailsBecauseOfRemoteChanges() 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);
    // 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: Add something
    clientA.changeFile("file.jpg");
    clientA.upWithForceChecksum();
    // B: Cleanup
    CleanupOperationResult cleanupOperationResult = clientB.cleanup(options);
    assertEquals(CleanupResultCode.NOK_REMOTE_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) Test(org.junit.Test)

Example 22 with CleanupOperationOptions

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

the class CleanupOperationTest method testFullFileVersionDeletion.

@Test
public void testFullFileVersionDeletion() throws Exception {
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    java.sql.Connection databaseConnectionA = clientA.getConfig().createDatabaseConnection();
    CleanupOperationOptions options = new CleanupOperationOptions();
    options.setRemoveOldVersions(true);
    options.setPurgeFileVersionSettings(new TreeMap<Long, TimeUnit>());
    options.setMinKeepSeconds(0);
    options.setMinSecondsBetweenCleanups(0);
    // More than a month back
    clientA.createNewFile("file.jpg", 1024);
    clientA.upWithForceChecksum();
    // Less than a month back
    clientA.changeFile("file.jpg");
    clientA.upWithForceChecksum();
    clientA.cleanup(options);
    assertEquals("1", TestSqlUtil.runSqlSelect("select count(*) from fileversion", databaseConnectionA));
    // Tear down
    clientA.deleteTestData();
}
Also used : 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 23 with CleanupOperationOptions

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

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

the class CleanupOperationTest method testFullyDeletingDeletedFiles.

@Test
public void testFullyDeletingDeletedFiles() throws Exception {
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    java.sql.Connection databaseConnectionA = clientA.getConfig().createDatabaseConnection();
    CleanupOperationOptions options = new CleanupOperationOptions();
    options.setRemoveOldVersions(true);
    options.setMinSecondsBetweenCleanups(0);
    options.setPurgeFileVersionSettings(new TreeMap<Long, TimeUnit>());
    options.setMinKeepSeconds(2);
    clientA.createNewFile("file.jpg");
    clientA.up();
    clientA.deleteFile("file.jpg");
    clientA.up();
    clientA.cleanup(options);
    assertEquals("2", TestSqlUtil.runSqlSelect("select count(*) from fileversion", databaseConnectionA));
    Thread.sleep(3000);
    clientA.cleanup(options);
    assertEquals("0", TestSqlUtil.runSqlSelect("select count(*) from fileversion", databaseConnectionA));
    // Tear down
    clientA.deleteTestData();
}
Also used : 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 25 with CleanupOperationOptions

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

the class CleanupOperationTest method testDefaultFileVersionDeletion.

@Test
public void testDefaultFileVersionDeletion() throws Exception {
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    java.sql.Connection databaseConnectionA = clientA.getConfig().createDatabaseConnection();
    CleanupOperationOptions options = new CleanupOperationOptions();
    options.setRemoveOldVersions(true);
    options.setMinSecondsBetweenCleanups(0);
    // More than a month back
    clientA.createNewFile("file.jpg", 1024);
    clientA.upWithForceChecksum();
    // Less than a month back
    clientA.changeFile("file.jpg");
    clientA.upWithForceChecksum();
    // Less than a month back, same day as above
    clientA.changeFile("file.jpg");
    clientA.upWithForceChecksum();
    // Less than 3 days back
    clientA.changeFile("file.jpg");
    clientA.upWithForceChecksum();
    // Less than 3 days back, same hour as above
    clientA.changeFile("file.jpg");
    clientA.upWithForceChecksum();
    // Less than 1 hour back
    clientA.changeFile("file.jpg");
    clientA.upWithForceChecksum();
    // Less than 1 hour back, same minute
    clientA.changeFile("file.jpg");
    clientA.upWithForceChecksum();
    long curTime = System.currentTimeMillis() / 1000L;
    long[] times = new long[] { curTime - 31L * 24L * 3600L, curTime - 20L * 24L * 3600L - 1L, curTime - 20L * 24L * 3600L, curTime - 24 * 3600L - 1L, curTime - 24L * 3600L, curTime - 500L, curTime - 499L };
    int i = 0;
    try (PreparedStatement preparedStatement = databaseConnectionA.prepareStatement("select * from fileversion")) {
        ResultSet res = preparedStatement.executeQuery();
        while (res.next()) {
            int version = res.getInt("version");
            try (PreparedStatement preparedUpdate = databaseConnectionA.prepareStatement("update fileversion set updated = ? where version = ?")) {
                System.out.println(new Timestamp(times[i] * 1000L));
                preparedUpdate.setTimestamp(1, new Timestamp(times[i] * 1000L));
                preparedUpdate.setInt(2, version);
                assertEquals(1, preparedUpdate.executeUpdate());
            }
            i++;
        }
    }
    databaseConnectionA.commit();
    assertEquals("7", TestSqlUtil.runSqlSelect("select count(*) from fileversion", databaseConnectionA));
    clientA.cleanup(options);
    assertEquals("3", TestSqlUtil.runSqlSelect("select count(*) from fileversion", databaseConnectionA));
    assertEquals("3\n5\n7", TestSqlUtil.runSqlSelect("select version from fileversion", databaseConnectionA));
    // Tear down
    clientA.deleteTestData();
}
Also used : 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) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Timestamp(java.sql.Timestamp) 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