Search in sources :

Example 11 with UnreliableLocalTransferSettings

use of org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings in project syncany by syncany.

the class TestConfigUtil method createTestUnreliableInitOperationOptions.

public static InitOperationOptions createTestUnreliableInitOperationOptions(String machineName, List<String> failingOperationPatterns) throws Exception {
    InitOperationOptions initOperationOptions = createTestInitOperationOptions(machineName);
    // createTestInitOperationOptions always returns LocalTransferSettings
    File tempRpoDir = ((LocalTransferSettings) initOperationOptions.getConfigTO().getTransferSettings()).getPath();
    UnreliableLocalTransferSettings transferSettings = Plugins.get("unreliable_local", TransferPlugin.class).createEmptySettings();
    transferSettings.setPath(tempRpoDir);
    transferSettings.setFailingOperationPatterns(failingOperationPatterns);
    initOperationOptions.getConfigTO().setTransferSettings(transferSettings);
    return initOperationOptions;
}
Also used : TransferPlugin(org.syncany.plugins.transfer.TransferPlugin) UnreliableLocalTransferPlugin(org.syncany.plugins.unreliable_local.UnreliableLocalTransferPlugin) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) UnreliableLocalTransferSettings(org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings) InitOperationOptions(org.syncany.operations.init.InitOperationOptions) UnreliableLocalTransferSettings(org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings) File(java.io.File)

Example 12 with UnreliableLocalTransferSettings

use of org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings in project syncany by syncany.

the class InitOperationTest method testFaultyInitOperation.

@Test
public void testFaultyInitOperation() throws Exception {
    // Create an unreliable connection
    List<String> failingOperationsPattern = Lists.newArrayList("rel=1.*op=upload");
    InitOperationOptions operationOptions = TestConfigUtil.createTestUnreliableInitOperationOptions("A", failingOperationsPattern);
    InitOperation op = new InitOperation(operationOptions, null);
    File repoDir = ((UnreliableLocalTransferSettings) operationOptions.getConfigTO().getTransferSettings()).getPath();
    File localDir = new File(operationOptions.getLocalDir(), ".syncany");
    try {
        op.execute();
    } catch (StorageException e) {
        logger.log(Level.INFO, "This operation failed because of the unreliable connection.", e);
    }
    // The local directory should not exist, since the uploading of the repo file fails
    // so the local directories should be removed
    assertFalse(localDir.exists());
    // Tear down
    TestFileUtil.deleteDirectory(repoDir);
    TestFileUtil.deleteDirectory(operationOptions.getLocalDir());
}
Also used : InitOperation(org.syncany.operations.init.InitOperation) InitOperationOptions(org.syncany.operations.init.InitOperationOptions) UnreliableLocalTransferSettings(org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings) File(java.io.File) StorageException(org.syncany.plugins.transfer.StorageException) Test(org.junit.Test)

Example 13 with UnreliableLocalTransferSettings

use of org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings in project syncany by syncany.

the class CleanupOperationTest method testCleanupAfterFailedUpOperation.

@Test
public void testCleanupAfterFailedUpOperation() throws Exception {
    // Setup
    UnreliableLocalTransferSettings testConnection = TestConfigUtil.createTestUnreliableLocalConnection(Arrays.asList(new String[] { // << 3 retries!
    "rel=[456].+upload.+multichunk" }));
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    StatusOperationOptions forceChecksumStatusOperationOptions = new StatusOperationOptions();
    forceChecksumStatusOperationOptions.setForceChecksum(true);
    UpOperationOptions noCleanupAndForceUpOperationOptions = new UpOperationOptions();
    noCleanupAndForceUpOperationOptions.setForceUploadEnabled(true);
    noCleanupAndForceUpOperationOptions.setStatusOptions(forceChecksumStatusOperationOptions);
    // Run
    // 1. Call A.up(); this fails AFTER the first multichunk
    clientA.createNewFile("A-file1", 5 * 1024 * 1024);
    boolean operationFailed = false;
    try {
        clientA.up();
    } catch (Exception e) {
        // That is supposed to happen!
        operationFailed = true;
    }
    File repoMultiChunkDir = new File(testConnection.getPath() + "/multichunks");
    File repoActionsDir = new File(testConnection.getPath() + "/actions");
    assertTrue(operationFailed);
    // Atomic operation, so multichunk is not yet present at location
    assertEquals(0, repoMultiChunkDir.listFiles().length);
    assertEquals(1, repoActionsDir.listFiles().length);
    // 2. Call A.cleanup(); this does not run, because there are local changes
    CleanupOperationResult cleanupOperationResultA = clientA.cleanup();
    assertEquals(CleanupResultCode.NOK_LOCAL_CHANGES, cleanupOperationResultA.getResultCode());
    // 3. Call B.cleanup(); this does not run, because of the leftover 'action' file
    CleanupOperationResult cleanupOperationResultB = clientB.cleanup();
    assertEquals(CleanupResultCode.NOK_OTHER_OPERATIONS_RUNNING, cleanupOperationResultB.getResultCode());
    // 4. Call B.down(); this does not deliver any results, because no databases have been uploaded
    DownOperationResult downOperationResult = clientB.down();
    assertEquals(DownResultCode.OK_NO_REMOTE_CHANGES, downOperationResult.getResultCode());
    // 5. Call 'up' again, this uploads previously crashed stuff, and then runs cleanup.
    // The cleanup then removes the old multichunk and the old action files.
    UpOperationResult secondUpResult = clientA.up();
    assertEquals(UpResultCode.OK_CHANGES_UPLOADED, secondUpResult.getResultCode());
    assertEquals(2, repoMultiChunkDir.listFiles().length);
    assertEquals(0, repoActionsDir.listFiles().length);
    // 6. Call 'cleanup' manually (Nothing happens, since transaction was cleaned on second up)
    CleanupOperationResult cleanupOperationResult = clientA.cleanup();
    assertEquals(CleanupOperationResult.CleanupResultCode.OK_NOTHING_DONE, cleanupOperationResult.getResultCode());
    assertEquals(0, cleanupOperationResult.getRemovedMultiChunksCount());
    assertEquals(0, repoActionsDir.listFiles().length);
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : CleanupOperationResult(org.syncany.operations.cleanup.CleanupOperationResult) DownOperationResult(org.syncany.operations.down.DownOperationResult) UnreliableLocalTransferSettings(org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) UpOperationOptions(org.syncany.operations.up.UpOperationOptions) StatusOperationOptions(org.syncany.operations.status.StatusOperationOptions) File(java.io.File) UpOperationResult(org.syncany.operations.up.UpOperationResult) Test(org.junit.Test)

Example 14 with UnreliableLocalTransferSettings

use of org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings 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 15 with UnreliableLocalTransferSettings

use of org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings in project syncany by syncany.

the class UploadInterruptedTest method testUnreliableUpload_FailResume.

@Test
public void testUnreliableUpload_FailResume() throws Exception {
    // Setup
    UnreliableLocalTransferSettings testConnection = TestConfigUtil.createTestUnreliableLocalConnection(Arrays.asList(new String[] { // << 3 retries!!
    "rel=[345] .+upload.+multichunk", // << 3 retries!!
    "rel=(8|9|10) .+upload.+database" }));
    TestClient clientA = new TestClient("A", testConnection);
    clientA.createNewFile("file-1.txt");
    boolean failed = false;
    try {
        clientA.up();
    } catch (StorageException e) {
        failed = true;
    }
    assertTrue(failed);
    UpOperationOptions upOptions = new UpOperationOptions();
    upOptions.setResume(true);
    upOptions.setForceUploadEnabled(true);
    // Try to resume and fail
    failed = false;
    try {
        clientA.up(upOptions);
    } catch (StorageException e) {
        failed = true;
    }
    assertTrue(failed);
    TestClient clientB = new TestClient("B", testConnection);
    clientB.down();
    assertEquals(0, clientB.getLocalFiles().size());
    clientA.up(upOptions);
    clientB.down();
    assertEquals(1, clientB.getLocalFiles().size());
    assertTrue(clientB.getLocalFile("file-1.txt").exists());
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : UnreliableLocalTransferSettings(org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) UpOperationOptions(org.syncany.operations.up.UpOperationOptions) StorageException(org.syncany.plugins.transfer.StorageException) Test(org.junit.Test)

Aggregations

UnreliableLocalTransferSettings (org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings)21 Test (org.junit.Test)18 TestClient (org.syncany.tests.util.TestClient)17 File (java.io.File)16 StorageException (org.syncany.plugins.transfer.StorageException)12 MultichunkRemoteFile (org.syncany.plugins.transfer.files.MultichunkRemoteFile)10 CleanupOperationOptions (org.syncany.operations.cleanup.CleanupOperationOptions)7 CleanupOperationResult (org.syncany.operations.cleanup.CleanupOperationResult)6 UpOperationOptions (org.syncany.operations.up.UpOperationOptions)6 FilenameFilter (java.io.FilenameFilter)5 Persister (org.simpleframework.xml.core.Persister)5 TransferManager (org.syncany.plugins.transfer.TransferManager)5 TransactionAware (org.syncany.plugins.transfer.features.TransactionAware)5 DatabaseRemoteFile (org.syncany.plugins.transfer.files.DatabaseRemoteFile)5 TransactionTO (org.syncany.plugins.transfer.to.TransactionTO)5 ActionRemoteFile (org.syncany.plugins.transfer.files.ActionRemoteFile)4 RemoteFile (org.syncany.plugins.transfer.files.RemoteFile)4 TempRemoteFile (org.syncany.plugins.transfer.files.TempRemoteFile)4 TransactionRemoteFile (org.syncany.plugins.transfer.files.TransactionRemoteFile)4 InitOperationOptions (org.syncany.operations.init.InitOperationOptions)2