use of org.syncany.database.SqlDatabase in project syncany by syncany.
the class FileLockedScenarioTest method runUpAndTestForConsistentDatabase.
private void runUpAndTestForConsistentDatabase(TransferSettings connection, TestClient client) throws Exception {
UpOperationResult upResult = client.up();
StatusOperationResult statusResult = upResult.getStatusResult();
// Test 1: Check result sets for inconsistencies
assertTrue("Status command expected to return changes.", statusResult.getChangeSet().hasChanges());
assertTrue("File should be uploaded while it is read-only.", upResult.getChangeSet().hasChanges());
// Test 2: Check database for inconsistencies
SqlDatabase database = client.loadLocalDatabase();
assertNotNull("There should be a new database version, because files should have been added.", database.getLastDatabaseVersionHeader());
// Test 3: Check file system for inconsistencies
File repoPath = ((LocalTransferSettings) connection).getPath();
assertEquals("Repository should contain any files.", 5, repoPath.list().length);
}
use of org.syncany.database.SqlDatabase in project syncany by syncany.
the class FileVanishedScenarioTest method testCallUpWhileDeletingFiles.
// TODO [low] If a file has vanished, are its chunks and multichunks still added to the database, and then uploaded? If so, fix this!
@Test
public void testCallUpWhileDeletingFiles() throws Exception {
// Setup
final TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
final TestClient clientA = new TestClient("A", testConnection);
final TestClient clientB = new TestClient("B", testConnection);
final int numFiles = 100;
final int numFilesVanished = 50;
final int numFilesRemaining = numFiles - numFilesVanished;
final int sizeFiles = 500 * 1024;
CleanupOperationOptions options = new CleanupOperationOptions();
options.setMinKeepSeconds(0);
// Prepare by creating test files
logger.log(Level.INFO, "Creating test files ...");
for (int i = 0; i <= numFiles; i++) {
clientA.createNewFile("A-original" + i, sizeFiles);
}
// Prepare threads (delete & run up)
Thread deleteFilesThread = new Thread(new Runnable() {
@Override
public void run() {
for (int i = numFiles; i >= numFilesVanished; i--) {
boolean deleteSuccess = clientA.deleteFile("A-original" + i);
if (deleteSuccess) {
logger.log(Level.SEVERE, "Deleted " + clientA.getLocalFile("A-original" + i));
} else {
logger.log(Level.SEVERE, "FAILED TO DELETE FILE " + clientA.getLocalFile("A-original" + i));
}
try {
Thread.sleep(50);
} catch (InterruptedException e) {
logger.log(Level.FINE, "Thread interrupted", e);
}
}
}
}, "A-delete");
Thread runUpThread = new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(40);
clientA.up();
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
}, "A-up");
// Before we start: init database (this takes a while)
clientA.status();
clientB.status();
// Delete files and run up simultaneously
// --> This will hopefully lead to a couple of 'vanished' files
logger.log(Level.INFO, "Starting 'up' thread ...");
runUpThread.start();
logger.log(Level.INFO, "Starting 'delete' thread ...");
deleteFilesThread.start();
runUpThread.join();
deleteFilesThread.join();
// Test 1: There should be between 50 and 100 file histories in the database
SqlDatabase databaseClientA = clientA.loadLocalDatabase();
assertTrue("There should be less file histories than originally added files.", databaseClientA.getFileHistoriesWithFileVersions().size() < numFiles);
assertTrue("There should be more (or equal size) file histories than files there are.", databaseClientA.getFileHistoriesWithFileVersions().size() >= numFilesRemaining);
// Test 2: Now up the rest, there should be exactly 50 files in the database
clientA.up();
clientA.cleanup(options);
databaseClientA = clientA.loadLocalDatabase();
assertEquals("There should be EXACTLY " + numFilesRemaining + " file histories in the database.", numFilesRemaining, databaseClientA.getFileHistoriesWithFileVersions().size());
// Test 3: After that, the sync between the clients should of course still work
clientB.down();
assertFileListEquals("Files of both clients should be identical.", clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
}
use of org.syncany.database.SqlDatabase in project syncany by syncany.
the class EmptyFolderScenarioTest method testEmptyFolderCreateAndSync.
@Test
public void testEmptyFolderCreateAndSync() throws Exception {
// Setup
TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
// Run
clientA.createNewFolder("A-folder1");
clientA.createNewFolder("A-folder2");
clientA.createNewFolder("A-folder3");
clientA.up();
clientB.down();
assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
clientB.createNewFolder("B-folder4");
clientB.createNewFolder("B-folder5");
clientB.up();
SqlDatabase databaseB = clientB.loadLocalDatabase();
DatabaseVersionHeader beforeDatabaseVersionHeader = databaseB.getLastDatabaseVersionHeader();
// double-up, has caused problems
clientB.up();
DatabaseVersionHeader afterDatabaseVersionHeader = databaseB.getLastDatabaseVersionHeader();
assertEquals("Nothing changed. Local database file should not change.", beforeDatabaseVersionHeader, afterDatabaseVersionHeader);
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.database.SqlDatabase in project syncany by syncany.
the class SymlinkSyncScenarioTest method testSymlinkOneUpOneDown.
@Test
public void testSymlinkOneUpOneDown() throws Exception {
if (!EnvironmentUtil.symlinksSupported()) {
// Skip test for Windows, no symlinks there!
return;
}
// Setup
TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
// Run
File symlinkFile = clientA.getLocalFile("symlink-name");
FileUtil.createSymlink("/etc/hosts", symlinkFile);
assertTrue("Symlink should exist at " + symlinkFile, symlinkFile.exists());
UpOperationResult upResult = clientA.up();
StatusOperationResult statusResult = upResult.getStatusResult();
// Test 1: Check result sets for inconsistencies
assertTrue("Status should return changes.", statusResult.getChangeSet().hasChanges());
assertTrue("File should be uploaded.", upResult.getChangeSet().hasChanges());
// Test 2: Check database for inconsistencies
SqlDatabase database = clientA.loadLocalDatabase();
assertEquals("File should be uploaded.", 1, database.getFileList("symlink-name", null, false, false, false, null).size());
assertNotNull("There should be a new database version, because file should not have been added.", database.getLastDatabaseVersionHeader());
// Test 3: Check file system for inconsistencies
File repoPath = new File(((LocalTransferSettings) testConnection).getPath() + "/databases");
String[] repoFileList = repoPath.list(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.startsWith("database-");
}
});
assertEquals("Repository should contain only ONE database file, not multichunks.", 1, repoFileList.length);
// B down
clientB.down();
assertEquals("Local folder should contain one file (link!)", 1, clientB.getLocalFilesExcludeLockedAndNoRead().size());
File localSymlinkFile = clientB.getLocalFile("symlink-name");
assertTrue("Local symlink file should exist.", localSymlinkFile.exists());
assertTrue("Local symlink file should be a SYMLINK.", FileUtil.isSymlink(localSymlinkFile));
assertEquals("Local symlink file should point to actual target.", "/etc/hosts", FileUtil.readSymlinkTarget(localSymlinkFile));
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
}
Aggregations