Search in sources :

Example 6 with UnreliableLocalTransferSettings

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

use of org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings 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();
}
Also used : CleanupOperationResult(org.syncany.operations.cleanup.CleanupOperationResult) 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) UpOperationResult(org.syncany.operations.up.UpOperationResult) Test(org.junit.Test)

Example 8 with UnreliableLocalTransferSettings

use of org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings 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();
}
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)

Example 9 with UnreliableLocalTransferSettings

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

the class UploadInterruptedTest method testUnreliableUpload_Test4_1_FailsAtSecondMultiChunkUpload.

@Test
public void testUnreliableUpload_Test4_1_FailsAtSecondMultiChunkUpload() throws Exception {
    /*
		 * This test fails when trying to upload the second multichunk, but succeeds on retry
		 *
		 * 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) <<< FAILS HERE
		 * 5. upload(database-123, temp-3) 6. move(temp-1, multichunks/multichunk-1)
		 * 7. move(temp-2, multichunks/multichunk-2)
		 * 8. move(temp-3, databases/database-123)
		 */
    // Setup
    UnreliableLocalTransferSettings testConnection = TestConfigUtil.createTestUnreliableLocalConnection(Arrays.asList(new String[] { "rel=[456].+upload.+multichunk" }));
    TestClient clientA = new TestClient("A", testConnection);
    // << larger than one multichunk!
    clientA.createNewFile("A-original", 5 * 1024 * 1024);
    boolean upFailed = false;
    try {
        clientA.up();
    } catch (StorageException e) {
        upFailed = true;
        logger.log(Level.INFO, e.getMessage());
    }
    assertTrue(upFailed);
    assertEquals(0, new File(testConnection.getPath() + "/databases/").listFiles().length);
    assertEquals(0, 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(1, tempFiles.length);
    // 1 MC with 1 MB, 1 with 4 MB; must be larger than 500 KB
    assertTrue(tempFiles[0].length() > 500 * 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. Second try succeeds and must clean up the transactions
    clientA.up();
    assertEquals(1, new File(testConnection.getPath() + "/databases/").listFiles().length);
    assertEquals(2, new File(testConnection.getPath() + "/multichunks/").listFiles().length);
    assertEquals(0, new File(testConnection.getPath() + "/actions/").listFiles().length);
    assertEquals(0, new File(testConnection.getPath() + "/transactions/").listFiles().length);
    assertEquals(0, new File(testConnection.getPath() + "/temporary/").listFiles().length);
    // Tear down
    clientA.deleteTestData();
}
Also used : 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) TransactionTO(org.syncany.plugins.transfer.to.TransactionTO) Test(org.junit.Test)

Example 10 with UnreliableLocalTransferSettings

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

the class TestConfigUtil method createTestUnreliableLocalConnection.

public static UnreliableLocalTransferSettings createTestUnreliableLocalConnection(List<String> failingOperationPatterns) throws Exception {
    UnreliableLocalTransferPlugin unreliableLocalPlugin = new UnreliableLocalTransferPlugin();
    UnreliableLocalTransferSettings unreliableLocalConnection = createTestUnreliableLocalConnectionWithoutInit(unreliableLocalPlugin, failingOperationPatterns);
    unreliableLocalPlugin.createTransferManager(unreliableLocalConnection, null).init(true);
    return unreliableLocalConnection;
}
Also used : UnreliableLocalTransferSettings(org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings) UnreliableLocalTransferPlugin(org.syncany.plugins.unreliable_local.UnreliableLocalTransferPlugin)

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