Search in sources :

Example 1 with Response

use of org.syncany.operations.daemon.messages.api.Response in project syncany by syncany.

the class XmlMessageFactoryTest method testXmlToResponseSuccess.

@Test
public void testXmlToResponseSuccess() throws Exception {
    Response response = XmlMessageFactory.toResponse("<getFileFolderResponse><code>200</code><requestId>1234</requestId><root>/some/path</root><tempFileToken>beefbeefbeef</tempFileToken></getFileFolderResponse>");
    assertEquals(GetFileFolderResponse.class, response.getClass());
    assertEquals(200, ((GetFileFolderResponse) response).getCode());
    assertEquals((Integer) 1234, ((GetFileFolderResponse) response).getRequestId());
    assertEquals("beefbeefbeef", ((GetFileFolderResponse) response).getTempToken());
}
Also used : GetFileFolderResponse(org.syncany.operations.daemon.messages.GetFileFolderResponse) Response(org.syncany.operations.daemon.messages.api.Response) Test(org.junit.Test)

Example 2 with Response

use of org.syncany.operations.daemon.messages.api.Response in project syncany by syncany.

the class WatchRunner method onRequestReceived.

@Subscribe
public void onRequestReceived(FolderRequest folderRequest) {
    File requestRootFolder = new File(folderRequest.getRoot());
    boolean localDirMatches = requestRootFolder.equals(config.getLocalDir());
    if (localDirMatches) {
        logger.log(Level.INFO, "Received " + folderRequest);
        try {
            if (!watchOperation.isSyncRunning() && !watchOperation.isSyncRequested()) {
                watchOperation.pause();
                FolderRequestHandler handler = FolderRequestHandler.createFolderRequestHandler(folderRequest, config);
                Response response = handler.handleRequest(folderRequest);
                if (response != null) {
                    eventBus.post(response);
                }
                watchOperation.resume();
            } else {
                logger.log(Level.WARNING, "FolderRequest discarded : ", folderRequest);
                eventBus.post(new AlreadySyncingResponse(folderRequest.getId(), "FolderRequest discarded."));
            }
        } catch (Exception e) {
            logger.log(Level.FINE, "Failed to process request", e);
            eventBus.post(new BadRequestResponse(folderRequest.getId(), "Invalid request."));
        }
    }
}
Also used : AlreadySyncingResponse(org.syncany.operations.daemon.messages.AlreadySyncingResponse) BadRequestResponse(org.syncany.operations.daemon.messages.BadRequestResponse) Response(org.syncany.operations.daemon.messages.api.Response) FolderRequestHandler(org.syncany.operations.daemon.messages.api.FolderRequestHandler) BadRequestResponse(org.syncany.operations.daemon.messages.BadRequestResponse) AlreadySyncingResponse(org.syncany.operations.daemon.messages.AlreadySyncingResponse) File(java.io.File) ConfigException(org.syncany.config.ConfigException) Subscribe(com.google.common.eventbus.Subscribe)

Example 3 with Response

use of org.syncany.operations.daemon.messages.api.Response in project syncany by syncany.

the class JsonMessageFactoryTest method testJsonToResponseSuccess.

@Test
public void testJsonToResponseSuccess() throws Exception {
    Response response = JsonMessageFactory.toResponse("{\"GetFileFolderResponse\":{\"code\":\"200\",\"requestId\":\"1234\",\"root\":\"/some/path\",\"tempFileToken\":\"beefbeefbeef\"}}");
    assertEquals(GetFileFolderResponse.class, response.getClass());
    assertEquals(200, ((GetFileFolderResponse) response).getCode());
    assertEquals((Integer) 1234, ((GetFileFolderResponse) response).getRequestId());
    assertEquals("beefbeefbeef", ((GetFileFolderResponse) response).getTempToken());
}
Also used : GetFileFolderResponse(org.syncany.operations.daemon.messages.GetFileFolderResponse) Response(org.syncany.operations.daemon.messages.api.Response) Test(org.junit.Test)

Example 4 with Response

use of org.syncany.operations.daemon.messages.api.Response in project syncany by syncany.

the class XmlMessageFactoryTest method testXmlToResponseSuccess.

@Test
public void testXmlToResponseSuccess() throws Exception {
    Response response = XmlMessageFactory.toResponse("<getFileFolderResponse><code>200</code><requestId>1234</requestId><root>/some/path</root><tempFileToken>beefbeefbeef</tempFileToken></getFileFolderResponse>");
    assertEquals(GetFileFolderResponse.class, response.getClass());
    assertEquals(200, ((GetFileFolderResponse) response).getCode());
    assertEquals((Integer) 1234, ((GetFileFolderResponse) response).getRequestId());
    assertEquals("beefbeefbeef", ((GetFileFolderResponse) response).getTempToken());
}
Also used : GetFileFolderResponse(org.syncany.operations.daemon.messages.GetFileFolderResponse) Response(org.syncany.operations.daemon.messages.api.Response) Test(org.junit.Test)

Example 5 with Response

use of org.syncany.operations.daemon.messages.api.Response 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

Response (org.syncany.operations.daemon.messages.api.Response)9 Test (org.junit.Test)6 AlreadySyncingResponse (org.syncany.operations.daemon.messages.AlreadySyncingResponse)4 GetFileFolderResponse (org.syncany.operations.daemon.messages.GetFileFolderResponse)4 BadRequestResponse (org.syncany.operations.daemon.messages.BadRequestResponse)3 Subscribe (com.google.common.eventbus.Subscribe)2 ConfigException (org.syncany.config.ConfigException)2 DaemonConfigTO (org.syncany.config.to.DaemonConfigTO)2 WatchServer (org.syncany.operations.daemon.WatchServer)2 StatusFolderRequest (org.syncany.operations.daemon.messages.StatusFolderRequest)2 TransferSettings (org.syncany.plugins.transfer.TransferSettings)2 TestClient (org.syncany.tests.util.TestClient)2 File (java.io.File)1 HttpResponse (org.apache.http.HttpResponse)1 LocalEventBus (org.syncany.config.LocalEventBus)1 FileVersion (org.syncany.database.FileVersion)1 AddWatchManagementResponse (org.syncany.operations.daemon.messages.AddWatchManagementResponse)1 GetFileFolderRequest (org.syncany.operations.daemon.messages.GetFileFolderRequest)1 GetFileHistoryFolderRequest (org.syncany.operations.daemon.messages.GetFileHistoryFolderRequest)1 GetFileHistoryFolderResponse (org.syncany.operations.daemon.messages.GetFileHistoryFolderResponse)1