use of org.syncany.tests.util.TestClient in project syncany by syncany.
the class ChangedTypeScenarioTest method testSingleFileChangeTypeToFolder.
@Test
public void testSingleFileChangeTypeToFolder() throws Exception {
final TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
final TestClient clientA = new TestClient("A", testConnection);
final TestClient clientB = new TestClient("B", testConnection);
// 1. Client A creates a new file
clientA.createNewFile("test-file");
clientA.up();
// 2. Client A removes file and creates directory with the same name
clientA.deleteFile("test-file");
clientA.createNewFolder("test-file");
clientA.up();
// 3. Client B downloads repository state
clientB.down();
// Verify that client A and client B have identical repositories
assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
clientA.deleteTestData();
clientB.deleteTestData();
}
use of org.syncany.tests.util.TestClient in project syncany by syncany.
the class DirtyDatabaseVersionsScenarioTest method testThreeClientsOneLoser.
@Test
public void testThreeClientsOneLoser() 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);
UpOperationOptions cUpOptionsWithForce = new UpOperationOptions();
cUpOptionsWithForce.setForceUploadEnabled(true);
// Run
clientA.createNewFile("file1.jpg");
clientA.upWithForceChecksum();
clientB.down();
clientB.createNewFile("file2.jpg");
clientB.upWithForceChecksum();
// Client C: No down!
clientC.createNewFile("file3.jpg");
clientC.up(cUpOptionsWithForce);
// A tries to upload, this fails due to C's unknown database
clientA.createNewFile("file4.jpg");
//
UpOperationResult aUpResult = clientA.upWithForceChecksum();
assertEquals("Expected to fail, because db-C-1 has not been looked at", UpResultCode.NOK_UNKNOWN_DATABASES, aUpResult.getResultCode());
assertFalse(clientA.getLocalFile("file2.jpg").exists());
assertFalse(clientA.getLocalFile("file3.jpg").exists());
// A downloads C's changes, no file changes are expected
DownOperationResult aDownResult = clientA.down();
assertEquals("Expected to succeed with remote changes (a new database file, but no file changes!).", DownResultCode.OK_WITH_REMOTE_CHANGES, aDownResult.getResultCode());
assertTrue(clientA.getLocalFile("file2.jpg").exists());
assertFalse(clientA.getLocalFile("file3.jpg").exists());
// TODO [low] Add assert: "no file changes are expected"
// A uploads again, this time it should succeed, because C's file is in knowndbs.list
aUpResult = clientA.upWithForceChecksum();
assertEquals("Expected to succeed, because db-C-1 has already been looked at", UpResultCode.OK_CHANGES_UPLOADED, aUpResult.getResultCode());
// C calls down and up, to sync its changes
// Adds dirty database
clientC.down();
assertSqlResultEquals(clientC.getDatabaseFile(), "select count(*) from databaseversion where status='DIRTY'", "1");
clientC.upWithForceChecksum();
assertSqlResultEquals(clientC.getDatabaseFile(), "select count(*) from databaseversion where status='DIRTY'", "0");
clientA.down();
assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientC.getLocalFilesExcludeLockedAndNoRead());
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
clientC.deleteTestData();
}
use of org.syncany.tests.util.TestClient in project syncany by syncany.
the class DirtyDatabaseVersionsScenarioTest method testRemoveDirtyLostMultiChunksIssue132_1.
@Test
public void testRemoveDirtyLostMultiChunksIssue132_1() 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
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);
FileUtils.copyDirectory(testConnection.getPath(), new File(testConnection.getPath() + "_1_before_down"));
FileUtils.copyDirectory(clientB.getConfig().getLocalDir(), new File(clientB.getConfig().getLocalDir() + "_1_before_down"));
assertSqlResultEquals(clientB.getDatabaseFile(), "select count(*) from multichunk_muddy", "0");
// Download A's version, realize it's muddy (= dirty by other client)
clientB.down();
assertSqlResultEquals(clientB.getDatabaseFile(), "select count(*) from multichunk_muddy", "1");
FileUtils.copyDirectory(testConnection.getPath(), new File(testConnection.getPath(), "_2_after_down_before_cleanup"));
FileUtils.copyDirectory(clientB.getConfig().getLocalDir(), new File(clientB.getConfig().getLocalDir() + "_2_after_down_before_cleanup"));
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);
FileUtils.copyDirectory(testConnection.getPath(), new File(testConnection.getPath() + "_3_after_cleanup"));
FileUtils.copyDirectory(clientB.getConfig().getLocalDir(), new File(clientB.getConfig().getLocalDir() + "_3_after_cleanup"));
// Adds dirty database
clientA.down();
assertSqlResultEquals(clientA.getDatabaseFile(), "select count(*) from databaseversion where status='DIRTY'", "1");
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();
System.out.println(new File(testConnection.getPath() + "_1_before_down"));
System.out.println(new File(clientB.getConfig().getLocalDir(), "_1_before_down"));
FileUtils.deleteDirectory(new File(testConnection.getPath() + "_1_before_down"));
FileUtils.deleteDirectory(new File(clientB.getConfig().getLocalDir() + "_1_before_down"));
FileUtils.deleteDirectory(new File(testConnection.getPath() + "_2_after_down_before_cleanup"));
FileUtils.deleteDirectory(new File(clientB.getConfig().getLocalDir() + "_2_after_down_before_cleanup"));
FileUtils.deleteDirectory(new File(testConnection.getPath() + "_3_after_cleanup"));
FileUtils.deleteDirectory(new File(clientB.getConfig().getLocalDir() + "_3_after_cleanup"));
}
use of org.syncany.tests.util.TestClient in project syncany by syncany.
the class EvilCUpWithoutDownScenarioTest method testEvilC.
@Test
public void testEvilC() 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);
// Run
clientA.createNewFile("A1");
clientA.upWithForceChecksum();
clientA.moveFile("A1", "A2");
clientA.upWithForceChecksum();
clientA.changeFile("A2");
clientA.createNewFile("A3");
clientA.upWithForceChecksum();
clientA.deleteFile("A3");
clientA.upWithForceChecksum();
clientB.down();
assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
clientB.createNewFile("A4,B1");
clientB.up();
// Evil. "up" without "down"
clientC.createNewFile("C1");
clientC.changeFile("C1");
clientC.up();
clientC.changeFile("C1");
clientC.up();
clientC.changeFile("C1");
clientC.up();
clientA.down();
assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
Map<String, File> beforeSyncDownBFileList = clientB.getLocalFilesExcludeLockedAndNoRead();
clientB.down();
assertFileListEquals("No change in file lists expected. Nothing changed for 'B'.", beforeSyncDownBFileList, clientB.getLocalFilesExcludeLockedAndNoRead());
clientC.down();
assertEquals("Client C is expected to have one more local file (C1)", clientA.getLocalFilesExcludeLockedAndNoRead().size() + 1, clientC.getLocalFilesExcludeLockedAndNoRead().size());
clientA.up();
clientB.up();
clientC.up();
clientA.down();
clientB.down();
clientC.down();
assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
assertFileListEquals(clientB.getLocalFilesExcludeLockedAndNoRead(), clientC.getLocalFilesExcludeLockedAndNoRead());
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
clientC.deleteTestData();
}
use of org.syncany.tests.util.TestClient in project syncany by syncany.
the class FileLockedScenarioTest method testFileLocked.
// TODO [high] Fix issues with readonly files on Windows, and r------ files on Linux
@Test
public void testFileLocked() throws Exception {
// Setup
TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
// Run!
clientA.createNewFile("locked-file");
RandomAccessFile lockedFile = new RandomAccessFile(clientA.getLocalFile("locked-file"), "rw");
FileLock lockedFileLock = lockedFile.getChannel().lock();
runUpAndTestForEmptyDatabase(testConnection, clientA);
// Tear down
lockedFileLock.release();
lockedFile.close();
clientA.deleteTestData();
}
Aggregations