Search in sources :

Example 1 with LocalEventBus

use of org.syncany.config.LocalEventBus in project syncany by syncany.

the class NoCliRequestsWhileSyncingTest method testNoCliRequestWhileSyncing.

@Test
public void testNoCliRequestWhileSyncing() throws Exception {
    final TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    final TestClient clientA = new TestClient("ClientA", testConnection);
    int port = 58444;
    // Load config template
    DaemonConfigTO daemonConfig = TestDaemonUtil.loadDaemonConfig("daemonOneFolderNoWebServer.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());
    // Create access token (not needed in this test, but prevents errors in daemon)
    daemonConfig.setPortTO(TestDaemonUtil.createPortTO(port));
    // Register to event bus
    LocalEventBus localEventBus = LocalEventBus.getInstance();
    localEventBus.register(this);
    // Prepare CLI request
    StatusFolderRequest cliStatusRequest = new StatusFolderRequest();
    cliStatusRequest.setId(2586);
    cliStatusRequest.setRoot(clientA.getConfig().getLocalDir().getAbsolutePath());
    // Create watchServer
    WatchServer watchServer = new WatchServer();
    watchServer.start(daemonConfig);
    // Settlement for watch server
    Thread.sleep(1000);
    // Create large file, then wait 3sec for the settlement timer and
    // send the CLI request at the same time
    clientA.createNewFile("largefile", 10 * 1024 * 1024);
    Response response = null;
    for (int i = 1; i < 100; i++) {
        cliStatusRequest.setId(i);
        localEventBus.post(cliStatusRequest);
        // Then, let's hope the response is "no, no, no!"
        response = waitForResponse(i);
        if (response instanceof AlreadySyncingResponse) {
            break;
        }
        Thread.sleep(40);
    }
    assertTrue(response instanceof AlreadySyncingResponse);
    watchServer.stop();
    clientA.deleteTestData();
}
Also used : WatchServer(org.syncany.operations.daemon.WatchServer) AlreadySyncingResponse(org.syncany.operations.daemon.messages.AlreadySyncingResponse) Response(org.syncany.operations.daemon.messages.api.Response) StatusFolderRequest(org.syncany.operations.daemon.messages.StatusFolderRequest) AlreadySyncingResponse(org.syncany.operations.daemon.messages.AlreadySyncingResponse) TestClient(org.syncany.tests.util.TestClient) DaemonConfigTO(org.syncany.config.to.DaemonConfigTO) TransferSettings(org.syncany.plugins.transfer.TransferSettings) LocalEventBus(org.syncany.config.LocalEventBus) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 LocalEventBus (org.syncany.config.LocalEventBus)1 DaemonConfigTO (org.syncany.config.to.DaemonConfigTO)1 WatchServer (org.syncany.operations.daemon.WatchServer)1 AlreadySyncingResponse (org.syncany.operations.daemon.messages.AlreadySyncingResponse)1 StatusFolderRequest (org.syncany.operations.daemon.messages.StatusFolderRequest)1 Response (org.syncany.operations.daemon.messages.api.Response)1 TransferSettings (org.syncany.plugins.transfer.TransferSettings)1 TestClient (org.syncany.tests.util.TestClient)1