use of org.syncany.operations.status.StatusOperationResult in project syncany by syncany.
the class FileLockedScenarioTest method runUpAndTestForEmptyDatabase.
private void runUpAndTestForEmptyDatabase(TransferSettings connection, TestClient client) throws Exception {
UpOperationResult upResult = client.up();
StatusOperationResult statusResult = upResult.getStatusResult();
// Test 1: Check result sets for inconsistencies
assertFalse("Status command expected to return NO changes.", statusResult.getChangeSet().hasChanges());
assertFalse("File should NOT be uploaded while it is locked.", upResult.getChangeSet().hasChanges());
// Test 2: Check database for inconsistencies
SqlDatabase database = client.loadLocalDatabase();
assertEquals("File should NOT be uploaded while it is locked.", 0, database.getFileList("large-test-file", null, false, false, false, null).size());
assertNull("There should NOT be a new database version, because file should not have been added.", database.getLastDatabaseVersionHeader());
// Test 3: Check file system for inconsistencies
File repoPath = ((LocalTransferSettings) connection).getPath();
String[] repoFileList = repoPath.list(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.startsWith("database-");
}
});
assertEquals("Repository should NOT contain any files.", 0, repoFileList.length);
}
use of org.syncany.operations.status.StatusOperationResult in project syncany by syncany.
the class StatusFolderRequestHandler method handleRequest.
@Override
public Response handleRequest(FolderRequest request) {
StatusFolderRequest concreteRequest = (StatusFolderRequest) request;
try {
StatusOperation operation = new StatusOperation(config, concreteRequest.getOptions());
StatusOperationResult operationResult = operation.execute();
StatusFolderResponse statusFolderResponse = new StatusFolderResponse(operationResult, request.getId());
return statusFolderResponse;
} catch (Exception e) {
logger.log(Level.WARNING, "Cannot obtain status.", e);
return new BadRequestResponse(request.getId(), "Cannot execute operation: " + e.getMessage());
}
}
use of org.syncany.operations.status.StatusOperationResult 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.operations.status.StatusOperationResult in project syncany by syncany.
the class StatusCommand method execute.
@Override
public int execute(String[] operationArgs) throws Exception {
StatusOperationOptions operationOptions = parseOptions(operationArgs);
StatusOperationResult operationResult = new StatusOperation(config, operationOptions).execute();
printResults(operationResult);
return 0;
}
use of org.syncany.operations.status.StatusOperationResult in project syncany by syncany.
the class CallUpWhileStillWritingFileScenarioTest method testUpWhileWritingFile.
@Test
public void testUpWhileWritingFile() throws Exception {
// Setup
final TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
final TestClient clientA = new TestClient("A", testConnection);
final TestClient clientB = new TestClient("B", testConnection);
final File testFile = clientA.getLocalFile("large-test-file");
final long testFileLength = 100 * 1024 * 1024;
Thread writeFileThread = new Thread(new Runnable() {
@Override
public void run() {
try {
logger.log(Level.INFO, "Started thread to write file to " + testFile + " ...");
FileOutputStream fos = new FileOutputStream(testFile);
Random randomEngine = new Random();
byte[] buf = new byte[4096];
int writtenLen = 0;
while (writtenLen < testFileLength) {
randomEngine.nextBytes(buf);
fos.write(buf, 0, buf.length);
writtenLen += buf.length;
}
fos.close();
logger.log(Level.INFO, "Ended thread to write file to " + testFile + " ...");
} catch (IOException e) {
logger.log(Level.FINE, "Thread failed to write to file", e);
}
}
}, "writerThread");
// Before start: setup up databases (takes a while)
clientA.status();
clientB.status();
// Run!
writeFileThread.start();
Thread.sleep(50);
logger.log(Level.INFO, "Started clientA.up()");
UpOperationResult upResult = clientA.up();
StatusOperationResult statusResult = upResult.getStatusResult();
logger.log(Level.INFO, "Ended clientA.up()");
writeFileThread.join();
// Test 1: Check result sets for inconsistencies
assertTrue("Status command expected to return changes.", statusResult.getChangeSet().hasChanges());
assertFalse("File should NOT be uploaded while still writing (no half-file upload).", upResult.getChangeSet().hasChanges());
// Test 2: Check database for inconsistencies
SqlDatabase database = clientA.loadLocalDatabase();
assertEquals("File should NOT be uploaded while still writing (no half-file upload).", 0, database.getFileList("large-test-file", null, false, false, false, null).size());
assertNull("There should NOT 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 NOT contain any files.", 0, repoFileList.length);
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
}
Aggregations