use of org.syncany.operations.cleanup.CleanupOperationResult in project syncany by syncany.
the class WatchOperation method runSync.
/**
* Runs one iteration of the main synchronization loop, containing a {@link DownOperation},
* an {@link UpOperation} and (if required), a {@link CleanupOperation}.
*/
private void runSync() throws Exception {
if (!syncRunning.get()) {
syncRunning.set(true);
syncRequested.set(false);
logger.log(Level.INFO, "RUNNING SYNC ...");
fireStartEvent();
try {
boolean notifyChanges = false;
// Run down
DownOperationResult downResult = new DownOperation(config, options.getDownOptions()).execute();
if (downResult.getResultCode() == DownResultCode.OK_WITH_REMOTE_CHANGES) {
// TODO [low] Do something?
}
// Run up
UpOperationResult upOperationResult = new UpOperation(config, options.getUpOptions()).execute();
if (upOperationResult.getResultCode() == UpResultCode.OK_CHANGES_UPLOADED && upOperationResult.getChangeSet().hasChanges()) {
upCount.incrementAndGet();
notifyChanges = true;
}
CleanupOperationResult cleanupOperationResult = new CleanupOperation(config, options.getCleanupOptions()).execute();
if (cleanupOperationResult.getResultCode() == CleanupResultCode.OK) {
notifyChanges = true;
}
// Fire change event if up and/or cleanup
if (notifyChanges) {
notifyChanges();
}
} finally {
logger.log(Level.INFO, "SYNC DONE.");
syncRunning.set(false);
fireEndEvent();
}
} else {
// Can't do a log message here, because this bit is called thousand
// of times when file system events occur.
syncRequested.set(true);
}
}
use of org.syncany.operations.cleanup.CleanupOperationResult 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.CleanupOperationResult 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();
}
use of org.syncany.operations.cleanup.CleanupOperationResult in project syncany by syncany.
the class CleanupOperationTest method testCleanupAfterFailedUpOperation.
@Test
public void testCleanupAfterFailedUpOperation() throws Exception {
// Setup
UnreliableLocalTransferSettings testConnection = TestConfigUtil.createTestUnreliableLocalConnection(Arrays.asList(new String[] { // << 3 retries!
"rel=[456].+upload.+multichunk" }));
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
StatusOperationOptions forceChecksumStatusOperationOptions = new StatusOperationOptions();
forceChecksumStatusOperationOptions.setForceChecksum(true);
UpOperationOptions noCleanupAndForceUpOperationOptions = new UpOperationOptions();
noCleanupAndForceUpOperationOptions.setForceUploadEnabled(true);
noCleanupAndForceUpOperationOptions.setStatusOptions(forceChecksumStatusOperationOptions);
// Run
// 1. Call A.up(); this fails AFTER the first multichunk
clientA.createNewFile("A-file1", 5 * 1024 * 1024);
boolean operationFailed = false;
try {
clientA.up();
} catch (Exception e) {
// That is supposed to happen!
operationFailed = true;
}
File repoMultiChunkDir = new File(testConnection.getPath() + "/multichunks");
File repoActionsDir = new File(testConnection.getPath() + "/actions");
assertTrue(operationFailed);
// Atomic operation, so multichunk is not yet present at location
assertEquals(0, repoMultiChunkDir.listFiles().length);
assertEquals(1, repoActionsDir.listFiles().length);
// 2. Call A.cleanup(); this does not run, because there are local changes
CleanupOperationResult cleanupOperationResultA = clientA.cleanup();
assertEquals(CleanupResultCode.NOK_LOCAL_CHANGES, cleanupOperationResultA.getResultCode());
// 3. Call B.cleanup(); this does not run, because of the leftover 'action' file
CleanupOperationResult cleanupOperationResultB = clientB.cleanup();
assertEquals(CleanupResultCode.NOK_OTHER_OPERATIONS_RUNNING, cleanupOperationResultB.getResultCode());
// 4. Call B.down(); this does not deliver any results, because no databases have been uploaded
DownOperationResult downOperationResult = clientB.down();
assertEquals(DownResultCode.OK_NO_REMOTE_CHANGES, downOperationResult.getResultCode());
// 5. Call 'up' again, this uploads previously crashed stuff, and then runs cleanup.
// The cleanup then removes the old multichunk and the old action files.
UpOperationResult secondUpResult = clientA.up();
assertEquals(UpResultCode.OK_CHANGES_UPLOADED, secondUpResult.getResultCode());
assertEquals(2, repoMultiChunkDir.listFiles().length);
assertEquals(0, repoActionsDir.listFiles().length);
// 6. Call 'cleanup' manually (Nothing happens, since transaction was cleaned on second up)
CleanupOperationResult cleanupOperationResult = clientA.cleanup();
assertEquals(CleanupOperationResult.CleanupResultCode.OK_NOTHING_DONE, cleanupOperationResult.getResultCode());
assertEquals(0, cleanupOperationResult.getRemovedMultiChunksCount());
assertEquals(0, repoActionsDir.listFiles().length);
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
}
use of org.syncany.operations.cleanup.CleanupOperationResult 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();
}
Aggregations