@Ignore("hangs when run with other tests") @Test public void testJoinChannel() throws Exception { CountDownLatch connectedLatch = new CountDownLatch(1); String channelToJoin = "#anotherChannel"; doAnswer( invocation -> { connectedLatch.countDown(); return null; }) .when(outputIrc) .joinChannel(DEFAULT_CHANNEL_NAME); when(taskService.submitTask(any())).thenReturn(CompletableFuture.completedFuture(null)); instance.connect(); instance.connectionStateProperty().set(ConnectionState.CONNECTED); assertTrue(connectedLatch.await(TIMEOUT, TIMEOUT_UNIT)); instance.joinChannel(channelToJoin); verify(outputIrc).joinChannel(DEFAULT_CHANNEL_NAME); verify(outputIrc).joinChannel(channelToJoin); }
@Test public void testSendActionInBackground() throws Exception { instance.connect(); String action = "test action"; when(taskService.submitTask(any())).thenReturn(CompletableFuture.completedFuture(action)); mockTaskService(); CompletableFuture<String> future = instance.sendActionInBackground(DEFAULT_CHANNEL_NAME, action); verify(pircBotX).sendIRC(); verify(outputIrc).action(DEFAULT_CHANNEL_NAME, action); assertThat(future.get(TIMEOUT, TIMEOUT_UNIT), is(action)); }
private void downloadReplayToTemporaryDirectory(int replayId, Callback<Path> callback) { String taskTitle = i18n.get("mapReplayTask.title", replayId); taskService.submitTask( TaskGroup.NET_HEAVY, new PrioritizedTask<Path>(taskTitle) { @Override protected Path call() throws Exception { String replayUrl = getReplayUrl(replayId, environment.getProperty("vault.replayDownloadUrl")); logger.info("Downloading replay {} from {}", replayId, replayUrl); HttpURLConnection urlConnection = (HttpURLConnection) new URL(replayUrl).openConnection(); int bytesToRead = urlConnection.getContentLength(); Path tempSupComReplayFile = preferencesService.getCacheDirectory().resolve(TEMP_FAF_REPLAY_FILE_NAME); Files.createDirectories(tempSupComReplayFile.getParent()); try (InputStream inputStream = new BufferedInputStream(urlConnection.getInputStream()); OutputStream outputStream = new BufferedOutputStream(Files.newOutputStream(tempSupComReplayFile))) { ByteCopier.from(inputStream) .to(outputStream) .totalBytes(bytesToRead) .listener(this::updateProgress) .copy(); return tempSupComReplayFile; } } }, callback); }