use of org.syncany.plugins.transfer.StorageException in project syncany by syncany.
the class RemoteFile method createRemoteFile.
/**
* Creates a remote file based on a name and derives the class name using the
* file name.
*
* <p>The name must match the corresponding name pattern (nameprefix-...), and
* the derived class can either be <tt>RemoteFile</tt>, or a sub-class thereof.
*
* @param name The name of the remote file
* @return Returns a new object of the given class
*/
@SuppressWarnings("unchecked")
public static <T extends RemoteFile> T createRemoteFile(String name) throws StorageException {
String prefix = name.contains("-") ? name.substring(0, name.indexOf('-')) : name;
String camelCasePrefix = StringUtil.toCamelCase(prefix);
try {
Class<T> remoteFileClass = (Class<T>) Class.forName(REMOTE_FILE_PACKAGE + "." + camelCasePrefix + REMOTE_FILE_SUFFIX);
return createRemoteFile(name, remoteFileClass);
} catch (ClassNotFoundException | StorageException e) {
logger.log(Level.INFO, "Invalid filename for remote file " + name);
throw new StorageException("Invalid filename for remote file " + name);
}
}
use of org.syncany.plugins.transfer.StorageException in project syncany by syncany.
the class CleanupInterruptedTest method testUnreliableCleanup_Test1_oldVersionRemoval.
@Test
public void testUnreliableCleanup_Test1_oldVersionRemoval() 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.setMinKeepSeconds(0);
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(1, new File(testConnection.getPath(), "multichunks").list().length);
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);
clientA.cleanup(cleanupOptions);
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);
clientA.deleteTestData();
}
use of org.syncany.plugins.transfer.StorageException in project syncany by syncany.
the class CleanupInterruptedTest method testUnreliableCleanup_failBlocksOtherClients.
@Test
public void testUnreliableCleanup_failBlocksOtherClients() throws Exception {
// Setup
UnreliableLocalTransferSettings testConnection = TestConfigUtil.createTestUnreliableLocalConnection(Arrays.asList(new String[] { // << 3 retries!!
"rel=(12|13|14).+upload.+database" }));
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
clientA.createNewFile("file");
clientA.up();
clientA.changeFile("file");
clientA.upWithForceChecksum();
clientB.down();
CleanupOperationOptions cleanupOptions = new CleanupOperationOptions();
cleanupOptions.setMinKeepSeconds(0);
boolean cleanupFailed = false;
try {
clientA.cleanup(cleanupOptions);
} catch (StorageException e) {
cleanupFailed = true;
}
assertTrue(cleanupFailed);
// Pretend time has passed by deleting the action file:
TestFileUtil.deleteFile(new File(testConnection.getPath(), "/actions/").listFiles()[0]);
CleanupOperationResult cleanupResult = clientB.cleanup(cleanupOptions);
assertEquals(CleanupResultCode.NOK_REPO_BLOCKED, cleanupResult.getResultCode());
clientB.createNewFile("file2");
UpOperationResult upResult = clientB.up();
assertEquals(UpResultCode.NOK_REPO_BLOCKED, upResult.getResultCode());
clientA.deleteTestData();
clientB.deleteTestData();
}
use of org.syncany.plugins.transfer.StorageException 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.StorageException in project syncany by syncany.
the class UploadInterruptedTest method testUnreliableUpload_FailOnceThenResume.
@Test
public void testUnreliableUpload_FailOnceThenResume() throws Exception {
// Setup
UnreliableLocalTransferSettings testConnection = TestConfigUtil.createTestUnreliableLocalConnection(Arrays.asList(new String[] { // << 3 retries!!
"rel=[345] .+upload.+multichunk" }));
TestClient clientA = new TestClient("A", testConnection);
clientA.createNewFile("file-1.txt");
boolean failed = false;
try {
clientA.up();
} catch (StorageException e) {
failed = true;
}
assertTrue(failed);
TestClient clientB = new TestClient("B", testConnection);
clientB.down();
assertEquals(0, clientB.getLocalFiles().size());
UpOperationOptions upOptions = new UpOperationOptions();
upOptions.setResume(true);
upOptions.setForceUploadEnabled(true);
clientA.up(upOptions);
clientB.down();
assertEquals(1, clientB.getLocalFiles().size());
assertTrue(clientB.getLocalFile("file-1.txt").exists());
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
}
Aggregations