Search in sources :

Example 1 with TransferManager

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

the class AbstractInitOperation method createTransferManagerFromNullConfig.

protected TransferManager createTransferManagerFromNullConfig(ConfigTO configTo) throws IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchMethodException, StorageException {
    // Init plugin and transfer manager
    TransferPlugin plugin = Plugins.get(configTo.getTransferSettings().getType(), TransferPlugin.class);
    TransferSettings transferSettings = configTo.getTransferSettings();
    transferSettings.setUserInteractionListener(listener);
    TransferManager transferManager = plugin.createTransferManager(transferSettings, config);
    // constructor is not visible and config seems to be null at this point, hence we cannot use the build method here
    Constructor<TransferManagerBuilder> tmbConstructor = TransferManagerBuilder.class.getDeclaredConstructor(Config.class, TransferManager.class);
    tmbConstructor.setAccessible(true);
    return tmbConstructor.newInstance(config, transferManager).withFeature(ReadAfterWriteConsistent.class).asDefault();
}
Also used : TransferPlugin(org.syncany.plugins.transfer.TransferPlugin) TransferManager(org.syncany.plugins.transfer.TransferManager) ReadAfterWriteConsistent(org.syncany.plugins.transfer.features.ReadAfterWriteConsistent) TransferSettings(org.syncany.plugins.transfer.TransferSettings) TransferManagerBuilder(org.syncany.plugins.transfer.TransferManagerFactory.TransferManagerBuilder)

Example 2 with TransferManager

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

the class CleanupInterruptedTest method testUnreliableCleanup_Test2_databaseFileMerge.

@Test
public void testUnreliableCleanup_Test2_databaseFileMerge() throws Exception {
    // Setup
    UnreliableLocalTransferSettings testConnection = TestConfigUtil.createTestUnreliableLocalConnection(Arrays.asList(new String[] { // << 3 retries!!
    "rel=(11|12|13).+upload.+database" }));
    TestClient clientA = new TestClient("A", testConnection);
    clientA.createNewFile("file");
    clientA.up();
    clientA.changeFile("file");
    clientA.upWithForceChecksum();
    CleanupOperationOptions cleanupOptions = new CleanupOperationOptions();
    cleanupOptions.setMaxDatabaseFiles(1);
    cleanupOptions.setPurgeFileVersionSettings(new TreeMap<Long, TimeUnit>());
    boolean cleanupFailed = false;
    try {
        clientA.cleanup(cleanupOptions);
    } catch (StorageException e) {
        cleanupFailed = true;
    }
    assertTrue(cleanupFailed);
    TransferManager transferManagerA = TransferManagerFactory.build(clientA.getConfig()).withFeature(TransactionAware.class).asDefault();
    assertEquals(2, transferManagerA.list(MultichunkRemoteFile.class).size());
    assertEquals(2, new File(testConnection.getPath(), "multichunks").list().length);
    // Note that the list here differs from the actual files, because the transaction fails
    // while deletions have been done
    assertEquals(2, transferManagerA.list(DatabaseRemoteFile.class).size());
    assertEquals(0, new File(testConnection.getPath(), "databases").list().length);
    assertEquals(1, transferManagerA.list(TransactionRemoteFile.class).size());
    assertEquals(1, new File(testConnection.getPath(), "transactions").list().length);
    assertEquals(1, transferManagerA.list(ActionRemoteFile.class).size());
    assertEquals(1, new File(testConnection.getPath(), "actions").list().length);
    File tempDir = TestFileUtil.createTempDirectoryInSystemTemp();
    File tempFile = File.createTempFile("multichunk", "", tempDir);
    for (RemoteFile remoteFile : transferManagerA.list(DatabaseRemoteFile.class).values()) {
        transferManagerA.download(remoteFile, tempFile);
        assertTrue(tempFile.exists());
        tempFile.delete();
    }
    // Cleanup should have merged the two files.
    CleanupOperationResult result = clientA.cleanup(cleanupOptions);
    assertEquals(CleanupResultCode.OK, result.getResultCode());
    assertEquals(2, result.getMergedDatabaseFilesCount());
    assertEquals(2, transferManagerA.list(MultichunkRemoteFile.class).size());
    assertEquals(2, new File(testConnection.getPath(), "multichunks").list().length);
    assertEquals(1, transferManagerA.list(DatabaseRemoteFile.class).size());
    assertEquals(1, new File(testConnection.getPath(), "databases").list(new FilenameFilter() {

        public boolean accept(File dir, String name) {
            return name.startsWith("database-");
        }
    }).length);
    assertEquals(0, transferManagerA.list(TransactionRemoteFile.class).size());
    assertEquals(0, new File(testConnection.getPath(), "transactions").list().length);
    assertEquals(0, transferManagerA.list(ActionRemoteFile.class).size());
    assertEquals(0, new File(testConnection.getPath(), "actions").list().length);
    clientA.deleteTestData();
}
Also used : TransferManager(org.syncany.plugins.transfer.TransferManager) CleanupOperationResult(org.syncany.operations.cleanup.CleanupOperationResult) CleanupOperationOptions(org.syncany.operations.cleanup.CleanupOperationOptions) FilenameFilter(java.io.FilenameFilter) TransactionAware(org.syncany.plugins.transfer.features.TransactionAware) UnreliableLocalTransferSettings(org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) TimeUnit(org.syncany.operations.cleanup.CleanupOperationOptions.TimeUnit) StorageException(org.syncany.plugins.transfer.StorageException) RemoteFile(org.syncany.plugins.transfer.files.RemoteFile) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) TempRemoteFile(org.syncany.plugins.transfer.files.TempRemoteFile) ActionRemoteFile(org.syncany.plugins.transfer.files.ActionRemoteFile) TransactionRemoteFile(org.syncany.plugins.transfer.files.TransactionRemoteFile) File(java.io.File) MultichunkRemoteFile(org.syncany.plugins.transfer.files.MultichunkRemoteFile) RemoteFile(org.syncany.plugins.transfer.files.RemoteFile) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) TempRemoteFile(org.syncany.plugins.transfer.files.TempRemoteFile) ActionRemoteFile(org.syncany.plugins.transfer.files.ActionRemoteFile) TransactionRemoteFile(org.syncany.plugins.transfer.files.TransactionRemoteFile) MultichunkRemoteFile(org.syncany.plugins.transfer.files.MultichunkRemoteFile) Test(org.junit.Test)

Example 3 with TransferManager

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

the class CleanupInterruptedTest method testUnreliableCleanup_Test3_unreferencedTempFiles.

@Test
public void testUnreliableCleanup_Test3_unreferencedTempFiles() throws Exception {
    // Setup
    UnreliableLocalTransferSettings testConnection = TestConfigUtil.createTestUnreliableLocalConnection(Arrays.asList(new String[] { // << 3 retries!!
    "rel=[678].+delete.+temp" }));
    TestClient clientA = new TestClient("A", testConnection);
    clientA.createNewFile("file");
    clientA.up();
    clientA.changeFile("file");
    clientA.upWithForceChecksum();
    CleanupOperationOptions cleanupOptions = new CleanupOperationOptions();
    cleanupOptions.setMinSecondsBetweenCleanups(0);
    cleanupOptions.setMinKeepSeconds(0);
    clientA.cleanup(cleanupOptions);
    TransferManager transferManagerA = TransferManagerFactory.build(clientA.getConfig()).withFeature(TransactionAware.class).asDefault();
    assertEquals(1, transferManagerA.list(MultichunkRemoteFile.class).size());
    assertEquals(1, new File(testConnection.getPath(), "multichunks").list().length);
    assertEquals(1, transferManagerA.list(DatabaseRemoteFile.class).size());
    assertEquals(1, new File(testConnection.getPath(), "databases").list(new FilenameFilter() {

        public boolean accept(File dir, String name) {
            return name.startsWith("database-");
        }
    }).length);
    assertEquals(0, transferManagerA.list(TransactionRemoteFile.class).size());
    assertEquals(0, new File(testConnection.getPath(), "transactions").list().length);
    assertEquals(0, transferManagerA.list(ActionRemoteFile.class).size());
    assertEquals(0, new File(testConnection.getPath(), "actions").list().length);
    // One deletion failed
    assertEquals(1, transferManagerA.list(TempRemoteFile.class).size());
    assertEquals(1, new File(testConnection.getPath(), "temporary").list().length);
    // Change something to trigger cleanup
    clientA.changeFile("file");
    clientA.up();
    CleanupOperationResult result = clientA.cleanup(cleanupOptions);
    // Functional cleanup results in removal of action file and unreferenced files
    assertEquals(0, transferManagerA.list(ActionRemoteFile.class).size());
    assertEquals(0, new File(testConnection.getPath(), "actions").list().length);
    assertEquals(0, transferManagerA.list(TempRemoteFile.class).size());
    assertEquals(0, new File(testConnection.getPath(), "temporary").list().length);
    clientA.deleteTestData();
}
Also used : TransferManager(org.syncany.plugins.transfer.TransferManager) FilenameFilter(java.io.FilenameFilter) CleanupOperationResult(org.syncany.operations.cleanup.CleanupOperationResult) TransactionAware(org.syncany.plugins.transfer.features.TransactionAware) UnreliableLocalTransferSettings(org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) CleanupOperationOptions(org.syncany.operations.cleanup.CleanupOperationOptions) RemoteFile(org.syncany.plugins.transfer.files.RemoteFile) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) TempRemoteFile(org.syncany.plugins.transfer.files.TempRemoteFile) ActionRemoteFile(org.syncany.plugins.transfer.files.ActionRemoteFile) TransactionRemoteFile(org.syncany.plugins.transfer.files.TransactionRemoteFile) File(java.io.File) MultichunkRemoteFile(org.syncany.plugins.transfer.files.MultichunkRemoteFile) Test(org.junit.Test)

Example 4 with TransferManager

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

the class AbstractTransferManagerTest method testConnectWithInvalidSettings.

@Test(expected = StorageException.class)
public void testConnectWithInvalidSettings() throws StorageException {
    TransferPlugin plugin = Plugins.get(getPluginId(), TransferPlugin.class);
    TransferSettings connection = plugin.createEmptySettings();
    // This should cause a Storage exception, because the path does not exist
    TransferManager transferManager = plugin.createTransferManager(connection, null);
    transferManager.connect();
}
Also used : TransferPlugin(org.syncany.plugins.transfer.TransferPlugin) TransferManager(org.syncany.plugins.transfer.TransferManager) TransactionAwareFeatureTransferManager(org.syncany.plugins.transfer.features.TransactionAwareFeatureTransferManager) TransferSettings(org.syncany.plugins.transfer.TransferSettings) Test(org.junit.Test)

Example 5 with TransferManager

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

the class AbstractTransferManagerTest method loadPluginAndCreateTransferManager.

private TransferManager loadPluginAndCreateTransferManager() throws StorageException {
    TransferPlugin pluginInfo = Plugins.get(getPluginId(), TransferPlugin.class);
    TransferSettings connection = pluginInfo.createEmptySettings();
    for (Map.Entry<String, String> pair : createPluginSettings().entrySet()) {
        connection.setField(pair.getKey(), pair.getValue());
    }
    TransferManager originalTransferManager = pluginInfo.createTransferManager(connection, null);
    return new TransactionAwareFeatureTransferManager(originalTransferManager, originalTransferManager, null, null);
}
Also used : TransferPlugin(org.syncany.plugins.transfer.TransferPlugin) TransferManager(org.syncany.plugins.transfer.TransferManager) TransactionAwareFeatureTransferManager(org.syncany.plugins.transfer.features.TransactionAwareFeatureTransferManager) TransactionAwareFeatureTransferManager(org.syncany.plugins.transfer.features.TransactionAwareFeatureTransferManager) TransferSettings(org.syncany.plugins.transfer.TransferSettings) Map(java.util.Map)

Aggregations

TransferManager (org.syncany.plugins.transfer.TransferManager)12 Test (org.junit.Test)8 File (java.io.File)7 MultichunkRemoteFile (org.syncany.plugins.transfer.files.MultichunkRemoteFile)7 TransactionAware (org.syncany.plugins.transfer.features.TransactionAware)5 DatabaseRemoteFile (org.syncany.plugins.transfer.files.DatabaseRemoteFile)5 UnreliableLocalTransferSettings (org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings)5 TestClient (org.syncany.tests.util.TestClient)5 FilenameFilter (java.io.FilenameFilter)4 StorageException (org.syncany.plugins.transfer.StorageException)4 TransactionAwareFeatureTransferManager (org.syncany.plugins.transfer.features.TransactionAwareFeatureTransferManager)4 RemoteFile (org.syncany.plugins.transfer.files.RemoteFile)4 CleanupOperationOptions (org.syncany.operations.cleanup.CleanupOperationOptions)3 TransferPlugin (org.syncany.plugins.transfer.TransferPlugin)3 TransferSettings (org.syncany.plugins.transfer.TransferSettings)3 ActionRemoteFile (org.syncany.plugins.transfer.files.ActionRemoteFile)3 TempRemoteFile (org.syncany.plugins.transfer.files.TempRemoteFile)3 TransactionRemoteFile (org.syncany.plugins.transfer.files.TransactionRemoteFile)3 Persister (org.simpleframework.xml.core.Persister)2 CleanupOperationResult (org.syncany.operations.cleanup.CleanupOperationResult)2