use of org.syncany.tests.util.TestClient in project syncany by syncany.
the class EmptyFileScenarioTest method testEmptyFileCreateAndSync.
@Test
public void testEmptyFileCreateAndSync() throws Exception {
// Setup
TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
// Run
clientA.createNewFile("A-file1.jpg", 0);
clientA.up();
clientB.down();
assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
clientB.createNewFile("B-file2", 0);
clientB.moveFile("A-file1.jpg", "B-file1-moved");
clientB.up();
SqlDatabase database = clientB.loadLocalDatabase();
DatabaseVersionHeader lastDatabaseVersionHeaderBeforeUp = database.getLastDatabaseVersionHeader();
// double-up, has caused problems
clientB.up();
DatabaseVersionHeader lastDatabaseVersionHeaderAfterUp = database.getLastDatabaseVersionHeader();
assertEquals("Nothing changed. Local database file should not change.", lastDatabaseVersionHeaderBeforeUp, lastDatabaseVersionHeaderAfterUp);
clientA.down();
assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
Map<String, File> beforeSyncDownFileList = clientB.getLocalFilesExcludeLockedAndNoRead();
// double-down, has caused problems
clientA.down();
assertFileListEquals("No change in file lists expected. Nothing changed", beforeSyncDownFileList, clientA.getLocalFilesExcludeLockedAndNoRead());
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
}
use of org.syncany.tests.util.TestClient 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.tests.util.TestClient in project syncany by syncany.
the class FileLockedScenarioTest method testPermissionDeniedNotReadable.
@Test
public void testPermissionDeniedNotReadable() throws Exception {
if (EnvironmentUtil.isWindows()) {
// Not possible in windows
return;
}
// Setup
TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
// Run
File noReadPermissionFile = clientA.createNewFile("no-read-permission-file");
Path filePath = Paths.get(noReadPermissionFile.getAbsolutePath());
Set<PosixFilePermission> perms = new HashSet<PosixFilePermission>();
perms.add(PosixFilePermission.OWNER_READ);
perms.add(PosixFilePermission.GROUP_READ);
perms.add(PosixFilePermission.OTHERS_READ);
Files.setPosixFilePermissions(filePath, perms);
runUpAndTestForConsistentDatabase(testConnection, clientA);
// Tear down
clientA.deleteTestData();
}
use of org.syncany.tests.util.TestClient in project syncany by syncany.
the class FileLockedScenarioTest method testLockUnlockFile.
@Test
public void testLockUnlockFile() throws Exception {
final TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
final TestClient clientA = new TestClient("A", testConnection);
final TestClient clientB = new TestClient("B", testConnection);
ClientActions.run(clientA, null, new CreateFileTree(), new Executable() {
@Override
public void execute() throws Exception {
clientA.upWithForceChecksum();
clientB.down();
assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
}
});
ClientActions.run(clientA, null, new LockFile(), new Executable() {
@Override
public void execute() throws Exception {
clientA.upWithForceChecksum();
clientB.down();
assertEquals(clientA.getLocalFilesExcludeLockedAndNoRead().size(), clientB.getLocalFilesExcludeLockedAndNoRead().size() - 1);
}
});
ClientActions.run(clientA, null, new UnlockFile(), new Executable() {
@Override
public void execute() throws Exception {
clientA.upWithForceChecksum();
clientB.down();
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 FilenameCapitalizationWindowsScenarioTest method testFilenameCapitalizationWindows.
// TODO [medium] Windows: LARGE/small capitalization --> Dropbox makes a file "name (Case Conflict 1)"; define expected/desired behavior
@Test
public void testFilenameCapitalizationWindows() throws Exception {
// Setup
TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
// Run
clientA.createNewFile("FILENAME-FOR-WINDOWS");
clientA.createNewFile("filename-for-windows");
clientA.createNewFile("Filename-For-Windows");
clientA.upWithForceChecksum();
assertEquals("There should be three files.", 3, clientA.getLocalFilesExcludeLockedAndNoRead().size());
clientB.down();
assertEquals("There should be three files.", 3, clientB.getLocalFilesExcludeLockedAndNoRead().size());
assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
}
Aggregations