use of org.syncany.operations.cleanup.CleanupOperationOptions.TimeUnit 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();
}
use of org.syncany.operations.cleanup.CleanupOperationOptions.TimeUnit 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();
}
use of org.syncany.operations.cleanup.CleanupOperationOptions.TimeUnit 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();
}
use of org.syncany.operations.cleanup.CleanupOperationOptions.TimeUnit in project syncany by syncany.
the class CleanupOperation method collectPurgableFileVersions.
/**
* For all time intervals defined in the purge file settings, determine the eligible file
* versions to be purged -- namely all but the newest one.
*
* @see CleanupOperation
* @see CleanupOperationOptions#getPurgeFileVersionSettings()
* @see FileVersionSqlDao#getFileHistoriesToPurgeInInterval(long, long, TimeUnit)
*/
private Map<FileHistoryId, List<FileVersion>> collectPurgableFileVersions() {
Map<FileHistoryId, List<FileVersion>> purgeFileVersions = new HashMap<FileHistoryId, List<FileVersion>>();
long currentTime = System.currentTimeMillis();
long previousTruncateIntervalTimeMultiplier = 0;
for (Map.Entry<Long, TimeUnit> purgeFileVersionSetting : options.getPurgeFileVersionSettings().entrySet()) {
Long truncateIntervalMultiplier = purgeFileVersionSetting.getKey();
TimeUnit truncateIntervalTimeUnit = purgeFileVersionSetting.getValue();
long beginIntervalTimestamp = currentTime - truncateIntervalMultiplier * 1000;
long endIntervalTimestamp = currentTime - previousTruncateIntervalTimeMultiplier * 1000;
Map<FileHistoryId, List<FileVersion>> newPurgeFileVersions = localDatabase.getFileHistoriesToPurgeInInterval(beginIntervalTimestamp, endIntervalTimestamp, truncateIntervalTimeUnit);
putAllFileVersionsInMap(newPurgeFileVersions, purgeFileVersions);
previousTruncateIntervalTimeMultiplier = truncateIntervalMultiplier;
}
return purgeFileVersions;
}
use of org.syncany.operations.cleanup.CleanupOperationOptions.TimeUnit 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();
}
Aggregations