use of org.syncany.plugins.transfer.files.DatabaseRemoteFile in project syncany by syncany.
the class ApplicationDaoTest method testShutdown.
@Test
public void testShutdown() throws Exception {
// Setup
Config testConfig = TestConfigUtil.createTestLocalConfig();
Connection databaseConnection = testConfig.createDatabaseConnection();
// Prepare
ApplicationSqlDao applicationDao = new ApplicationSqlDao(databaseConnection);
List<DatabaseRemoteFile> expectedKnownDatabases = Arrays.asList(new DatabaseRemoteFile[] { new DatabaseRemoteFile("database-A-0000000001") });
applicationDao.writeKnownRemoteDatabases(expectedKnownDatabases);
// Run & Test
assertTrue(new File(testConfig.getDatabaseFile() + ".lck").exists());
applicationDao.shutdown();
assertFalse(new File(testConfig.getDatabaseFile() + ".lck").exists());
// Tear down
databaseConnection.close();
TestConfigUtil.deleteTestLocalConfigAndData(testConfig);
}
use of org.syncany.plugins.transfer.files.DatabaseRemoteFile in project syncany by syncany.
the class ApplicationDaoTest method testGetKnownDatabases.
@Test
public void testGetKnownDatabases() throws Exception {
// Setup
Config testConfig = TestConfigUtil.createTestLocalConfig();
Connection databaseConnection = testConfig.createDatabaseConnection();
// Run
TestSqlUtil.runSqlFromResource(databaseConnection, "test.insert.set3.sql");
ApplicationSqlDao applicationDao = new ApplicationSqlDao(databaseConnection);
List<DatabaseRemoteFile> actualKnownDatabases = applicationDao.getKnownDatabases();
// Test
assertTrue(CollectionUtil.containsExactly(Arrays.asList(new DatabaseRemoteFile[] { new DatabaseRemoteFile("database-B-0000000001"), new DatabaseRemoteFile("database-B-0000000002"), new DatabaseRemoteFile("database-B-0000000003") }), actualKnownDatabases));
// Tear down
databaseConnection.close();
TestConfigUtil.deleteTestLocalConfigAndData(testConfig);
}
use of org.syncany.plugins.transfer.files.DatabaseRemoteFile in project syncany by syncany.
the class ApplicationDaoTest method testPersistAndGetKnownDatabases.
@Test
public void testPersistAndGetKnownDatabases() throws Exception {
// Setup
Config testConfig = TestConfigUtil.createTestLocalConfig();
Connection databaseConnection = testConfig.createDatabaseConnection();
// Run
ApplicationSqlDao applicationDao = new ApplicationSqlDao(databaseConnection);
List<DatabaseRemoteFile> expectedKnownDatabases = Arrays.asList(new DatabaseRemoteFile[] { new DatabaseRemoteFile("database-A-0000000001"), new DatabaseRemoteFile("database-V-0000000001"), new DatabaseRemoteFile("database-B-0000000001"), new DatabaseRemoteFile("database-A-0000000002") });
applicationDao.writeKnownRemoteDatabases(expectedKnownDatabases);
List<DatabaseRemoteFile> actualKnownDatabases = applicationDao.getKnownDatabases();
// Test
assertTrue(CollectionUtil.containsExactly(expectedKnownDatabases, actualKnownDatabases));
// Tear down
databaseConnection.close();
TestConfigUtil.deleteTestLocalConfigAndData(testConfig);
}
use of org.syncany.plugins.transfer.files.DatabaseRemoteFile in project syncany by syncany.
the class UpOperation method checkPreconditions.
/**
* This method checks if:
*
* <ul>
* <li>If there are local changes => No need for Up.</li>
* <li>If another clients is running Cleanup => Not allowed to upload.</li>
* <li>If remote changes exist => Should Down first.</li>
* </ul>
*
* @returns boolean true if Up can and should be done, false otherwise.
*/
private boolean checkPreconditions() throws Exception {
// Find local changes
StatusOperation statusOperation = new StatusOperation(config, options.getStatusOptions());
StatusOperationResult statusOperationResult = statusOperation.execute();
ChangeSet localChanges = statusOperationResult.getChangeSet();
result.getStatusResult().setChangeSet(localChanges);
if (!localChanges.hasChanges()) {
logger.log(Level.INFO, "Local database is up-to-date (change set). NOTHING TO DO!");
result.setResultCode(UpResultCode.OK_NO_CHANGES);
return false;
}
// Check if other operations are running
if (otherRemoteOperationsRunning(CleanupOperation.ACTION_ID)) {
logger.log(Level.INFO, "* Cleanup running. Skipping down operation.");
result.setResultCode(UpResultCode.NOK_UNKNOWN_DATABASES);
return false;
}
// Find remote changes (unless --force is enabled)
if (!options.forceUploadEnabled()) {
LsRemoteOperationResult lsRemoteOperationResult = new LsRemoteOperation(config, transferManager).execute();
List<DatabaseRemoteFile> unknownRemoteDatabases = lsRemoteOperationResult.getUnknownRemoteDatabases();
if (unknownRemoteDatabases.size() > 0) {
logger.log(Level.INFO, "There are remote changes. Call 'down' first or use --force-upload you must, Luke!");
logger.log(Level.FINE, "Unknown remote databases are: " + unknownRemoteDatabases);
result.setResultCode(UpResultCode.NOK_UNKNOWN_DATABASES);
return false;
} else {
logger.log(Level.INFO, "No remote changes, ready to upload.");
}
} else {
logger.log(Level.INFO, "Force (--force-upload) is enabled, ignoring potential remote changes.");
}
return true;
}
use of org.syncany.plugins.transfer.files.DatabaseRemoteFile in project syncany by syncany.
the class UpOperation method writeAndAddDeltaDatabase.
/**
* This method takes the metadata that is to be uploaded, loads it into a {@link MemoryDatabase} and serializes
* it to a file. If this is not a resumption of a previous transaction, this file is added to the transaction.
* Finally, databaseversions that are uploaded are remembered as known, such that they are not downloaded in future Downs.
*
* @param newDatabaseVersion {@link DatabaseVersion} containing all metadata that would be locally persisted if the transaction succeeds.
* @param resuming boolean indicating if the current transaction is in the process of being resumed.
*/
private void writeAndAddDeltaDatabase(RemoteTransaction remoteTransaction, DatabaseVersion newDatabaseVersion, boolean resuming) throws InterruptedException, StorageException, IOException, SQLException {
// Clone database version (necessary, because the original must not be touched)
DatabaseVersion deltaDatabaseVersion = newDatabaseVersion.clone();
// New delta database
MemoryDatabase deltaDatabase = new MemoryDatabase();
deltaDatabase.addDatabaseVersion(deltaDatabaseVersion);
// Save delta database locally
long newestLocalDatabaseVersion = getNewestDatabaseFileVersion(config.getMachineName(), localDatabase.getKnownDatabases());
DatabaseRemoteFile remoteDeltaDatabaseFile = new DatabaseRemoteFile(config.getMachineName(), newestLocalDatabaseVersion + 1);
File localDeltaDatabaseFile = config.getCache().getDatabaseFile(remoteDeltaDatabaseFile.getName());
logger.log(Level.INFO, "Saving local delta database, version {0} to file {1} ... ", new Object[] { deltaDatabaseVersion.getHeader(), localDeltaDatabaseFile });
saveDeltaDatabase(deltaDatabase, localDeltaDatabaseFile);
if (!resuming) {
// Upload delta database, if we are not resuming (in which case the db is in the transaction already)
logger.log(Level.INFO, "- Uploading local delta database file ...");
addLocalDatabaseToTransaction(remoteTransaction, localDeltaDatabaseFile, remoteDeltaDatabaseFile);
}
// Remember uploaded database as known.
List<DatabaseRemoteFile> newDatabaseRemoteFiles = new ArrayList<DatabaseRemoteFile>();
newDatabaseRemoteFiles.add(remoteDeltaDatabaseFile);
localDatabase.writeKnownRemoteDatabases(newDatabaseRemoteFiles);
}
Aggregations