Search in sources :

Example 1 with UnreliableLocalTransferSettings

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

the class Issue316ScenarioTest method testIssue316CleanupThenDeleteFileButLocalFileChanged.

@Test
public void testIssue316CleanupThenDeleteFileButLocalFileChanged() throws Exception {
    /*
		 * Same test as above, but local file has changed at client B.
		 */
    // Setup
    UnreliableLocalTransferSettings testConnection = TestConfigUtil.createTestUnreliableLocalConnection(Arrays.asList(new String[] { // << 3 retries!
    "rel=(5|6|7) .+download.+multichunk" }));
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    CleanupOperationOptions cleanupOptionsKeepOne = new CleanupOperationOptions();
    cleanupOptionsKeepOne.setMaxDatabaseFiles(1);
    cleanupOptionsKeepOne.setForce(true);
    clientA.createNewFile("Kazam_screencast_00010.mp4");
    clientA.upWithForceChecksum();
    clientB.down();
    assertTrue(clientB.getLocalFile("Kazam_screencast_00010.mp4").exists());
    // <<<<<<<<< Different from above test
    clientB.changeFile("Kazam_screencast_00010.mp4");
    clientA.createNewFile("SomeFileTOIncreaseTheDatabaseFileCount");
    clientA.upWithForceChecksum();
    CleanupOperationResult cleanupResult = clientA.cleanup(cleanupOptionsKeepOne);
    assertEquals(CleanupResultCode.OK, cleanupResult.getResultCode());
    clientA.deleteFile("Kazam_screencast_00010.mp4");
    clientA.upWithForceChecksum();
    // First 'down' of client B after the cleanup. 
    // This fails AFTER the local database was wiped.
    boolean downFailedAtB = false;
    try {
        clientB.down();
    } catch (Exception e) {
        downFailedAtB = true;
    }
    assertTrue("Down operation should have failed.", downFailedAtB);
    // Second 'down' of client B; This should delete the file 'Kazam_screencast_00010.mp4',
    // because it matches the checksum of the 'DELETED' entry
    clientB.down();
    // <<<<<<<<< Different from above test 
    assertConflictingFileExists("Kazam_screencast_00010.mp4", clientB.getLocalFiles());
    assertFalse(clientB.getLocalFile("Kazam_screencast_00010.mp4").exists());
    // Tear down
    clientB.deleteTestData();
    clientA.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) Test(org.junit.Test)

Example 2 with UnreliableLocalTransferSettings

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

the class FailedSplitSyncUpScenarioTest method testUpFailsOnFirstTransaction.

@Test
public void testUpFailsOnFirstTransaction() throws Exception {
    // Inject failure for the second multichunk
    UnreliableLocalTransferSettings testConnection = TestConfigUtil.createTestUnreliableLocalConnection(Arrays.asList("rel=[4567].+upload.+multichunk"));
    TestClient clientA = new TestClient("A", testConnection);
    UpOperationOptions options = new UpOperationOptions();
    options.setTransactionSizeLimit(0L);
    // Write three files (three transactions), with the first file spanning two multichunks
    clientA.createNewFile("file1", 5 * 1024 * 1024);
    clientA.createNewFile("file2", 1024);
    clientA.createNewFile("file3", 1024);
    // 1. Attempt upload, should fail
    boolean operationFailed = false;
    try {
        clientA.up(options);
    } catch (Exception ex) {
        operationFailed = true;
    }
    assertTrue(operationFailed);
    // 2. Verify local state
    File stateDir = clientA.getConfig().getStateDir();
    File cacheDir = clientA.getConfig().getCacheDir();
    // Expecting: 3 transactions + 3 databases + transaction list + in-progress transaction
    assertEquals(8, stateDir.listFiles().length);
    // Expecting: 3 databases + 4 multichunks + in-progress transaction
    assertEquals(8, cacheDir.listFiles().length);
    // 3. Verify remote state
    File repoActionsDir = new File(testConnection.getPath() + "/actions");
    File repoDatabasesDir = new File(testConnection.getPath() + "/databases");
    File repoMultichunksDir = new File(testConnection.getPath() + "/multichunks");
    File repoTemporaryDir = new File(testConnection.getPath() + "/temporary");
    File repoTransactionsDir = new File(testConnection.getPath() + "/transactions");
    // Expecting that no databases/multichunks have been committed, 1 multichunk is temporary, 1 action and transaction are pending
    assertEquals("One pending action should exist in repo", 1, repoActionsDir.listFiles().length);
    assertEquals("No database should be committed in repo", 0, repoDatabasesDir.listFiles().length);
    assertEquals("No multichunk should be committed in repo", 0, repoMultichunksDir.listFiles().length);
    assertEquals("One multichunk should exist in repo as temporary", 1, repoTemporaryDir.listFiles().length);
    assertEquals("One pending transaction should exist in repo", 1, repoTransactionsDir.listFiles().length);
    // 4. Resume operation
    clientA.up();
    // 5. Final state should be as if no failure occurred; three database versions, three complete files
    assertEquals("Three databases should be committed in repo", 3, repoDatabasesDir.listFiles().length);
    for (int fileNumber = 1; fileNumber <= 3; fileNumber++) {
        DatabaseRemoteFile databaseRemoteFile = new DatabaseRemoteFile("A", fileNumber);
        File databaseFile = new File(testConnection.getPath() + "/databases/" + databaseRemoteFile.getName());
        assertTrue("Database file should exist: " + databaseFile, databaseFile.exists());
    }
    assertEquals("Four multichunks should be committed in repo", 4, repoMultichunksDir.listFiles().length);
    // Tear down
    clientA.deleteTestData();
}
Also used : UnreliableLocalTransferSettings(org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) UpOperationOptions(org.syncany.operations.up.UpOperationOptions) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) File(java.io.File) Test(org.junit.Test)

Example 3 with UnreliableLocalTransferSettings

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

the class CleanupOperationTest method testCleanupFailsMidCommit.

@Test
public void testCleanupFailsMidCommit() throws Exception {
    // Setup
    UnreliableLocalTransferSettings testConnection = TestConfigUtil.createTestUnreliableLocalConnection(Arrays.asList(new String[] { // << 3 retries!
    "rel=(13|14|15).+move" }));
    TestClient clientA = new TestClient("A", testConnection);
    java.sql.Connection databaseConnectionA = clientA.getConfig().createDatabaseConnection();
    StatusOperationOptions forceChecksumStatusOperationOptions = new StatusOperationOptions();
    forceChecksumStatusOperationOptions.setForceChecksum(true);
    CleanupOperationOptions options = new CleanupOperationOptions();
    options.setStatusOptions(forceChecksumStatusOperationOptions);
    options.setRemoveOldVersions(true);
    options.setMinKeepSeconds(0);
    options.setMinSecondsBetweenCleanups(40000000);
    options.setForce(true);
    File repoDir = testConnection.getPath();
    File repoMultiChunkDir = new File(testConnection.getPath() + "/multichunks");
    File repoActionsDir = new File(testConnection.getPath() + "/actions");
    File repoDatabasesDir = new File(testConnection.getPath() + "/databases");
    File repoTransactionsDir = new File(testConnection.getPath() + "/transactions");
    File repoTemporaryDir = new File(testConnection.getPath() + "/temporary");
    // Run
    clientA.createNewFile("A-file1", 5 * 1024);
    clientA.up();
    for (int i = 0; i < 5; i++) {
        clientA.changeFile("A-file1");
        clientA.upWithForceChecksum();
    }
    assertEquals(6, repoDatabasesDir.listFiles().length);
    assertEquals(6, repoMultiChunkDir.listFiles().length);
    assertEquals(0, repoActionsDir.listFiles().length);
    assertEquals("6", TestSqlUtil.runSqlSelect("select count(*) from multichunk", databaseConnectionA));
    // Run cleanup, fails mid-move!
    boolean operationFailed = false;
    try {
        clientA.cleanup(options);
    } catch (Exception e) {
        // That is supposed to happen!
        operationFailed = true;
        e.printStackTrace();
    }
    assertTrue(operationFailed);
    assertEquals(1, repoTransactionsDir.listFiles().length);
    assertEquals(0, repoTemporaryDir.listFiles().length);
    assertEquals(6, repoDatabasesDir.listFiles().length);
    assertEquals(6, repoMultiChunkDir.listFiles().length);
    assertEquals("6", TestSqlUtil.runSqlSelect("select count(*) from multichunk", databaseConnectionA));
    // Retry
    clientA.cleanup(options);
    assertEquals(1, repoDatabasesDir.listFiles(new FilenameFilter() {

        public boolean accept(File dir, String name) {
            return name.startsWith("database-");
        }
    }).length);
    assertEquals(1, repoMultiChunkDir.listFiles().length);
    assertEquals(0, repoActionsDir.listFiles().length);
    assertEquals(0, repoDir.list(new FilenameFilter() {

        public boolean accept(File dir, String name) {
            return name.startsWith("transaction-");
        }
    }).length);
    assertEquals(0, repoDir.list(new FilenameFilter() {

        public boolean accept(File dir, String name) {
            return name.startsWith("temp-");
        }
    }).length);
    assertEquals("1", TestSqlUtil.runSqlSelect("select count(*) from multichunk", databaseConnectionA));
    // Tear down
    clientA.deleteTestData();
}
Also used : FilenameFilter(java.io.FilenameFilter) UnreliableLocalTransferSettings(org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) CleanupOperationOptions(org.syncany.operations.cleanup.CleanupOperationOptions) StatusOperationOptions(org.syncany.operations.status.StatusOperationOptions) File(java.io.File) Test(org.junit.Test)

Example 4 with UnreliableLocalTransferSettings

use of org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings 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();
}
Also used : TransferManager(org.syncany.plugins.transfer.TransferManager) CleanupOperationResult(org.syncany.operations.cleanup.CleanupOperationResult) CleanupOperationOptions(org.syncany.operations.cleanup.CleanupOperationOptions) FilenameFilter(java.io.FilenameFilter) TransactionAware(org.syncany.plugins.transfer.features.TransactionAware) UnreliableLocalTransferSettings(org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) TimeUnit(org.syncany.operations.cleanup.CleanupOperationOptions.TimeUnit) 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) 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) MultichunkRemoteFile(org.syncany.plugins.transfer.files.MultichunkRemoteFile) Test(org.junit.Test)

Example 5 with UnreliableLocalTransferSettings

use of org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings 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();
}
Also used : TransferManager(org.syncany.plugins.transfer.TransferManager) FilenameFilter(java.io.FilenameFilter) CleanupOperationResult(org.syncany.operations.cleanup.CleanupOperationResult) 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) 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)

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