use of org.syncany.operations.up.UpOperationOptions in project syncany by syncany.
the class CleanupMergeDatabaseFilesScenarioTest method testIssue58_3.
@Test
public void testIssue58_3() throws Exception {
// 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);
clientA.createNewFile("fileA");
clientB.createNewFile("fileB");
clientA.up(upNoCleanupForceChecksum);
clientB.down();
TestFileUtil.copyFile(clientA.getLocalFile("fileA"), clientB.getLocalFile("fileB"));
String problemChecksum = StringUtil.toHex(FileUtil.createChecksum(clientA.getLocalFile("fileA"), "SHA1"));
clientB.up(upNoCleanupForceChecksum);
for (int i = 0; i < 20; i++) {
clientA.down();
clientA.changeFile("fileA");
clientA.up(upNoCleanupForceChecksum);
clientB.down();
clientB.changeFile("fileB");
clientB.up(upNoCleanupForceChecksum);
}
System.out.println("Problem checksum: " + problemChecksum);
clientB.cleanup();
clientA.down();
clientA.cleanup();
clientA.down();
clientC.down();
// 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_5.
@Test
public void testIssue58_5() 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);
TestClient clientD = new TestClient("D", testConnection);
TestClient clientE = new TestClient("E", 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);
// First round
clientB.createNewFile("fileA");
clientB.up(upNoCleanupForceChecksum);
clientA.down();
TestFileUtil.copyFile(clientA.getLocalFile("fileA"), clientA.getLocalFile("fileAcopy"));
clientA.up(upNoCleanupForceChecksum);
clientA.down();
for (int i = 0; i < 30; i++) {
clientA.down();
clientA.changeFile("fileA");
clientA.up(upNoCleanupForceChecksum);
}
// First cleanup
FileUtils.copyDirectory(testConnection.getPath(), new File(testConnection.getPath() + "_1_before_cleanup"));
FileUtils.copyDirectory(clientA.getConfig().getDatabaseDir(), new File(clientA.getConfig().getAppDir(), "1_before_cleanup"));
CleanupOperationOptions cleanupMergeAndRemoveOldFiles = new CleanupOperationOptions();
cleanupMergeAndRemoveOldFiles.setRemoveOldVersions(true);
clientA.cleanup(cleanupMergeAndRemoveOldFiles);
FileUtils.copyDirectory(testConnection.getPath(), new File(testConnection.getPath() + "_2_after_cleanup"));
FileUtils.copyDirectory(clientA.getConfig().getDatabaseDir(), new File(clientA.getConfig().getAppDir(), "2_after_cleanup"));
// If this doesn't crash that's a win!
clientC.down();
for (int i = 0; i < 30; i++) {
clientB.down();
clientB.changeFile("fileA");
clientB.up(upNoCleanupForceChecksum);
}
// Second cleanup
FileUtils.copyDirectory(testConnection.getPath(), new File(testConnection.getPath() + "_3_before_cleanup"));
FileUtils.copyDirectory(clientB.getConfig().getDatabaseDir(), new File(clientB.getConfig().getAppDir(), "3_before_cleanup"));
clientB.cleanup(cleanupMergeAndRemoveOldFiles);
FileUtils.copyDirectory(testConnection.getPath(), new File(testConnection.getPath() + "_4_after_cleanup"));
FileUtils.copyDirectory(clientB.getConfig().getDatabaseDir(), new File(clientB.getConfig().getAppDir(), "4_after_cleanup"));
// If this doesn't crash that's a win!
clientD.down();
for (int i = 0; i < 30; i++) {
clientB.down();
clientB.changeFile("fileA");
clientB.up(upNoCleanupForceChecksum);
}
// < Remove original checksum from first DBV
clientB.deleteFile("fileAcopy");
clientB.up(upNoCleanupForceChecksum);
// Third cleanup
FileUtils.copyDirectory(testConnection.getPath(), new File(testConnection.getPath() + "_5_before_cleanup"));
FileUtils.copyDirectory(clientB.getConfig().getDatabaseDir(), new File(clientB.getConfig().getAppDir(), "5_before_cleanup"));
clientB.cleanup(cleanupMergeAndRemoveOldFiles);
FileUtils.copyDirectory(testConnection.getPath(), new File(testConnection.getPath() + "_6_after_cleanup"));
FileUtils.copyDirectory(clientB.getConfig().getDatabaseDir(), new File(clientB.getConfig().getAppDir(), "6_after_cleanup"));
// If this doesn't crash that's a win!
clientE.down();
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
clientC.deleteTestData();
clientD.deleteTestData();
clientE.deleteTestData();
FileUtils.deleteDirectory(new File(testConnection.getPath() + "_1_before_cleanup"));
FileUtils.deleteDirectory(new File(clientA.getConfig().getAppDir(), "1_before_cleanup"));
FileUtils.deleteDirectory(new File(testConnection.getPath() + "_2_after_cleanup"));
FileUtils.deleteDirectory(new File(clientA.getConfig().getAppDir(), "2_after_cleanup"));
FileUtils.deleteDirectory(new File(testConnection.getPath() + "_3_before_cleanup"));
FileUtils.deleteDirectory(new File(clientB.getConfig().getAppDir(), "3_before_cleanup"));
FileUtils.deleteDirectory(new File(testConnection.getPath() + "_4_after_cleanup"));
FileUtils.deleteDirectory(new File(clientB.getConfig().getAppDir(), "4_after_cleanup"));
FileUtils.deleteDirectory(new File(testConnection.getPath() + "_5_before_cleanup"));
FileUtils.deleteDirectory(new File(clientB.getConfig().getAppDir(), "5_before_cleanup"));
FileUtils.deleteDirectory(new File(testConnection.getPath() + "_6_after_cleanup"));
FileUtils.deleteDirectory(new File(clientB.getConfig().getAppDir(), "6_after_cleanup"));
}
use of org.syncany.operations.up.UpOperationOptions in project syncany by syncany.
the class CleanupMergeDatabaseFilesScenarioTest method testCleanupMergeDatabaseFilesScenario1.
@Test
public void testCleanupMergeDatabaseFilesScenario1() throws Exception {
// 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 cleanupOptionsOnlyMergeDatabases = new CleanupOperationOptions();
cleanupOptionsOnlyMergeDatabases.setRemoveOldVersions(false);
UpOperationOptions upOperationOptionsNoCleanup = new UpOperationOptions();
upOperationOptionsNoCleanup.setForceUploadEnabled(true);
// Run preparations
int[] clientUpSequence = new int[] { // 16x "1", merge happens after 15!
1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
for (int i = 0; i < clientUpSequence.length; i++) {
if (clientUpSequence[i] == 1) {
clientA.down();
clientA.createNewFile("A-file" + i + ".jpg", i);
clientA.up(upOperationOptionsNoCleanup);
} else {
clientB.down();
clientB.createNewFile("B-file" + i + ".jpg", i);
clientB.up(upOperationOptionsNoCleanup);
}
}
clientA.cleanup();
clientA.down();
clientB.down();
assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
// Make sure the "merge" process actually happened
assertFalse(new File(testConnection.getPath(), "databases/database-A-0000000001").exists());
assertFalse(new File(testConnection.getPath(), "databases/database-A-0000000005").exists());
assertFalse(new File(testConnection.getPath(), "databases/database-A-0000000010").exists());
assertFalse(new File(testConnection.getPath(), "databases/database-A-0000000030").exists());
assertFalse(new File(testConnection.getPath(), "databases/database-A-0000000031").exists());
assertTrue(new File(testConnection.getPath(), "databases/database-A-0000000032").exists());
// 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 DirtyDatabaseScenarioTest method testDirtyCleanupDirty.
@Test
public void testDirtyCleanupDirty() throws Exception {
// Setup
TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
TestClient clientC = new TestClient("C", testConnection);
TestClient clientD = new TestClient("D", testConnection);
StatusOperationOptions statusOptions = new StatusOperationOptions();
statusOptions.setForceChecksum(true);
UpOperationOptions upOptionsForceEnabled = new UpOperationOptions();
upOptionsForceEnabled.setStatusOptions(statusOptions);
upOptionsForceEnabled.setForceUploadEnabled(true);
CleanupOperationOptions cleanupOptions = new CleanupOperationOptions();
cleanupOptions.setMinSecondsBetweenCleanups(0);
cleanupOptions.setForce(true);
// Run
//// 1. CREATE FIRST DIRTY VERSION
clientA.createNewFile("A-file1.jpg", 50 * 1024);
// (A1)
clientA.up(upOptionsForceEnabled);
clientB.down();
clientB.changeFile("A-file1.jpg");
// (A1,B1)
clientB.up(upOptionsForceEnabled);
clientA.down();
// conflict (winner)
clientA.changeFile("A-file1.jpg");
// (A2,B1)
clientA.up(upOptionsForceEnabled);
// conflict (loser)
clientB.changeFile("A-file1.jpg");
clientB.up(upOptionsForceEnabled);
// don't care about the conflict, just continue
clientA.createNewFolder("new folder at A");
// (A3,B1)
clientA.up(upOptionsForceEnabled);
// don't care about the conflict, just continue
clientB.createNewFolder("new folder at B");
clientB.up(upOptionsForceEnabled);
// resolve conflict (wins, no DIRTY)
clientA.down();
java.sql.Connection databaseConnectionA = DatabaseConnectionFactory.createConnection(clientA.getDatabaseFile(), false);
assertEquals("0", TestSqlUtil.runSqlSelect("select count(*) from databaseversion where status='DIRTY'", databaseConnectionA));
// resolve conflict (loses, creates DIRTY version)
clientB.down();
java.sql.Connection databaseConnectionB = DatabaseConnectionFactory.createConnection(clientB.getDatabaseFile(), false);
assertEquals("2", TestSqlUtil.runSqlSelect("select count(*) from databaseversion where status='DIRTY'", databaseConnectionB));
assertEquals("(A1,B2)\n(A1,B3)", TestSqlUtil.runSqlSelect("select vectorclock_serialized from databaseversion where status='DIRTY' order by id", databaseConnectionB));
assertEquals("(A1)\n(A1,B1)\n(A2,B1)\n(A3,B1)", TestSqlUtil.runSqlSelect("select vectorclock_serialized from databaseversion where status<>'DIRTY' order by id", databaseConnectionB));
StatusOperationResult statusResultBAfterDirty = clientB.status();
assertNotNull(statusResultBAfterDirty);
ChangeSet changeSetBAfterDirty = statusResultBAfterDirty.getChangeSet();
assertEquals(2, changeSetBAfterDirty.getNewFiles().size());
TestAssertUtil.assertConflictingFileExists("A-file1.jpg", clientB.getLocalFiles());
// (A3,B2)
clientB.up(upOptionsForceEnabled);
assertEquals("0", TestSqlUtil.runSqlSelect("select count(*) from databaseversion where status='DIRTY'", databaseConnectionB));
// (A1), (A1,B1), (A2,B1), (A3,B1)
assertEquals("4", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));
assertEquals("(A1)\n(A1,B1)\n(A2,B1)\n(A3,B1)", TestSqlUtil.runSqlSelect("select vectorclock_serialized from databaseversion order by id", databaseConnectionA));
assertEquals("5", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionB));
assertEquals("(A1)\n(A1,B1)\n(A2,B1)\n(A3,B1)\n(A3,B4)", TestSqlUtil.runSqlSelect("select vectorclock_serialized from databaseversion order by id", databaseConnectionB));
//// 2. NOW THAT CLIENT B RESOLVED IT, A GETS DIRTY
// No 'down'! This version will become DIRTY
clientA.changeFile("A-file1.jpg");
clientA.createNewFile("dirty1");
clientA.up(upOptionsForceEnabled);
// No 'down'! This version will become DIRTY
clientA.changeFile("A-file1.jpg");
clientA.createNewFile("dirty2");
clientA.up(upOptionsForceEnabled);
// No 'down'! This version will become DIRTY
clientA.changeFile("A-file1.jpg");
clientA.createNewFile("dirty3");
clientA.up(upOptionsForceEnabled);
// No 'down'! This version will become DIRTY
clientA.changeFile("A-file1.jpg");
clientA.createNewFile("dirty4");
clientA.up(upOptionsForceEnabled);
// No 'down'! This version will become DIRTY
clientA.changeFile("A-file1.jpg");
clientA.createNewFile("dirty5");
clientA.up(upOptionsForceEnabled);
// No 'down'! This version will become DIRTY
clientA.changeFile("A-file1.jpg");
clientA.createNewFile("dirty6");
clientA.up(upOptionsForceEnabled);
// No 'down'! This version will become DIRTY
clientA.changeFile("A-file1.jpg");
clientA.createNewFile("dirty7");
clientA.up(upOptionsForceEnabled);
assertEquals("11", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));
clientA.down();
assertEquals("12", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));
assertEquals("7", TestSqlUtil.runSqlSelect("select count(*) from databaseversion where status='DIRTY'", databaseConnectionA));
assertEquals("5", TestSqlUtil.runSqlSelect("select count(*) from databaseversion where status<>'DIRTY'", databaseConnectionA));
assertEquals("(A1)\n(A1,B1)\n(A2,B1)\n(A3,B1)\n(A3,B4)", TestSqlUtil.runSqlSelect("select vectorclock_serialized from databaseversion where status<>'DIRTY' order by id", databaseConnectionA));
// Does nothing; A versions lose against (A3,B2) // same as above!
clientB.down();
assertEquals("5", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionB));
assertEquals("(A1)\n(A1,B1)\n(A2,B1)\n(A3,B1)\n(A3,B4)", TestSqlUtil.runSqlSelect("select vectorclock_serialized from databaseversion order by id", databaseConnectionB));
//// 3. NEW CLIENT JOINS
clientC.down();
TestAssertUtil.assertSqlDatabaseEquals(clientB.getDatabaseFile(), clientC.getDatabaseFile());
//// 4. FORCE MERGE DATABASES ON CLIENT A
clientA.deleteFile("dirty1");
clientA.deleteFile("dirty2");
// upload DIRTY version
clientA.up(upOptionsForceEnabled);
assertEquals("6", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));
assertEquals("0", TestSqlUtil.runSqlSelect("select count(*) from databaseversion where status='DIRTY'", databaseConnectionA));
assertEquals("6", TestSqlUtil.runSqlSelect("select count(*) from databaseversion where status<>'DIRTY'", databaseConnectionA));
clientA.createNewFile("A-file2.jpg");
// For every X up's call 'cleanup' ("X" is larger than the max. length of file versions in a history)
int cleanupEveryXUps = 7;
for (int i = 1; i <= 21; i++) {
clientA.changeFile("A-file2.jpg");
clientA.up(upOptionsForceEnabled);
if (i % cleanupEveryXUps == 0) {
clientA.cleanup(cleanupOptions);
}
}
clientA.cleanup(cleanupOptions);
clientB.down();
clientC.down();
clientD.down();
TestAssertUtil.assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
TestAssertUtil.assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientC.getDatabaseFile());
TestAssertUtil.assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientD.getDatabaseFile());
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
clientC.deleteTestData();
clientD.deleteTestData();
}
use of org.syncany.operations.up.UpOperationOptions in project syncany by syncany.
the class DirtyDatabaseScenarioTest method testDirtyDatabase.
@Test
public void testDirtyDatabase() throws Exception {
// Setup
TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
// Run
UpOperationOptions upOptionsForceEnabled = new UpOperationOptions();
upOptionsForceEnabled.setForceUploadEnabled(true);
clientA.createNewFile("A-file1.jpg", 50 * 1024);
clientA.up(upOptionsForceEnabled);
clientB.createNewFile("A-file1.jpg", 51 * 1024);
clientB.up(upOptionsForceEnabled);
// This creates a dirty database
clientB.down();
// Test (for dirty database existence)
Config configB = clientB.getConfig();
java.sql.Connection databaseConnectionB = configB.createDatabaseConnection();
ChunkSqlDao chunkDao = new ChunkSqlDao(databaseConnectionB);
MultiChunkSqlDao multiChunkDao = new MultiChunkSqlDao(databaseConnectionB);
FileVersionSqlDao fileVersionDao = new FileVersionSqlDao(databaseConnectionB);
FileHistorySqlDao fileHistoryDao = new FileHistorySqlDao(databaseConnectionB, fileVersionDao);
FileContentSqlDao fileContentDao = new FileContentSqlDao(databaseConnectionB);
DatabaseVersionSqlDao databaseVersionDao = new DatabaseVersionSqlDao(databaseConnectionB, chunkDao, fileContentDao, fileVersionDao, fileHistoryDao, multiChunkDao);
Iterator<DatabaseVersion> databaseVersionsDirtyB = databaseVersionDao.getDirtyDatabaseVersions();
List<DatabaseVersion> databaseVersionsDirtyListB = TestCollectionUtil.toList(databaseVersionsDirtyB);
assertEquals(1, databaseVersionsDirtyListB.size());
DatabaseVersion dirtyDatabaseVersionB = databaseVersionsDirtyListB.get(0);
assertNotNull(dirtyDatabaseVersionB);
assertEquals(1, dirtyDatabaseVersionB.getFileHistories().size());
PartialFileHistory fileHistoryFile1B = dirtyDatabaseVersionB.getFileHistories().iterator().next();
assertNotNull(fileHistoryFile1B);
assertEquals(1, fileHistoryFile1B.getFileVersions().size());
assertEquals("A-file1.jpg", fileHistoryFile1B.getLastVersion().getPath());
assertFileEquals(clientA.getLocalFile("A-file1.jpg"), clientB.getLocalFile("A-file1.jpg"));
assertConflictingFileExists("A-file1.jpg", clientB.getLocalFilesExcludeLockedAndNoRead());
// Run (part 2)
// This deletes the dirty database file
clientB.up();
Iterator<DatabaseVersion> databaseVersionsDirtyB2 = databaseVersionDao.getDirtyDatabaseVersions();
List<DatabaseVersion> databaseVersionsDirtyListB2 = TestCollectionUtil.toList(databaseVersionsDirtyB2);
assertEquals(0, databaseVersionsDirtyListB2.size());
// Run (part 3)
// This pulls down the conflicting file
clientA.down();
assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
assertConflictingFileExists("A-file1.jpg", clientA.getLocalFilesExcludeLockedAndNoRead());
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
}
Aggregations