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