Search in sources :

Example 31 with TransferSettings

use of org.syncany.plugins.transfer.TransferSettings in project syncany by syncany.

the class SingleFileNoConflictsScenarioTest method testSingleFileMoveNoConflicts.

@Test
public void testSingleFileMoveNoConflicts() throws Exception {
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    // Create files and upload
    clientA.createNewFile("file");
    clientA.up();
    clientB.down();
    assertFileEquals(clientA.getLocalFile("file"), clientB.getLocalFile("file"));
    clientB.moveFile("file", "moved");
    clientB.up();
    clientA.down();
    assertFalse("Originally moved file should not exist.", clientA.getLocalFile("file").exists());
    assertFileEquals(clientA.getLocalFile("moved"), clientB.getLocalFile("moved"));
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    // Cleanup
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : TestClient(org.syncany.tests.util.TestClient) TransferSettings(org.syncany.plugins.transfer.TransferSettings) Test(org.junit.Test)

Example 32 with TransferSettings

use of org.syncany.plugins.transfer.TransferSettings in project syncany by syncany.

the class ApplicationLink method createTransferSettings.

private TransferSettings createTransferSettings(byte[] plaintextPluginSettingsBytes) throws StorageException, IOException {
    // Find plugin ID and settings XML
    int pluginIdentifierLength = Ints.fromByteArray(Arrays.copyOfRange(plaintextPluginSettingsBytes, 0, INTEGER_BYTES));
    String pluginId = new String(Arrays.copyOfRange(plaintextPluginSettingsBytes, INTEGER_BYTES, INTEGER_BYTES + pluginIdentifierLength));
    byte[] gzippedPluginSettingsByteArray = Arrays.copyOfRange(plaintextPluginSettingsBytes, INTEGER_BYTES + pluginIdentifierLength, plaintextPluginSettingsBytes.length);
    String pluginSettings = IOUtils.toString(new GZIPInputStream(new ByteArrayInputStream(gzippedPluginSettingsByteArray)));
    // Create transfer settings object
    try {
        TransferPlugin plugin = Plugins.get(pluginId, TransferPlugin.class);
        if (plugin == null) {
            throw new StorageException("Link contains unknown connection type '" + pluginId + "'. Corresponding plugin not found.");
        }
        Class<? extends TransferSettings> pluginTransferSettingsClass = TransferPluginUtil.getTransferSettingsClass(plugin.getClass());
        TransferSettings transferSettings = new Persister().read(pluginTransferSettingsClass, pluginSettings);
        logger.log(Level.INFO, "(Decrypted) link contains: " + pluginId + " -- " + pluginSettings);
        return transferSettings;
    } catch (Exception e) {
        throw new StorageException(e);
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) TransferPlugin(org.syncany.plugins.transfer.TransferPlugin) ByteArrayInputStream(java.io.ByteArrayInputStream) TransferSettings(org.syncany.plugins.transfer.TransferSettings) Persister(org.simpleframework.xml.core.Persister) StorageException(org.syncany.plugins.transfer.StorageException) StorageException(org.syncany.plugins.transfer.StorageException) IOException(java.io.IOException)

Example 33 with TransferSettings

use of org.syncany.plugins.transfer.TransferSettings 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 34 with TransferSettings

use of org.syncany.plugins.transfer.TransferSettings in project syncany by syncany.

the class AbstractInitCommand method askGenericChildPluginSettings.

/**
 * Queries the user for a plugin (which plugin to use?) and then
 * asks for all of the plugin's settings.
 *
 * <p>This case is triggered by a field looking like this:
 * <tt>private TransferSettings childPluginSettings;</tt>
 */
private void askGenericChildPluginSettings(TransferSettings settings, TransferPluginOption option, Map<String, String> knownPluginSettings, String nestPrefix) throws StorageException, IllegalAccessException, InstantiationException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
    TransferPluginOptionCallback optionCallback = createOptionCallback(settings, option.getCallback());
    if (isInteractive) {
        callAndPrintPreQueryCallback(optionCallback);
        out.println();
        out.println(option.getDescription() + ":");
    }
    TransferPlugin childPlugin = null;
    Class<? extends TransferPlugin> pluginClass = TransferPluginUtil.getTransferPluginClass(settings.getClass());
    // Non-interactive: Plugin settings might be given via command line
    try {
        childPlugin = initPlugin(knownPluginSettings.get(nestPrefix + option.getName() + GENERIC_PLUGIN_TYPE_IDENTIFIER));
    } catch (Exception e) {
        if (!isInteractive) {
            throw new IllegalArgumentException("Missing nested plugin type (" + nestPrefix + option.getName() + GENERIC_PLUGIN_TYPE_IDENTIFIER + ") in non-interactive mode.");
        }
    }
    // Interactive mode: Ask for sub-plugin
    while (childPlugin == null) {
        childPlugin = askPlugin(pluginClass);
    }
    if (isInteractive) {
        out.println();
    }
    // Create nested/child settings
    TransferSettings childSettings = childPlugin.createEmptySettings();
    settings.setField(option.getField().getName(), childSettings);
    nestPrefix = nestPrefix + option.getName() + NESTED_OPTIONS_SEPARATOR;
    for (TransferPluginOption nestedOption : TransferPluginOptions.getOrderedOptions(childSettings.getClass())) {
        askPluginSettings(childSettings, nestedOption, knownPluginSettings, nestPrefix);
    }
    if (isInteractive) {
        callAndPrintPostQueryCallback(optionCallback, null);
    }
}
Also used : TransferPlugin(org.syncany.plugins.transfer.TransferPlugin) TransferPluginOptionCallback(org.syncany.plugins.transfer.TransferPluginOptionCallback) TransferPluginOption(org.syncany.plugins.transfer.TransferPluginOption) NestedTransferPluginOption(org.syncany.plugins.transfer.NestedTransferPluginOption) TransferSettings(org.syncany.plugins.transfer.TransferSettings) TimeoutException(java.util.concurrent.TimeoutException) StorageException(org.syncany.plugins.transfer.StorageException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ExecutionException(java.util.concurrent.ExecutionException)

Example 35 with TransferSettings

use of org.syncany.plugins.transfer.TransferSettings in project syncany by syncany.

the class ConnectCommand method parseOptions.

@Override
public ConnectOperationOptions parseOptions(String[] operationArgs) throws Exception {
    ConnectOperationOptions operationOptions = new ConnectOperationOptions();
    OptionParser parser = new OptionParser();
    OptionSpec<String> optionPlugin = parser.acceptsAll(asList("P", "plugin")).withRequiredArg();
    OptionSpec<String> optionPluginOpts = parser.acceptsAll(asList("o", "plugin-option")).withRequiredArg();
    OptionSpec<Void> optionAddDaemon = parser.acceptsAll(asList("n", "add-daemon"));
    OptionSpec<String> optionPassword = parser.acceptsAll(asList("password")).withRequiredArg();
    OptionSet options = parser.parse(operationArgs);
    List<?> nonOptionArgs = options.nonOptionArguments();
    // Set interactivity mode
    isInteractive = !options.has(optionPlugin) && !options.has(optionPassword);
    // Plugin
    TransferSettings transferSettings = null;
    if (nonOptionArgs.size() == 1) {
        String connectLink = (String) nonOptionArgs.get(0);
        operationOptions.setStrategy(ConnectOptionsStrategy.CONNECTION_LINK);
        operationOptions.setConnectLink(connectLink);
        transferSettings = null;
    } else if (nonOptionArgs.size() == 0) {
        operationOptions.setStrategy(ConnectOptionsStrategy.CONNECTION_TO);
        operationOptions.setConnectLink(null);
        transferSettings = createTransferSettingsFromOptions(options, optionPlugin, optionPluginOpts);
    } else {
        throw new Exception("Invalid syntax.");
    }
    ConfigTO configTO = createConfigTO(transferSettings);
    operationOptions.setLocalDir(localDir);
    operationOptions.setConfigTO(configTO);
    operationOptions.setDaemon(options.has(optionAddDaemon));
    operationOptions.setPassword(validateAndGetPassword(options, optionPassword));
    return operationOptions;
}
Also used : TransferSettings(org.syncany.plugins.transfer.TransferSettings) ConfigTO(org.syncany.config.to.ConfigTO) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser) ConnectOperationOptions(org.syncany.operations.init.ConnectOperationOptions)

Aggregations

TransferSettings (org.syncany.plugins.transfer.TransferSettings)78 Test (org.junit.Test)67 TestClient (org.syncany.tests.util.TestClient)65 File (java.io.File)20 LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)10 TransferPlugin (org.syncany.plugins.transfer.TransferPlugin)7 SqlDatabase (org.syncany.database.SqlDatabase)5 DownOperationResult (org.syncany.operations.down.DownOperationResult)4 StatusOperationResult (org.syncany.operations.status.StatusOperationResult)4 UpOperationOptions (org.syncany.operations.up.UpOperationOptions)4 UpOperationResult (org.syncany.operations.up.UpOperationResult)4 CreateFileTree (org.syncany.tests.integration.scenarios.framework.CreateFileTree)4 IOException (java.io.IOException)3 RandomAccessFile (java.io.RandomAccessFile)3 Path (java.nio.file.Path)3 PosixFilePermission (java.nio.file.attribute.PosixFilePermission)3 Config (org.syncany.config.Config)3 ConfigTO (org.syncany.config.to.ConfigTO)3 PartialFileHistory (org.syncany.database.PartialFileHistory)3 FileHistoryId (org.syncany.database.PartialFileHistory.FileHistoryId)3