Search in sources :

Example 6 with TransferManager

use of org.syncany.plugins.transfer.TransferManager 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();
}
Also used : TransferManager(org.syncany.plugins.transfer.TransferManager) FilenameFilter(java.io.FilenameFilter) 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) 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) Test(org.junit.Test)

Example 7 with TransferManager

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

the class LsRemoteOperation method execute.

@Override
public LsRemoteOperationResult execute() throws Exception {
    logger.log(Level.INFO, "");
    logger.log(Level.INFO, "Running 'Remote Status' at client " + config.getMachineName() + " ...");
    logger.log(Level.INFO, "--------------------------------------------");
    eventBus.post(new LsRemoteStartSyncExternalEvent(config.getLocalDir().getAbsolutePath()));
    TransferManager transferManager = createTransferManager(loadedTransferManager);
    List<DatabaseRemoteFile> knownDatabases = localDatabase.getKnownDatabases();
    List<DatabaseRemoteFile> unknownRemoteDatabases = listUnknownRemoteDatabases(transferManager, knownDatabases);
    transferManager.disconnect();
    boolean hasChanges = unknownRemoteDatabases.size() > 0;
    eventBus.post(new LsRemoteEndSyncExternalEvent(config.getLocalDir().getAbsolutePath(), hasChanges));
    return new LsRemoteOperationResult(new ArrayList<>(unknownRemoteDatabases));
}
Also used : TransferManager(org.syncany.plugins.transfer.TransferManager) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) LsRemoteStartSyncExternalEvent(org.syncany.operations.daemon.messages.LsRemoteStartSyncExternalEvent) LsRemoteEndSyncExternalEvent(org.syncany.operations.daemon.messages.LsRemoteEndSyncExternalEvent)

Example 8 with TransferManager

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

the class GetFileFolderRequestHandler method handleRequest.

@Override
public Response handleRequest(FolderRequest request) {
    GetFileFolderRequest concreteRequest = (GetFileFolderRequest) request;
    try {
        FileHistoryId fileHistoryId = FileHistoryId.parseFileId(concreteRequest.getFileHistoryId());
        long version = concreteRequest.getVersion();
        FileVersion fileVersion = localDatabase.getFileVersion(fileHistoryId, version);
        FileContent fileContent = localDatabase.getFileContent(fileVersion.getChecksum(), true);
        Map<ChunkChecksum, MultiChunkId> multiChunks = localDatabase.getMultiChunkIdsByChecksums(fileContent.getChunks());
        TransferManager transferManager = config.getTransferPlugin().createTransferManager(config.getConnection(), config);
        Downloader downloader = new Downloader(config, transferManager);
        Assembler assembler = new Assembler(config, localDatabase);
        downloader.downloadAndDecryptMultiChunks(new HashSet<MultiChunkId>(multiChunks.values()));
        File tempFile = assembler.assembleToCache(fileVersion);
        String tempFileToken = StringUtil.toHex(ObjectId.secureRandomBytes(40));
        GetFileFolderResponse fileResponse = new GetFileFolderResponse(concreteRequest.getId(), concreteRequest.getRoot(), tempFileToken);
        GetFileFolderResponseInternal fileResponseInternal = new GetFileFolderResponseInternal(fileResponse, tempFile);
        eventBus.post(fileResponseInternal);
        return null;
    } catch (Exception e) {
        logger.log(Level.WARNING, "Cannot reassemble file.", e);
        return new BadRequestResponse(concreteRequest.getId(), "Cannot reassemble file.");
    }
}
Also used : TransferManager(org.syncany.plugins.transfer.TransferManager) FileHistoryId(org.syncany.database.PartialFileHistory.FileHistoryId) MultiChunkId(org.syncany.database.MultiChunkEntry.MultiChunkId) Downloader(org.syncany.operations.Downloader) ChunkChecksum(org.syncany.database.ChunkEntry.ChunkChecksum) FileContent(org.syncany.database.FileContent) FileVersion(org.syncany.database.FileVersion) Assembler(org.syncany.operations.Assembler) File(java.io.File)

Example 9 with TransferManager

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

the class UploadInterruptedTest method testUnreliableUpload_Test4_2_FailsAtTXCommitDuring2ndMultiChunkMove.

@Test
public void testUnreliableUpload_Test4_2_FailsAtTXCommitDuring2ndMultiChunkMove() throws Exception {
    /*
		 * First run "Client A": This test fails when trying to execute the TX.commit() when moving the second multichunk. So the first multichunk was
		 * moved successfully.
		 *
		 * Double check by "Client B": Client B should not see this multichunk on TM.list()
		 *
		 * Second run "Client A": The second up() from Client A should revert the transaction. To verify this, we let the second run fail at the
		 * transaction file upload
		 *
		 * 1. upload(action-up-987, actions/action-up-987)
		 * 2. upload(transaction-123, transactions/transaction-123) <<< FAILS HERE (second run)
		 * 3. upload(multichunk-1, temp-1)
		 * 4. upload(multichunk-2, temp-2)
		 * 5. upload(database-123, temp-3)
		 * 6. move(temp-1, multichunks/multichunk-1)
		 * 7. move(temp-2, multichunks/multichunk-2) <<< FAILS HERE (first run)
		 * 8. move(temp-3, databases/database-123)
		 */
    // Setup
    UnreliableLocalTransferSettings testConnection = TestConfigUtil.createTestUnreliableLocalConnection(Arrays.asList(new String[] { "rel=[234].+move.+multichunk", "rel=(7|8|9).+upload.+transaction" }));
    TestClient clientA = new TestClient("A", testConnection);
    // << larger than one multichunk!
    clientA.createNewFile("A-original", 5 * 1024 * 1024);
    boolean firstUpFailed = false;
    try {
        clientA.up();
    } catch (StorageException e) {
        firstUpFailed = true;
        logger.log(Level.INFO, e.getMessage());
    }
    assertTrue(firstUpFailed);
    assertEquals(0, new File(testConnection.getPath() + "/databases/").listFiles().length);
    assertEquals(1, new File(testConnection.getPath() + "/multichunks/").listFiles().length);
    assertEquals(1, new File(testConnection.getPath() + "/actions/").listFiles().length);
    assertEquals(1, new File(testConnection.getPath() + "/transactions/").listFiles().length);
    File[] tempFiles = new File(testConnection.getPath() + "/temporary/").listFiles();
    assertEquals(2, tempFiles.length);
    // The second multichunk should be >500 KB
    assertTrue(tempFiles[0].length() > 500 * 1024 || tempFiles[1].length() > 500 * 1024);
    // The database file should be <100 KB
    assertTrue(tempFiles[0].length() < 100 * 1024 || tempFiles[1].length() < 100 * 1024);
    File transactionFile = new File(testConnection.getPath() + "/transactions/").listFiles()[0];
    TransactionTO transactionTO = new Persister().read(TransactionTO.class, transactionFile);
    assertEquals(3, transactionTO.getActions().size());
    assertTrue(transactionTO.getActions().get(0).getRemoteFile().getName().contains("multichunk-"));
    assertTrue(transactionTO.getActions().get(1).getRemoteFile().getName().contains("multichunk-"));
    assertTrue(transactionTO.getActions().get(2).getRemoteFile().getName().contains("database-"));
    // 2. Double check if list() does not return the multichunk
    TransferManager transferManager = TransferManagerFactory.build(clientA.getConfig()).withFeature(TransactionAware.class).asDefault();
    Map<String, MultichunkRemoteFile> multiChunkList = transferManager.list(MultichunkRemoteFile.class);
    assertEquals(0, multiChunkList.size());
    // 3. Second try fails in the beginning, to see if cleanTransactions was successful
    boolean secondUpFailed = false;
    // Do not resume, since we want to clean transactions.
    UpOperationOptions upOptions = new UpOperationOptions();
    upOptions.setResume(false);
    try {
        clientA.up(upOptions);
    } catch (StorageException e) {
        secondUpFailed = true;
        logger.log(Level.INFO, e.getMessage());
    }
    assertTrue(secondUpFailed);
    assertEquals(0, new File(testConnection.getPath() + "/databases/").listFiles().length);
    assertEquals(0, new File(testConnection.getPath() + "/multichunks/").listFiles().length);
    // Shouldn't this be 1
    assertEquals(2, new File(testConnection.getPath() + "/actions/").listFiles().length);
    assertEquals(0, new File(testConnection.getPath() + "/transactions/").listFiles().length);
    assertEquals(0, new File(testConnection.getPath() + "/").listFiles(new FilenameFilter() {

        public boolean accept(File dir, String name) {
            return name.contains("temp-");
        }
    }).length);
    // Tear down
    clientA.deleteTestData();
}
Also used : TransferManager(org.syncany.plugins.transfer.TransferManager) UpOperationOptions(org.syncany.operations.up.UpOperationOptions) TransactionTO(org.syncany.plugins.transfer.to.TransactionTO) FilenameFilter(java.io.FilenameFilter) MultichunkRemoteFile(org.syncany.plugins.transfer.files.MultichunkRemoteFile) TransactionAware(org.syncany.plugins.transfer.features.TransactionAware) UnreliableLocalTransferSettings(org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) Persister(org.simpleframework.xml.core.Persister) StorageException(org.syncany.plugins.transfer.StorageException) File(java.io.File) MultichunkRemoteFile(org.syncany.plugins.transfer.files.MultichunkRemoteFile) Test(org.junit.Test)

Example 10 with TransferManager

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

the class UploadInterruptedTest method testUnreliableUpload_Test4_3_FailsAtTXCommitDuring2ndMultiChunkMoveAndDuringTXRollback.

@Test
public void testUnreliableUpload_Test4_3_FailsAtTXCommitDuring2ndMultiChunkMoveAndDuringTXRollback() throws Exception {
    /*
		 * 1. upload(action-up-987, actions/action-up-987)
		 * 2. upload(transaction-123, transactions/transaction-123)
		 * 3. upload(multichunk-1, temp-1)
		 * 4. upload(multichunk-2, temp-2)
		 * 5. upload(database-123, temp-3)
		 * 6. move(temp-1, multichunks/multichunk-1)
		 * 7. move(temp-2, multichunks/multichunk-2) <<< FAILS HERE (first run)
		 * 8. move(temp-3, databases/database-123)
		 *
		 * 1. upload(action-up-987, actions/action-up-987)
		 * 2. list(databases/*)
		 * 3. list(transactions/*)
		 * 4. upload(transaction-345, transactions/transaction-345) (rollback TX)
		 * 5. move(multichunks/multichunk-1, temp-80)
		 * 6. move(temp-1, temp-81) (silently fails, b/c temp-1 does not exist)
		 * 7. move(multichunks/multichunk-2, temp-82) (silently fails, b/c multichunk-2 does not exist)
		 * 8. move(temp-2, temp-83)
		 * 9. move(databases/database-123, temp-84) (silently fails, b/c database-123 does not exist)
		 * 10. move(temp-3, temp-85)
		 * 10 move(transactions-345, temp-86)
		 * 11. delete(temp-80)
		 * 12. delete(temp-83) <<< FAILS HERE (second run)
		 *
		 * Expected: temp-(83,85,86)
		 */
    // Setup
    UnreliableLocalTransferSettings testConnection = TestConfigUtil.createTestUnreliableLocalConnection(Arrays.asList(new String[] { "rel=[234].+move.+multichunk", "rel=[567].+delete.+database" }));
    TestClient clientA = new TestClient("A", testConnection);
    // << larger than one multichunk!
    clientA.createNewFile("A-original", 5 * 1024 * 1024);
    boolean firstUpFailed = false;
    try {
        clientA.up();
    } catch (StorageException e) {
        firstUpFailed = true;
        logger.log(Level.INFO, e.getMessage());
    }
    assertTrue(firstUpFailed);
    assertEquals(0, new File(testConnection.getPath() + "/databases/").listFiles().length);
    assertEquals(1, new File(testConnection.getPath() + "/multichunks/").listFiles().length);
    assertEquals(1, new File(testConnection.getPath() + "/actions/").listFiles().length);
    assertEquals(1, new File(testConnection.getPath() + "/transactions/").listFiles().length);
    File[] tempFiles = new File(testConnection.getPath() + "/temporary").listFiles();
    assertEquals(2, tempFiles.length);
    // The second multichunk should be >500 KB
    assertTrue(tempFiles[0].length() > 500 * 1024 || tempFiles[1].length() > 500 * 1024);
    // The database file should be <100 KB
    assertTrue(tempFiles[0].length() < 100 * 1024 || tempFiles[1].length() < 100 * 1024);
    File transactionFile = new File(testConnection.getPath() + "/transactions/").listFiles()[0];
    TransactionTO transactionTO = new Persister().read(TransactionTO.class, transactionFile);
    assertEquals(3, transactionTO.getActions().size());
    assertTrue(transactionTO.getActions().get(0).getRemoteFile().getName().contains("multichunk-"));
    assertTrue(transactionTO.getActions().get(1).getRemoteFile().getName().contains("multichunk-"));
    assertTrue(transactionTO.getActions().get(2).getRemoteFile().getName().contains("database-"));
    // 2. Double check if list() does not return the multichunk
    TransferManager transferManager = TransferManagerFactory.build(clientA.getConfig()).withFeature(TransactionAware.class).asDefault();
    Map<String, MultichunkRemoteFile> multiChunkList = transferManager.list(MultichunkRemoteFile.class);
    assertEquals(0, multiChunkList.size());
    // 3. Second try fails in the beginning, to see if cleanTransactions was successful
    boolean secondUpFailed = false;
    // Do not resume, since we want to clean transactions.
    UpOperationOptions upOptions = new UpOperationOptions();
    upOptions.setResume(false);
    try {
        clientA.up(upOptions);
    } catch (StorageException e) {
        secondUpFailed = true;
        logger.log(Level.INFO, e.getMessage());
    }
    assertTrue(secondUpFailed);
    assertEquals(0, new File(testConnection.getPath() + "/databases/").listFiles().length);
    assertEquals(0, new File(testConnection.getPath() + "/multichunks/").listFiles().length);
    // left over, 2 failed ops
    assertEquals(2, new File(testConnection.getPath() + "/actions/").listFiles().length);
    assertEquals(1, new File(testConnection.getPath() + "/transactions/").listFiles().length);
    assertEquals(1, new File(testConnection.getPath() + "/temporary/").listFiles().length);
    // 4. Third try; this should finally succeed
    clientA.up(upOptions);
    assertEquals(1, new File(testConnection.getPath() + "/databases/").listFiles().length);
    assertEquals(2, new File(testConnection.getPath() + "/multichunks/").listFiles().length);
    // cleaned
    assertEquals(0, new File(testConnection.getPath() + "/actions/").listFiles().length);
    assertEquals(0, new File(testConnection.getPath() + "/transactions/").listFiles().length);
    // cleaned
    assertEquals(0, new File(testConnection.getPath() + "/temporary/").listFiles().length);
    // Tear down
    clientA.deleteTestData();
}
Also used : TransferManager(org.syncany.plugins.transfer.TransferManager) UpOperationOptions(org.syncany.operations.up.UpOperationOptions) TransactionTO(org.syncany.plugins.transfer.to.TransactionTO) MultichunkRemoteFile(org.syncany.plugins.transfer.files.MultichunkRemoteFile) TransactionAware(org.syncany.plugins.transfer.features.TransactionAware) UnreliableLocalTransferSettings(org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) Persister(org.simpleframework.xml.core.Persister) StorageException(org.syncany.plugins.transfer.StorageException) File(java.io.File) MultichunkRemoteFile(org.syncany.plugins.transfer.files.MultichunkRemoteFile) Test(org.junit.Test)

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