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());
}
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."));
}
}
}
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());
}
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());
}
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();
}
Aggregations