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