Search in sources :

Example 1 with UpOperation

use of org.syncany.operations.up.UpOperation in project syncany by syncany.

the class StatusOperationTest method testNotSoRecentFileModificationWithoutSizeOrModifiedDateChange.

@Test
public void testNotSoRecentFileModificationWithoutSizeOrModifiedDateChange() throws Exception {
    // Setup
    Config config = TestConfigUtil.createTestLocalConfig();
    File testFile = TestFileUtil.createRandomFileInDirectory(config.getLocalDir(), 40);
    // Perform 'up', wait a second and then change test file
    // IMPORTANT: Sleep to prevent detailed checksum-based update check in 'status' operation
    new UpOperation(config).execute();
    Thread.sleep(2000);
    TestFileUtil.changeRandomPartOfBinaryFile(testFile);
    // Run 'status', this should NOT run a checksum-based file comparison
    ChangeSet changeSet = (new StatusOperation(config).execute()).getChangeSet();
    assertEquals(changeSet.getChangedFiles().size(), 1);
    // Cleanup 
    TestConfigUtil.deleteTestLocalConfigAndData(config);
}
Also used : UpOperation(org.syncany.operations.up.UpOperation) StatusOperation(org.syncany.operations.status.StatusOperation) Config(org.syncany.config.Config) File(java.io.File) ChangeSet(org.syncany.operations.ChangeSet) Test(org.junit.Test)

Example 2 with UpOperation

use of org.syncany.operations.up.UpOperation in project syncany by syncany.

the class StatusOperationTest method testCreateFolderAndRunStatus.

@Test
public void testCreateFolderAndRunStatus() throws Exception {
    // Setup
    Config config = TestConfigUtil.createTestLocalConfig();
    new File(config.getLocalDir() + "/somefolder").mkdir();
    // Run 'status', this SHOULD list the folder
    ChangeSet changeSet = (new StatusOperation(config).execute()).getChangeSet();
    assertEquals(changeSet.getNewFiles().size(), 1);
    assertEquals(changeSet.getChangedFiles().size(), 0);
    assertEquals(changeSet.getDeletedFiles().size(), 0);
    assertEquals(changeSet.getUnchangedFiles().size(), 0);
    // Run 'up' to check in the folder
    new UpOperation(config).execute();
    // Run 'status', this SHOULD NOT list the folder in the changed/new files
    changeSet = (new StatusOperation(config).execute()).getChangeSet();
    assertEquals(changeSet.getNewFiles().size(), 0);
    assertEquals(changeSet.getChangedFiles().size(), 0);
    assertEquals(changeSet.getDeletedFiles().size(), 0);
    assertEquals(changeSet.getUnchangedFiles().size(), 1);
    // Cleanup 
    TestConfigUtil.deleteTestLocalConfigAndData(config);
}
Also used : UpOperation(org.syncany.operations.up.UpOperation) StatusOperation(org.syncany.operations.status.StatusOperation) Config(org.syncany.config.Config) File(java.io.File) ChangeSet(org.syncany.operations.ChangeSet) Test(org.junit.Test)

Example 3 with UpOperation

use of org.syncany.operations.up.UpOperation in project syncany by syncany.

the class OperationPerformanceTest method testOperationPerformance.

@Test
public void testOperationPerformance() throws Exception {
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    Config configA = TestConfigUtil.createTestLocalConfig("A", testConnection);
    Config configB = TestConfigUtil.createTestLocalConfig("B", testConnection);
    // Add new files on A and upload it 
    TestFileUtil.createRandomFilesInDirectory(configA.getLocalDir(), 5000 * 1024, 3);
    long timeSyncUpStart = System.currentTimeMillis();
    new UpOperation(configA).execute();
    long timeSyncUpEnd = System.currentTimeMillis();
    long timeSyncUpTotal = timeSyncUpEnd - timeSyncUpStart;
    if (timeSyncUpTotal > 3000) {
        fail("Sync up took: " + timeSyncUpTotal + " ms");
    }
    logger.log(Level.INFO, "Sync up performance: " + timeSyncUpTotal + " ms");
    // Sync down B
    long timeSyncDownStart = System.currentTimeMillis();
    new DownOperation(configB).execute();
    long timeSyncDownEnd = System.currentTimeMillis();
    long timeSyncDownTotal = timeSyncDownEnd - timeSyncDownStart;
    if (timeSyncDownTotal > 3000) {
        fail("Sync down took: " + timeSyncDownTotal + " ms");
    }
    logger.log(Level.INFO, "Sync down performance: " + timeSyncDownTotal + " ms");
    // Cleanup
    TestConfigUtil.deleteTestLocalConfigAndData(configA);
    TestConfigUtil.deleteTestLocalConfigAndData(configB);
}
Also used : UpOperation(org.syncany.operations.up.UpOperation) Config(org.syncany.config.Config) DownOperation(org.syncany.operations.down.DownOperation) TransferSettings(org.syncany.plugins.transfer.TransferSettings) Test(org.junit.Test)

Example 4 with UpOperation

use of org.syncany.operations.up.UpOperation in project syncany by syncany.

the class UpCommand method execute.

@Override
public int execute(String[] operationArgs) throws Exception {
    UpOperationOptions operationOptions = parseOptions(operationArgs);
    UpOperationResult operationResult = new UpOperation(config, operationOptions).execute();
    printResults(operationResult);
    return 0;
}
Also used : UpOperation(org.syncany.operations.up.UpOperation) UpOperationOptions(org.syncany.operations.up.UpOperationOptions) UpOperationResult(org.syncany.operations.up.UpOperationResult)

Example 5 with UpOperation

use of org.syncany.operations.up.UpOperation in project syncany by syncany.

the class WatchOperation method runSync.

/**
	 * Runs one iteration of the main synchronization loop, containing a {@link DownOperation},
	 * an {@link UpOperation} and (if required), a {@link CleanupOperation}.
	 */
private void runSync() throws Exception {
    if (!syncRunning.get()) {
        syncRunning.set(true);
        syncRequested.set(false);
        logger.log(Level.INFO, "RUNNING SYNC ...");
        fireStartEvent();
        try {
            boolean notifyChanges = false;
            // Run down
            DownOperationResult downResult = new DownOperation(config, options.getDownOptions()).execute();
            if (downResult.getResultCode() == DownResultCode.OK_WITH_REMOTE_CHANGES) {
            // TODO [low] Do something?
            }
            // Run up
            UpOperationResult upOperationResult = new UpOperation(config, options.getUpOptions()).execute();
            if (upOperationResult.getResultCode() == UpResultCode.OK_CHANGES_UPLOADED && upOperationResult.getChangeSet().hasChanges()) {
                upCount.incrementAndGet();
                notifyChanges = true;
            }
            CleanupOperationResult cleanupOperationResult = new CleanupOperation(config, options.getCleanupOptions()).execute();
            if (cleanupOperationResult.getResultCode() == CleanupResultCode.OK) {
                notifyChanges = true;
            }
            // Fire change event if up and/or cleanup
            if (notifyChanges) {
                notifyChanges();
            }
        } finally {
            logger.log(Level.INFO, "SYNC DONE.");
            syncRunning.set(false);
            fireEndEvent();
        }
    } else {
        // Can't do a log message here, because this bit is called thousand
        // of times when file system events occur.
        syncRequested.set(true);
    }
}
Also used : UpOperation(org.syncany.operations.up.UpOperation) CleanupOperationResult(org.syncany.operations.cleanup.CleanupOperationResult) DownOperationResult(org.syncany.operations.down.DownOperationResult) DownOperation(org.syncany.operations.down.DownOperation) CleanupOperation(org.syncany.operations.cleanup.CleanupOperation) UpOperationResult(org.syncany.operations.up.UpOperationResult)

Aggregations

UpOperation (org.syncany.operations.up.UpOperation)10 File (java.io.File)7 Test (org.junit.Test)7 Config (org.syncany.config.Config)6 ChangeSet (org.syncany.operations.ChangeSet)4 StatusOperation (org.syncany.operations.status.StatusOperation)4 UpOperationOptions (org.syncany.operations.up.UpOperationOptions)3 UpOperationResult (org.syncany.operations.up.UpOperationResult)3 ArrayList (java.util.ArrayList)2 DatabaseXmlSerializer (org.syncany.database.dao.DatabaseXmlSerializer)2 AbstractTransferOperation (org.syncany.operations.AbstractTransferOperation)2 DownOperation (org.syncany.operations.down.DownOperation)2 StatusOperationOptions (org.syncany.operations.status.StatusOperationOptions)2 LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)2 DatabaseVersion (org.syncany.database.DatabaseVersion)1 FileVersion (org.syncany.database.FileVersion)1 MemoryDatabase (org.syncany.database.MemoryDatabase)1 PartialFileHistory (org.syncany.database.PartialFileHistory)1 FileHistoryId (org.syncany.database.PartialFileHistory.FileHistoryId)1 SqlDatabase (org.syncany.database.SqlDatabase)1