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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations