use of org.syncany.operations.cleanup.CleanupOperationOptions in project syncany by syncany.
the class CleanupMergeDatabaseFilesScenarioTest method testIssue58_4.
@Test
public void testIssue58_4() throws Exception {
// Test for https://github.com/syncany/syncany/issues/58#issuecomment-43472118
// Setup
LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
TestClient clientC = new TestClient("C", testConnection);
CleanupOperationOptions cleanupOptionsKeep1 = new CleanupOperationOptions();
cleanupOptionsKeep1.setRemoveOldVersions(true);
StatusOperationOptions statusOptionsForceChecksum = new StatusOperationOptions();
statusOptionsForceChecksum.setForceChecksum(true);
UpOperationOptions upNoCleanupForceChecksum = new UpOperationOptions();
upNoCleanupForceChecksum.setStatusOptions(statusOptionsForceChecksum);
UpOperationOptions upWithCleanupKeep1ForceChecksum = new UpOperationOptions();
upWithCleanupKeep1ForceChecksum.setStatusOptions(statusOptionsForceChecksum);
clientB.createNewFile("fileB");
clientB.up(upNoCleanupForceChecksum);
clientA.down();
TestFileUtil.copyFile(clientB.getLocalFile("fileB"), clientA.getLocalFile("fileBcopy"));
clientA.up(upNoCleanupForceChecksum);
for (int i = 0; i < 30; i++) {
clientB.down();
clientB.changeFile("fileB");
clientB.up(upNoCleanupForceChecksum);
}
FileUtils.copyDirectory(testConnection.getPath(), new File(testConnection.getPath() + "_1_before_cleanup"));
FileUtils.copyDirectory(clientB.getConfig().getDatabaseDir(), new File(clientB.getConfig().getAppDir(), "1_before_cleanup"));
CleanupOperationOptions cleanupMergeAndRemoveOldFiles = new CleanupOperationOptions();
cleanupMergeAndRemoveOldFiles.setRemoveOldVersions(true);
clientB.cleanup(cleanupMergeAndRemoveOldFiles);
FileUtils.copyDirectory(testConnection.getPath(), new File(testConnection.getPath() + "_2_after_cleanup"));
FileUtils.copyDirectory(clientB.getConfig().getDatabaseDir(), new File(clientB.getConfig().getAppDir(), "2_after_cleanup"));
// <<< "Cannot determine file content for checksum X"
clientC.down();
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
clientC.deleteTestData();
FileUtils.deleteDirectory(new File(testConnection.getPath() + "_1_before_cleanup"));
FileUtils.deleteDirectory(new File(clientB.getConfig().getAppDir(), "1_before_cleanup"));
FileUtils.deleteDirectory(new File(testConnection.getPath() + "_2_after_cleanup"));
FileUtils.deleteDirectory(new File(clientB.getConfig().getAppDir(), "2_after_cleanup"));
}
use of org.syncany.operations.cleanup.CleanupOperationOptions in project syncany by syncany.
the class CleanupInterruptedTest method testUnreliableCleanup_Test1_oldVersionRemoval.
@Test
public void testUnreliableCleanup_Test1_oldVersionRemoval() 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.setMinKeepSeconds(0);
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(1, new File(testConnection.getPath(), "multichunks").list().length);
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);
clientA.cleanup(cleanupOptions);
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);
clientA.deleteTestData();
}
use of org.syncany.operations.cleanup.CleanupOperationOptions 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();
}
use of org.syncany.operations.cleanup.CleanupOperationOptions in project syncany by syncany.
the class CleanupOperationTest method testCleanupFailsBecauseOfLocalChanges.
@Test
public void testCleanupFailsBecauseOfLocalChanges() throws Exception {
// Setup
LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
StatusOperationOptions statusOptions = new StatusOperationOptions();
statusOptions.setForceChecksum(true);
CleanupOperationOptions cleanupOptions = new CleanupOperationOptions();
cleanupOptions.setStatusOptions(statusOptions);
cleanupOptions.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();
clientB.changeFile("file.jpg");
CleanupOperationResult cleanupOperationResult = clientB.cleanup(cleanupOptions);
assertEquals(CleanupResultCode.NOK_LOCAL_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 testCleanupManyUpsAfterCleanup.
@Test
public void testCleanupManyUpsAfterCleanup() 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
clientA.createNewFile("file.jpg");
for (int i = 1; i <= 4; i++) {
clientA.changeFile("file.jpg");
clientA.upWithForceChecksum();
}
// B: Sync down
clientB.down();
// A: Cleanup
CleanupOperationResult cleanupOperationResult = clientA.cleanup(options);
assertEquals(CleanupResultCode.OK, cleanupOperationResult.getResultCode());
assertEquals(4, cleanupOperationResult.getMergedDatabaseFilesCount());
assertEquals(3, cleanupOperationResult.getRemovedMultiChunksCount());
assertEquals(1, cleanupOperationResult.getRemovedOldVersionsCount());
// A: Continue to upload stuff ! <<<<<<<<<<<<<<<<<<<<<
for (int i = 1; i <= 4; i++) {
clientA.changeFile("file.jpg");
clientA.upWithForceChecksum();
}
clientA.createNewFile("file2.jpg");
for (int i = 1; i <= 4; i++) {
clientA.changeFile("file2.jpg");
clientA.upWithForceChecksum();
}
// B: Sync down
clientB.down();
TestAssertUtil.assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
}
Aggregations