use of org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings in project syncany by syncany.
the class Issue316ScenarioTest method testIssue316CleanupThenDeleteFileButLocalFileChanged.
@Test
public void testIssue316CleanupThenDeleteFileButLocalFileChanged() throws Exception {
/*
* Same test as above, but local file has changed at client B.
*/
// Setup
UnreliableLocalTransferSettings testConnection = TestConfigUtil.createTestUnreliableLocalConnection(Arrays.asList(new String[] { // << 3 retries!
"rel=(5|6|7) .+download.+multichunk" }));
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
CleanupOperationOptions cleanupOptionsKeepOne = new CleanupOperationOptions();
cleanupOptionsKeepOne.setMaxDatabaseFiles(1);
cleanupOptionsKeepOne.setForce(true);
clientA.createNewFile("Kazam_screencast_00010.mp4");
clientA.upWithForceChecksum();
clientB.down();
assertTrue(clientB.getLocalFile("Kazam_screencast_00010.mp4").exists());
// <<<<<<<<< Different from above test
clientB.changeFile("Kazam_screencast_00010.mp4");
clientA.createNewFile("SomeFileTOIncreaseTheDatabaseFileCount");
clientA.upWithForceChecksum();
CleanupOperationResult cleanupResult = clientA.cleanup(cleanupOptionsKeepOne);
assertEquals(CleanupResultCode.OK, cleanupResult.getResultCode());
clientA.deleteFile("Kazam_screencast_00010.mp4");
clientA.upWithForceChecksum();
// First 'down' of client B after the cleanup.
// This fails AFTER the local database was wiped.
boolean downFailedAtB = false;
try {
clientB.down();
} catch (Exception e) {
downFailedAtB = true;
}
assertTrue("Down operation should have failed.", downFailedAtB);
// Second 'down' of client B; This should delete the file 'Kazam_screencast_00010.mp4',
// because it matches the checksum of the 'DELETED' entry
clientB.down();
// <<<<<<<<< Different from above test
assertConflictingFileExists("Kazam_screencast_00010.mp4", clientB.getLocalFiles());
assertFalse(clientB.getLocalFile("Kazam_screencast_00010.mp4").exists());
// Tear down
clientB.deleteTestData();
clientA.deleteTestData();
}
use of org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings in project syncany by syncany.
the class FailedSplitSyncUpScenarioTest method testUpFailsOnFirstTransaction.
@Test
public void testUpFailsOnFirstTransaction() throws Exception {
// Inject failure for the second multichunk
UnreliableLocalTransferSettings testConnection = TestConfigUtil.createTestUnreliableLocalConnection(Arrays.asList("rel=[4567].+upload.+multichunk"));
TestClient clientA = new TestClient("A", testConnection);
UpOperationOptions options = new UpOperationOptions();
options.setTransactionSizeLimit(0L);
// Write three files (three transactions), with the first file spanning two multichunks
clientA.createNewFile("file1", 5 * 1024 * 1024);
clientA.createNewFile("file2", 1024);
clientA.createNewFile("file3", 1024);
// 1. Attempt upload, should fail
boolean operationFailed = false;
try {
clientA.up(options);
} catch (Exception ex) {
operationFailed = true;
}
assertTrue(operationFailed);
// 2. Verify local state
File stateDir = clientA.getConfig().getStateDir();
File cacheDir = clientA.getConfig().getCacheDir();
// Expecting: 3 transactions + 3 databases + transaction list + in-progress transaction
assertEquals(8, stateDir.listFiles().length);
// Expecting: 3 databases + 4 multichunks + in-progress transaction
assertEquals(8, cacheDir.listFiles().length);
// 3. Verify remote state
File repoActionsDir = new File(testConnection.getPath() + "/actions");
File repoDatabasesDir = new File(testConnection.getPath() + "/databases");
File repoMultichunksDir = new File(testConnection.getPath() + "/multichunks");
File repoTemporaryDir = new File(testConnection.getPath() + "/temporary");
File repoTransactionsDir = new File(testConnection.getPath() + "/transactions");
// Expecting that no databases/multichunks have been committed, 1 multichunk is temporary, 1 action and transaction are pending
assertEquals("One pending action should exist in repo", 1, repoActionsDir.listFiles().length);
assertEquals("No database should be committed in repo", 0, repoDatabasesDir.listFiles().length);
assertEquals("No multichunk should be committed in repo", 0, repoMultichunksDir.listFiles().length);
assertEquals("One multichunk should exist in repo as temporary", 1, repoTemporaryDir.listFiles().length);
assertEquals("One pending transaction should exist in repo", 1, repoTransactionsDir.listFiles().length);
// 4. Resume operation
clientA.up();
// 5. Final state should be as if no failure occurred; three database versions, three complete files
assertEquals("Three databases should be committed in repo", 3, repoDatabasesDir.listFiles().length);
for (int fileNumber = 1; fileNumber <= 3; fileNumber++) {
DatabaseRemoteFile databaseRemoteFile = new DatabaseRemoteFile("A", fileNumber);
File databaseFile = new File(testConnection.getPath() + "/databases/" + databaseRemoteFile.getName());
assertTrue("Database file should exist: " + databaseFile, databaseFile.exists());
}
assertEquals("Four multichunks should be committed in repo", 4, repoMultichunksDir.listFiles().length);
// Tear down
clientA.deleteTestData();
}
use of org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings in project syncany by syncany.
the class CleanupOperationTest method testCleanupFailsMidCommit.
@Test
public void testCleanupFailsMidCommit() throws Exception {
// Setup
UnreliableLocalTransferSettings testConnection = TestConfigUtil.createTestUnreliableLocalConnection(Arrays.asList(new String[] { // << 3 retries!
"rel=(13|14|15).+move" }));
TestClient clientA = new TestClient("A", testConnection);
java.sql.Connection databaseConnectionA = clientA.getConfig().createDatabaseConnection();
StatusOperationOptions forceChecksumStatusOperationOptions = new StatusOperationOptions();
forceChecksumStatusOperationOptions.setForceChecksum(true);
CleanupOperationOptions options = new CleanupOperationOptions();
options.setStatusOptions(forceChecksumStatusOperationOptions);
options.setRemoveOldVersions(true);
options.setMinKeepSeconds(0);
options.setMinSecondsBetweenCleanups(40000000);
options.setForce(true);
File repoDir = testConnection.getPath();
File repoMultiChunkDir = new File(testConnection.getPath() + "/multichunks");
File repoActionsDir = new File(testConnection.getPath() + "/actions");
File repoDatabasesDir = new File(testConnection.getPath() + "/databases");
File repoTransactionsDir = new File(testConnection.getPath() + "/transactions");
File repoTemporaryDir = new File(testConnection.getPath() + "/temporary");
// Run
clientA.createNewFile("A-file1", 5 * 1024);
clientA.up();
for (int i = 0; i < 5; i++) {
clientA.changeFile("A-file1");
clientA.upWithForceChecksum();
}
assertEquals(6, repoDatabasesDir.listFiles().length);
assertEquals(6, repoMultiChunkDir.listFiles().length);
assertEquals(0, repoActionsDir.listFiles().length);
assertEquals("6", TestSqlUtil.runSqlSelect("select count(*) from multichunk", databaseConnectionA));
// Run cleanup, fails mid-move!
boolean operationFailed = false;
try {
clientA.cleanup(options);
} catch (Exception e) {
// That is supposed to happen!
operationFailed = true;
e.printStackTrace();
}
assertTrue(operationFailed);
assertEquals(1, repoTransactionsDir.listFiles().length);
assertEquals(0, repoTemporaryDir.listFiles().length);
assertEquals(6, repoDatabasesDir.listFiles().length);
assertEquals(6, repoMultiChunkDir.listFiles().length);
assertEquals("6", TestSqlUtil.runSqlSelect("select count(*) from multichunk", databaseConnectionA));
// Retry
clientA.cleanup(options);
assertEquals(1, repoDatabasesDir.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.startsWith("database-");
}
}).length);
assertEquals(1, repoMultiChunkDir.listFiles().length);
assertEquals(0, repoActionsDir.listFiles().length);
assertEquals(0, repoDir.list(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.startsWith("transaction-");
}
}).length);
assertEquals(0, repoDir.list(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.startsWith("temp-");
}
}).length);
assertEquals("1", TestSqlUtil.runSqlSelect("select count(*) from multichunk", databaseConnectionA));
// Tear down
clientA.deleteTestData();
}
use of org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings 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.plugins.unreliable_local.UnreliableLocalTransferSettings 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();
}
Aggregations