use of org.syncany.operations.up.UpOperationOptions 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.operations.up.UpOperationOptions in project syncany by syncany.
the class CleanupMergeDatabaseFilesScenarioTest method testIssue58_2.
@Test
public void testIssue58_2() throws Exception {
/*
* This is the attempt to reproduce issue #58 https://github.com/syncany/syncany/issues/58
*/
// Setup
LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
TestClient clientC = new TestClient("C", testConnection);
java.sql.Connection databaseConnectionA = DatabaseConnectionFactory.createConnection(clientA.getDatabaseFile(), false);
java.sql.Connection databaseConnectionB = DatabaseConnectionFactory.createConnection(clientB.getDatabaseFile(), false);
CleanupOperationOptions options = new CleanupOperationOptions();
options.setRemoveOldVersions(true);
options.setMinSecondsBetweenCleanups(0);
options.setMaxDatabaseFiles(7);
StatusOperationOptions statusOptionsForceChecksum = new StatusOperationOptions();
statusOptionsForceChecksum.setForceChecksum(true);
UpOperationOptions upOperationOptionsWithCleanupForce = new UpOperationOptions();
upOperationOptionsWithCleanupForce.setStatusOptions(statusOptionsForceChecksum);
upOperationOptionsWithCleanupForce.setForceUploadEnabled(true);
// Run preparations
clientA.down();
clientA.createNewFile("A-file.jpg");
// (A1)
clientA.up(upOperationOptionsWithCleanupForce);
clientA.down();
clientA.changeFile("A-file.jpg");
// (A2)
clientA.up(upOperationOptionsWithCleanupForce);
clientB.down();
clientB.changeFile("A-file.jpg");
// (A2,B1)
clientB.up(upOperationOptionsWithCleanupForce);
clientA.down();
clientA.changeFile("A-file.jpg");
// (A3,B1)
clientA.up(upOperationOptionsWithCleanupForce);
clientA.down();
clientA.changeFile("A-file.jpg");
// (A4,B1)
clientA.up(upOperationOptionsWithCleanupForce);
clientB.down();
clientB.changeFile("A-file.jpg");
// (A4,B2) + (A4,B3) [PURGE]
clientB.up(upOperationOptionsWithCleanupForce);
clientB.cleanup(options);
clientC.down();
clientA.down();
clientA.changeFile("A-file.jpg");
// (A5,B3) + (A6,B3) [PURGE]
clientA.up(upOperationOptionsWithCleanupForce);
clientA.cleanup(options);
clientB.down();
clientB.changeFile("A-file.jpg");
// (A6,B4) + (A6,B5) [PURGE]
clientB.up(upOperationOptionsWithCleanupForce);
clientB.cleanup(options);
/*
* For some reason, this chunk checksum in the following commit is the reason for the exception. So we record it here to see where it vanishes
* from the databases.
*/
clientA.down();
clientA.changeFile("A-file.jpg");
String fileAndChunkChecksumThatRaisesException = StringUtil.toHex(TestFileUtil.createChecksum(clientA.getLocalFile("A-file.jpg")));
System.out.println("Chunk/File checksum that raises the issue: " + fileAndChunkChecksumThatRaisesException);
clientA.createNewFile("ADDED_IN_DBV_A7_B5");
// (A7,B5) + (A8,B5) [PURGE]
clientA.up(upOperationOptionsWithCleanupForce);
clientA.cleanup(options);
assertEquals("1", TestSqlUtil.runSqlSelect("select count(*) from chunk where checksum='" + fileAndChunkChecksumThatRaisesException + "'", databaseConnectionA));
clientB.down();
clientB.changeFile("A-file.jpg");
// (A8,B6) + (A8,B7) [PURGE]
clientB.up(upOperationOptionsWithCleanupForce);
clientB.cleanup(options);
assertEquals("0", TestSqlUtil.runSqlSelect("select count(*) from chunk where checksum='" + fileAndChunkChecksumThatRaisesException + "'", databaseConnectionB));
clientA.down();
clientA.changeFile("A-file.jpg");
// (A9,B7) + (A10,B7) [PURGE]
clientA.up(upOperationOptionsWithCleanupForce);
clientA.cleanup(options);
assertEquals("0", TestSqlUtil.runSqlSelect("select count(*) from chunk where checksum='" + fileAndChunkChecksumThatRaisesException + "'", databaseConnectionA));
clientB.down();
clientB.changeFile("A-file.jpg");
// (A10,B8) + (A10,B9) [PURGE]
clientB.up(upOperationOptionsWithCleanupForce);
clientB.cleanup(options);
assertEquals("0", TestSqlUtil.runSqlSelect("select count(*) from chunk where checksum='" + fileAndChunkChecksumThatRaisesException + "'", databaseConnectionB));
clientB.down();
clientB.changeFile("A-file.jpg");
// (A10,B10) + (A10,B11) [PURGE]
clientB.up(upOperationOptionsWithCleanupForce);
clientB.cleanup(options);
assertEquals("0", TestSqlUtil.runSqlSelect("select count(*) from chunk where checksum='" + fileAndChunkChecksumThatRaisesException + "'", databaseConnectionB));
clientA.down();
clientA.changeFile("A-file.jpg");
// (A11,B11) + (A12,B11) [PURGE]
clientA.up(upOperationOptionsWithCleanupForce);
clientA.cleanup(options);
clientA.down();
clientA.changeFile("A-file.jpg");
// (A13,B11) + (A14,B11) [PURGE]
clientA.up(upOperationOptionsWithCleanupForce);
clientA.cleanup(options);
clientB.down();
clientB.changeFile("A-file.jpg");
// (A14,B12) + (A14,B13) [PURGE]
clientB.up(upOperationOptionsWithCleanupForce);
clientB.cleanup(options);
clientA.down();
clientA.changeFile("A-file.jpg");
// (A15,B13) + (A16,B13) [PURGE]
clientA.up(upOperationOptionsWithCleanupForce);
clientA.cleanup(options);
clientA.down();
clientA.changeFile("A-file.jpg");
// (A17,B13) + (A18,B13) [PURGE]
clientA.up(upOperationOptionsWithCleanupForce);
clientA.cleanup(options);
// Sync them up
clientA.down();
clientB.down();
assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
// Run
// <<< Here is/was the issue: Client C failed when downloading
clientC.down();
assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientC.getDatabaseFile());
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
clientC.deleteTestData();
}
use of org.syncany.operations.up.UpOperationOptions 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.up.UpOperationOptions in project syncany by syncany.
the class DirtyDatabaseVersionsScenarioTest method testRemoveDirtyLostMultiChunksIssue132_2.
@Test
public void testRemoveDirtyLostMultiChunksIssue132_2() throws Exception {
/*
* This test tries to provoke issue #132, i.e. the deletion of
* multichunks of DIRTY database versions of other clients.
*/
// Setup
LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
UpOperationOptions upOptionsWithForce = new UpOperationOptions();
upOptionsWithForce.setForceUploadEnabled(true);
// Run
// Round 1
clientA.createNewFile("file1.jpg");
clientA.up();
clientB.down();
clientB.createNewFile("file2.jpg");
clientB.up();
clientA.createNewFile("file3.jpg");
// No 'down' (creates dirty version)
clientA.up(upOptionsWithForce);
// Download A's version, realize it's muddy (= dirty by other client)
clientB.down();
assertSqlResultEquals(clientB.getDatabaseFile(), "select count(*) from multichunk_muddy", "1");
assertEquals(3, new File(testConnection.getPath(), "multichunks").listFiles().length);
// <<< This should NOT delete any lost multichunks of DIRTY database versions!
clientB.cleanup();
assertEquals(3, new File(testConnection.getPath(), "multichunks").listFiles().length);
// Round 2
clientA.createNewFile("file4.jpg");
// This creates ANOTHER dirty version remotely!
clientA.up(upOptionsWithForce);
// Download A's version, realize it's muddy (= dirty by other client)
clientB.down();
assertSqlResultEquals(clientB.getDatabaseFile(), "select count(*) from multichunk_muddy", "2");
assertEquals(4, new File(testConnection.getPath(), "multichunks").listFiles().length);
// <<< This should NOT delete any lost multichunks of DIRTY database versions!
clientB.cleanup();
assertEquals(4, new File(testConnection.getPath(), "multichunks").listFiles().length);
// Adds dirty databases
clientA.down();
assertSqlResultEquals(clientA.getDatabaseFile(), "select count(*) from databaseversion where status='DIRTY'", "2");
clientA.up();
assertSqlResultEquals(clientA.getDatabaseFile(), "select count(*) from databaseversion where status='DIRTY'", "0");
clientB.down();
assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
assertSqlResultEquals(clientB.getDatabaseFile(), "select count(*) from multichunk_muddy", "0");
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
}
use of org.syncany.operations.up.UpOperationOptions in project syncany by syncany.
the class UploadInterruptedTest method testUnreliableUpload_FailOnceThenResume.
@Test
public void testUnreliableUpload_FailOnceThenResume() throws Exception {
// Setup
UnreliableLocalTransferSettings testConnection = TestConfigUtil.createTestUnreliableLocalConnection(Arrays.asList(new String[] { // << 3 retries!!
"rel=[345] .+upload.+multichunk" }));
TestClient clientA = new TestClient("A", testConnection);
clientA.createNewFile("file-1.txt");
boolean failed = false;
try {
clientA.up();
} catch (StorageException e) {
failed = true;
}
assertTrue(failed);
TestClient clientB = new TestClient("B", testConnection);
clientB.down();
assertEquals(0, clientB.getLocalFiles().size());
UpOperationOptions upOptions = new UpOperationOptions();
upOptions.setResume(true);
upOptions.setForceUploadEnabled(true);
clientA.up(upOptions);
clientB.down();
assertEquals(1, clientB.getLocalFiles().size());
assertTrue(clientB.getLocalFile("file-1.txt").exists());
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
}
Aggregations