Search in sources :

Example 1 with StatusOperationResult

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);
}
Also used : FilenameFilter(java.io.FilenameFilter) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) SqlDatabase(org.syncany.database.SqlDatabase) RandomAccessFile(java.io.RandomAccessFile) LockFile(org.syncany.tests.integration.scenarios.framework.LockFile) File(java.io.File) UnlockFile(org.syncany.tests.integration.scenarios.framework.UnlockFile) UpOperationResult(org.syncany.operations.up.UpOperationResult) StatusOperationResult(org.syncany.operations.status.StatusOperationResult)

Example 2 with StatusOperationResult

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());
    }
}
Also used : StatusOperation(org.syncany.operations.status.StatusOperation) StatusOperationResult(org.syncany.operations.status.StatusOperationResult)

Example 3 with StatusOperationResult

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;
}
Also used : StatusOperation(org.syncany.operations.status.StatusOperation) LsRemoteOperationResult(org.syncany.operations.ls_remote.LsRemoteOperationResult) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) ChangeSet(org.syncany.operations.ChangeSet) StatusOperationResult(org.syncany.operations.status.StatusOperationResult) LsRemoteOperation(org.syncany.operations.ls_remote.LsRemoteOperation)

Example 4 with StatusOperationResult

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;
}
Also used : StatusOperation(org.syncany.operations.status.StatusOperation) StatusOperationOptions(org.syncany.operations.status.StatusOperationOptions) StatusOperationResult(org.syncany.operations.status.StatusOperationResult)

Example 5 with StatusOperationResult

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();
}
Also used : LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TransferSettings(org.syncany.plugins.transfer.TransferSettings) IOException(java.io.IOException) UpOperationResult(org.syncany.operations.up.UpOperationResult) FilenameFilter(java.io.FilenameFilter) Random(java.util.Random) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) FileOutputStream(java.io.FileOutputStream) SqlDatabase(org.syncany.database.SqlDatabase) File(java.io.File) StatusOperationResult(org.syncany.operations.status.StatusOperationResult) Test(org.junit.Test)

Aggregations

StatusOperationResult (org.syncany.operations.status.StatusOperationResult)9 File (java.io.File)5 SqlDatabase (org.syncany.database.SqlDatabase)5 UpOperationResult (org.syncany.operations.up.UpOperationResult)5 Test (org.junit.Test)4 LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)4 TransferSettings (org.syncany.plugins.transfer.TransferSettings)4 TestClient (org.syncany.tests.util.TestClient)4 FilenameFilter (java.io.FilenameFilter)3 ChangeSet (org.syncany.operations.ChangeSet)3 StatusOperation (org.syncany.operations.status.StatusOperation)3 RandomAccessFile (java.io.RandomAccessFile)2 StatusOperationOptions (org.syncany.operations.status.StatusOperationOptions)2 LockFile (org.syncany.tests.integration.scenarios.framework.LockFile)2 UnlockFile (org.syncany.tests.integration.scenarios.framework.UnlockFile)2 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Random (java.util.Random)1 Set (java.util.Set)1