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();
}
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);
}
}
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);
}
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);
}
}
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;
}
Aggregations