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