use of org.syncany.plugins.local.LocalTransferSettings in project syncany by syncany.
the class CleanupMergeDatabaseFilesScenarioTest method testIssue266_EmptyDatabaseAfterCleanup.
@Test
public void testIssue266_EmptyDatabaseAfterCleanup() throws Exception {
// Test for https://github.com/syncany/syncany/issues/266#issuecomment-64472059
// 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 cleanupOptionsKeepOneForce = new CleanupOperationOptions();
cleanupOptionsKeepOneForce.setRemoveOldVersions(true);
cleanupOptionsKeepOneForce.setForce(true);
cleanupOptionsKeepOneForce.setMinKeepSeconds(0);
// Create a couple of files, then delete them and do a cleanup
clientA.createNewFile("fileA");
clientA.upWithForceChecksum();
clientB.down();
clientB.createNewFile("fileB");
clientB.upWithForceChecksum();
clientC.down();
clientC.createNewFile("fileC");
clientC.upWithForceChecksum();
clientD.down();
clientD.deleteFile("fileA");
clientD.deleteFile("fileB");
clientD.deleteFile("fileC");
clientD.upWithForceChecksum();
clientD.cleanup(cleanupOptionsKeepOneForce);
java.sql.Connection databaseConnectionD = DatabaseConnectionFactory.createConnection(clientD.getDatabaseFile(), false);
assertEquals("A,2\nB,2\nC,2\nD,2", TestSqlUtil.runSqlSelect("select client, filenumber from known_databases order by client, filenumber", databaseConnectionD));
assertEquals("", TestSqlUtil.runSqlSelect("select vectorclock_serialized from databaseversion", databaseConnectionD));
// Now the remote databases are completely empty (no files, no histories, no database versions!)
/* Case 1:
*
* Client A now knows "fileA" and must react on the cleanup by client D.
* The remote databases do NOT contain any trace of "fileA" anymore, so
* client A has to detect the deletion by comparing the local database with
* the winner database. "fileA" should be deleted after the next 'down'.
*/
// Existing client << This created a NullPointerException in #266
clientA.down();
assertFalse("File 'fileA' should have been deleted.", clientA.getLocalFile("fileA").exists());
assertFalse("File 'fileB' should not have been created.", clientA.getLocalFile("fileB").exists());
assertFalse("File 'fileC' should not have been created.", clientA.getLocalFile("fileC").exists());
assertConflictingFileNotExists("fileA", clientA.getLocalFiles());
assertConflictingFileNotExists("fileB", clientA.getLocalFiles());
assertConflictingFileNotExists("fileC", clientA.getLocalFiles());
assertSqlDatabaseEquals(clientD.getDatabaseFile(), clientA.getDatabaseFile());
assertFileListEquals(clientD.getLocalFiles(), clientA.getLocalFiles());
java.sql.Connection databaseConnectionA = DatabaseConnectionFactory.createConnection(clientA.getDatabaseFile(), false);
assertEquals("A,2\nB,2\nC,2\nD,2", TestSqlUtil.runSqlSelect("select client, filenumber from known_databases order by client, filenumber", databaseConnectionA));
/*
* Case 2:
*
* Client E is a completely new client. It's the first time downloading anything, so
* it has no local database, and (in this case), the remote/winner database is completely
* empty!
*/
// Empty/new client << This created a NullPointerException
clientE.down();
assertFalse("File 'fileA' should not have been created.", clientE.getLocalFile("fileA").exists());
assertFalse("File 'fileB' should not have been created.", clientE.getLocalFile("fileB").exists());
assertFalse("File 'fileC' should not have been created.", clientE.getLocalFile("fileC").exists());
assertConflictingFileNotExists("fileA", clientA.getLocalFiles());
assertConflictingFileNotExists("fileB", clientA.getLocalFiles());
assertConflictingFileNotExists("fileC", clientA.getLocalFiles());
assertSqlDatabaseEquals(clientD.getDatabaseFile(), clientE.getDatabaseFile());
assertFileListEquals(clientD.getLocalFiles(), clientE.getLocalFiles());
java.sql.Connection databaseConnectionE = DatabaseConnectionFactory.createConnection(clientE.getDatabaseFile(), false);
assertEquals("A,2\nB,2\nC,2\nD,2", TestSqlUtil.runSqlSelect("select client, filenumber from known_databases order by client, filenumber", databaseConnectionE));
// After a successful down, create a new database version (continue numbering!)
clientA.createNewFile("fileA");
UpOperationResult upResult = clientA.upWithForceChecksum();
assertEquals(UpResultCode.OK_CHANGES_UPLOADED, upResult.getResultCode());
assertEquals("(A3,B2,C2,D2)", TestSqlUtil.runSqlSelect("select vectorclock_serialized from databaseversion", databaseConnectionA));
// Check if E applies everything correctly and check E's numbering
clientE.down();
assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientE.getDatabaseFile());
assertFileListEquals(clientA.getLocalFiles(), clientE.getLocalFiles());
assertEquals("A,2\nA,3\nB,2\nC,2\nD,2", TestSqlUtil.runSqlSelect("select client, filenumber from known_databases order by client, filenumber", databaseConnectionE));
clientE.changeFile("fileA");
upResult = clientE.upWithForceChecksum();
assertEquals(UpResultCode.OK_CHANGES_UPLOADED, upResult.getResultCode());
assertEquals("(A3,B2,C2,D2)\n(A3,B2,C2,D2,E1)", TestSqlUtil.runSqlSelect("select vectorclock_serialized from databaseversion", databaseConnectionE));
// And with D ...
clientD.down();
assertSqlDatabaseEquals(clientE.getDatabaseFile(), clientD.getDatabaseFile());
assertFileListEquals(clientE.getLocalFiles(), clientD.getLocalFiles());
assertEquals("A,2\nA,3\nB,2\nC,2\nD,2\nE,1", TestSqlUtil.runSqlSelect("select client, filenumber from known_databases order by client, filenumber", databaseConnectionD));
assertEquals("(A3,B2,C2,D2)\n(A3,B2,C2,D2,E1)", TestSqlUtil.runSqlSelect("select vectorclock_serialized from databaseversion", databaseConnectionD));
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
clientC.deleteTestData();
clientD.deleteTestData();
clientE.deleteTestData();
}
use of org.syncany.plugins.local.LocalTransferSettings in project syncany by syncany.
the class CleanupMergeDatabaseFilesScenarioTest method testDeleteFileAndCleanup.
@Test
public void testDeleteFileAndCleanup() throws Exception {
// Test if a deleted file is deleted remotely even after a cleanup
// Setup
LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
CleanupOperationOptions cleanupOptionsKeepOneForce = new CleanupOperationOptions();
cleanupOptionsKeepOneForce.setRemoveOldVersions(true);
cleanupOptionsKeepOneForce.setForce(true);
// Create a couple of files, then delete them and do a cleanup
clientA.createNewFile("fileA1");
clientA.createNewFile("fileA2");
clientA.upWithForceChecksum();
clientB.down();
clientB.deleteFile("fileA1");
clientB.upWithForceChecksum();
// <<< This accidentally(?) deletes file histories marked DELETED
clientB.cleanup(cleanupOptionsKeepOneForce);
clientA.down();
assertFalse("Deleted file still exists.", clientA.getLocalFile("fileA1").exists());
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
}
use of org.syncany.plugins.local.LocalTransferSettings 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.plugins.local.LocalTransferSettings 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.plugins.local.LocalTransferSettings in project syncany by syncany.
the class PluginOperationTest method testPluginInstall.
@Test
public void testPluginInstall() throws Exception {
if (EnvironmentUtil.isWindows()) {
// Test is Unix-specific.
return;
}
File configDir = setupCleanConfigDir();
// Setup
LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
TestClient client = new TestClient("A", testConnection);
PluginOperationOptions pluginOptions = new PluginOperationOptions();
pluginOptions.setAction(PluginOperationAction.INSTALL);
pluginOptions.setPluginId("ftp");
PluginOperationResult pluginResult = client.plugin(pluginOptions);
assertNotNull(pluginResult);
assertEquals(PluginResultCode.OK, pluginResult.getResultCode());
// Only one file should be in here: the jar for ftp.
assertEquals(1, (new File(configDir, "plugins/lib/")).list().length);
// Tear down
client.deleteTestData();
TestFileUtil.deleteDirectory(configDir);
System.setProperty("user.home", "/tmp");
}
Aggregations