Search in sources :

Example 11 with StatusOperationOptions

use of org.syncany.operations.status.StatusOperationOptions 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 12 with StatusOperationOptions

use of org.syncany.operations.status.StatusOperationOptions in project syncany by syncany.

the class CleanupOperationTest method testCleanupFailsBecauseOfLocalChanges.

@Test
public void testCleanupFailsBecauseOfLocalChanges() throws Exception {
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    StatusOperationOptions statusOptions = new StatusOperationOptions();
    statusOptions.setForceChecksum(true);
    CleanupOperationOptions cleanupOptions = new CleanupOperationOptions();
    cleanupOptions.setStatusOptions(statusOptions);
    cleanupOptions.setRemoveOldVersions(true);
    // Run
    // A: Create some file versions
    clientA.createNewFile("file.jpg");
    for (int i = 1; i <= 4; i++) {
        clientA.changeFile("file.jpg");
        clientA.upWithForceChecksum();
    }
    // B: Sync down, add something
    clientB.down();
    clientB.changeFile("file.jpg");
    CleanupOperationResult cleanupOperationResult = clientB.cleanup(cleanupOptions);
    assertEquals(CleanupResultCode.NOK_LOCAL_CHANGES, cleanupOperationResult.getResultCode());
    assertEquals(0, cleanupOperationResult.getMergedDatabaseFilesCount());
    assertEquals(0, cleanupOperationResult.getRemovedMultiChunksCount());
    assertEquals(0, cleanupOperationResult.getRemovedOldVersionsCount());
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : CleanupOperationResult(org.syncany.operations.cleanup.CleanupOperationResult) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) 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) Test(org.junit.Test)

Example 13 with StatusOperationOptions

use of org.syncany.operations.status.StatusOperationOptions in project syncany by syncany.

the class LogOperationTest method testLogOperation.

@Test
public void testLogOperation() throws Exception {
    // Setup
    Config config = TestConfigUtil.createTestLocalConfig();
    StatusOperationOptions statusOptions = new StatusOperationOptions();
    statusOptions.setForceChecksum(true);
    UpOperationOptions upOptions = new UpOperationOptions();
    upOptions.setStatusOptions(statusOptions);
    upOptions.setForceUploadEnabled(true);
    // First, do some uploading
    List<File> originalFiles = TestFileUtil.createRandomFilesInDirectory(config.getLocalDir(), 5 * 1024, 5);
    new UpOperation(config, upOptions).execute();
    // And some more
    for (File file : originalFiles) {
        TestFileUtil.changeRandomPartOfBinaryFile(file);
    }
    new UpOperation(config, upOptions).execute();
    // And some more
    for (File file : originalFiles) {
        file.delete();
    }
    new UpOperation(config, upOptions).execute();
    // Then, check the log
    LogOperationOptions logOptions = new LogOperationOptions();
    logOptions.setStartDatabaseVersionIndex(0);
    logOptions.setMaxDatabaseVersionCount(99);
    logOptions.setMaxFileHistoryCount(99);
    List<LightweightDatabaseVersion> databaseVersions = (new LogOperation(config, logOptions).execute()).getDatabaseVersions();
    assertEquals(3, databaseVersions.size());
    assertEquals(5, databaseVersions.get(2).getChangeSet().getNewFiles().size());
    assertEquals(0, databaseVersions.get(2).getChangeSet().getChangedFiles().size());
    assertEquals(0, databaseVersions.get(2).getChangeSet().getDeletedFiles().size());
    assertEquals(0, databaseVersions.get(1).getChangeSet().getNewFiles().size());
    assertEquals(5, databaseVersions.get(1).getChangeSet().getChangedFiles().size());
    assertEquals(0, databaseVersions.get(1).getChangeSet().getDeletedFiles().size());
    assertEquals(0, databaseVersions.get(0).getChangeSet().getNewFiles().size());
    assertEquals(0, databaseVersions.get(0).getChangeSet().getChangedFiles().size());
    assertEquals(5, databaseVersions.get(0).getChangeSet().getDeletedFiles().size());
    // Cleanup
    TestConfigUtil.deleteTestLocalConfigAndData(config);
}
Also used : UpOperation(org.syncany.operations.up.UpOperation) LogOperation(org.syncany.operations.log.LogOperation) Config(org.syncany.config.Config) LightweightDatabaseVersion(org.syncany.operations.log.LightweightDatabaseVersion) UpOperationOptions(org.syncany.operations.up.UpOperationOptions) StatusOperationOptions(org.syncany.operations.status.StatusOperationOptions) File(java.io.File) LogOperationOptions(org.syncany.operations.log.LogOperationOptions) Test(org.junit.Test)

Example 14 with StatusOperationOptions

use of org.syncany.operations.status.StatusOperationOptions in project syncany by syncany.

the class BasicWatchServerTest method testWatchServer.

/**
 * The WatchServerTest tests all things WatchServer.
 * This is one single test to prevent issues with parallelism. (Occupied ports, EventBus mixups etc.)
 */
@Test
public void testWatchServer() throws Exception {
    final TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    final TestClient clientA = new TestClient("ClientA", testConnection);
    final TestClient clientB = new TestClient("ClientB", testConnection);
    int port = 58443;
    // Load config template
    DaemonConfigTO daemonConfig = TestDaemonUtil.loadDaemonConfig("daemonTwoFoldersNoWebServer.xml");
    // Set port to prevent conflicts with default daemons
    daemonConfig.getWebServer().setBindPort(port);
    // Dynamically insert paths
    daemonConfig.getFolders().get(0).setPath(clientA.getConfig().getLocalDir().getAbsolutePath());
    daemonConfig.getFolders().get(1).setPath(clientB.getConfig().getLocalDir().getAbsolutePath());
    // Create access token (not needed in this test, but prevents errors in daemon)
    daemonConfig.setPortTO(TestDaemonUtil.createPortTO(port));
    // Create watchServer
    WatchServer watchServer = new WatchServer();
    clientA.createNewFile("file-1");
    watchServer.start(daemonConfig);
    for (int i = 0; i < 20; i++) {
        if (clientB.getLocalFile("file-1").exists()) {
            break;
        }
        Thread.sleep(1000);
    }
    assertTrue("File has not synced to clientB", clientB.getLocalFile("file-1").exists());
    assertEquals(clientA.getLocalFile("file-1").length(), clientB.getLocalFile("file-1").length());
    registerWithBus();
    // Create watchServer
    clientA.createNewFolder("folder");
    clientA.createNewFile("folder/file-2");
    // Allow server to settle
    Thread.sleep(100);
    // Repeat request until 3 files are found.
    FileVersion[] files = null;
    for (int i = 0; i < 20; i++) {
        LsFolderRequest request = new LsFolderRequest();
        LsOperationOptions lsOperationOption = new LsOperationOptions();
        request.setId(i);
        request.setRoot(clientA.getConfig().getLocalDir().getAbsolutePath());
        request.setOptions(lsOperationOption);
        eventBus.post(request);
        Response response = waitForResponse(i);
        if (response instanceof AlreadySyncingResponse) {
            Thread.sleep(1000);
            continue;
        }
        assertTrue(response instanceof LsFolderResponse);
        LsFolderResponse treeResponse = (LsFolderResponse) response;
        files = treeResponse.getResult().getFileList().toArray(new FileVersion[] {});
        if (files.length == 2) {
            break;
        }
        if (i == 19) {
            assertEquals(2, files.length);
        } else {
            Thread.sleep(1000);
        }
    }
    if (files[0].getName().equals("folder")) {
        files = new FileVersion[] { files[1], files[0] };
    }
    assertEquals(clientA.getLocalFile("file-1").getName(), files[0].getName());
    assertEquals(clientA.getLocalFile("file-1").length(), (long) files[0].getSize());
    assertEquals(clientA.getLocalFile("folder").getName(), files[1].getName());
    assertTrue(clientA.getLocalFile("folder").isDirectory());
    assertEquals(files[1].getType(), FileVersion.FileType.FOLDER);
    // Create GetFileHistoryRequest for the first returned file
    GetFileHistoryFolderRequest request = new GetFileHistoryFolderRequest();
    request.setId(21);
    request.setRoot(clientA.getConfig().getLocalDir().getAbsolutePath());
    request.setFileHistoryId(files[0].getFileHistoryId().toString());
    eventBus.post(request);
    Response response = waitForResponse(21);
    assertTrue(response instanceof GetFileHistoryFolderResponse);
    GetFileHistoryFolderResponse fileHistoryResponse = (GetFileHistoryFolderResponse) response;
    assertEquals(1, fileHistoryResponse.getFiles().size());
    assertEquals(files[0], fileHistoryResponse.getFiles().get(0));
    // Create GetFileRequest for the first returned file
    GetFileFolderRequest getFileRequest = new GetFileFolderRequest();
    getFileRequest.setId(22);
    getFileRequest.setRoot(clientA.getConfig().getLocalDir().getAbsolutePath());
    getFileRequest.setFileHistoryId(files[0].getFileHistoryId().toString());
    getFileRequest.setVersion(1);
    eventBus.post(getFileRequest);
    int i = 0;
    while (internalResponse == null && i < 40) {
        Thread.sleep(100);
        i++;
    }
    assertEquals((long) files[0].getSize(), internalResponse.getTempFile().length());
    // Cli Requests
    clientA.copyFile("file-1", "file-1.bak");
    // CLI request while running.
    StatusFolderRequest statusRequest = new StatusFolderRequest();
    StatusOperationOptions statusOperationOption = new StatusOperationOptions();
    statusOperationOption.setForceChecksum(true);
    statusRequest.setId(30);
    statusRequest.setRoot(clientA.getConfig().getLocalDir().getAbsolutePath());
    statusRequest.setOptions(statusOperationOption);
    // Create big file to trigger sync
    clientA.createNewFile("bigfileforlongsync", 10 * 1024 * 1024);
    // ^^ Now sync should start and we send 'status' requests
    boolean syncRunningMessageReceived = false;
    for (i = 30; i < 59; i++) {
        statusRequest.setId(i);
        eventBus.post(statusRequest);
        response = waitForResponse(i);
        if (response instanceof AlreadySyncingResponse) {
            syncRunningMessageReceived = true;
            break;
        }
        Thread.sleep(200);
    }
    assertTrue(syncRunningMessageReceived);
    // Allow daemon to sync
    Thread.sleep(10000);
    for (i = 59; i < 69; i++) {
        statusRequest.setId(i);
        eventBus.post(statusRequest);
        response = waitForResponse(i);
        if (response instanceof StatusFolderResponse) {
            break;
        }
        Thread.sleep(1000);
    }
    assertNotNull(response);
    // assertEquals("No local changes.\n", cliResponse.getOutput());
    // Restore file test
    RestoreFolderRequest restoreRequest = new RestoreFolderRequest();
    RestoreOperationOptions restoreOperationOption = new RestoreOperationOptions();
    restoreOperationOption.setFileHistoryId(files[0].getFileHistoryId());
    restoreOperationOption.setFileVersion(1);
    restoreRequest.setId(70);
    restoreRequest.setRoot(clientA.getConfig().getLocalDir().getAbsolutePath());
    restoreRequest.setOptions(restoreOperationOption);
    eventBus.post(restoreRequest);
    response = waitForResponse(70);
    assertTrue(response instanceof RestoreFolderResponse);
    RestoreFolderResponse restoreResponse = (RestoreFolderResponse) response;
    byte[] copyChecksum = FileUtil.createChecksum(clientA.getLocalFile("file-1.bak"), "SHA1");
    byte[] restoreChecksum = FileUtil.createChecksum(restoreResponse.getResult().getTargetFile(), "SHA1");
    assertArrayEquals(copyChecksum, restoreChecksum);
    watchServer.stop();
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : WatchServer(org.syncany.operations.daemon.WatchServer) RestoreOperationOptions(org.syncany.operations.restore.RestoreOperationOptions) LsFolderRequest(org.syncany.operations.daemon.messages.LsFolderRequest) GetFileHistoryFolderResponse(org.syncany.operations.daemon.messages.GetFileHistoryFolderResponse) StatusFolderRequest(org.syncany.operations.daemon.messages.StatusFolderRequest) LsFolderResponse(org.syncany.operations.daemon.messages.LsFolderResponse) StatusFolderResponse(org.syncany.operations.daemon.messages.StatusFolderResponse) DaemonConfigTO(org.syncany.config.to.DaemonConfigTO) TransferSettings(org.syncany.plugins.transfer.TransferSettings) LsOperationOptions(org.syncany.operations.ls.LsOperationOptions) RestoreFolderRequest(org.syncany.operations.daemon.messages.RestoreFolderRequest) StatusOperationOptions(org.syncany.operations.status.StatusOperationOptions) GetFileFolderRequest(org.syncany.operations.daemon.messages.GetFileFolderRequest) RestoreFolderResponse(org.syncany.operations.daemon.messages.RestoreFolderResponse) LsFolderResponse(org.syncany.operations.daemon.messages.LsFolderResponse) GetFileHistoryFolderResponse(org.syncany.operations.daemon.messages.GetFileHistoryFolderResponse) AlreadySyncingResponse(org.syncany.operations.daemon.messages.AlreadySyncingResponse) StatusFolderResponse(org.syncany.operations.daemon.messages.StatusFolderResponse) Response(org.syncany.operations.daemon.messages.api.Response) AlreadySyncingResponse(org.syncany.operations.daemon.messages.AlreadySyncingResponse) TestClient(org.syncany.tests.util.TestClient) FileVersion(org.syncany.database.FileVersion) GetFileHistoryFolderRequest(org.syncany.operations.daemon.messages.GetFileHistoryFolderRequest) RestoreFolderResponse(org.syncany.operations.daemon.messages.RestoreFolderResponse) Test(org.junit.Test)

Example 15 with StatusOperationOptions

use of org.syncany.operations.status.StatusOperationOptions in project syncany by syncany.

the class TestClient method upWithForceChecksum.

public UpOperationResult upWithForceChecksum() throws Exception {
    StatusOperationOptions statusOptions = new StatusOperationOptions();
    statusOptions.setForceChecksum(true);
    UpOperationOptions upOptions = new UpOperationOptions();
    upOptions.setStatusOptions(statusOptions);
    return up(upOptions);
}
Also used : UpOperationOptions(org.syncany.operations.up.UpOperationOptions) StatusOperationOptions(org.syncany.operations.status.StatusOperationOptions)

Aggregations

StatusOperationOptions (org.syncany.operations.status.StatusOperationOptions)15 Test (org.junit.Test)12 UpOperationOptions (org.syncany.operations.up.UpOperationOptions)10 TestClient (org.syncany.tests.util.TestClient)10 CleanupOperationOptions (org.syncany.operations.cleanup.CleanupOperationOptions)8 File (java.io.File)6 LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)6 UnreliableLocalTransferSettings (org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings)4 CleanupOperationResult (org.syncany.operations.cleanup.CleanupOperationResult)3 Config (org.syncany.config.Config)2 ChangeSet (org.syncany.operations.ChangeSet)2 StatusOperation (org.syncany.operations.status.StatusOperation)2 StatusOperationResult (org.syncany.operations.status.StatusOperationResult)2 UpOperation (org.syncany.operations.up.UpOperation)2 TransferSettings (org.syncany.plugins.transfer.TransferSettings)2 FilenameFilter (java.io.FilenameFilter)1 OptionParser (joptsimple.OptionParser)1 OptionSet (joptsimple.OptionSet)1 DaemonConfigTO (org.syncany.config.to.DaemonConfigTO)1 FileVersion (org.syncany.database.FileVersion)1