@Test public void getLogAndStdoutFiles() throws Exception { WebMonitorUtils.LogFileLocation logFiles = WebMonitorUtils.LogFileLocation.find(CLUSTER_CONFIGURATION); FileUtils.writeStringToFile(logFiles.logFile, "job manager log"); String logs = TestBaseUtils.getFromHTTP("http://localhost:" + getRestPort() + "/jobmanager/log"); assertTrue(logs.contains("job manager log")); FileUtils.writeStringToFile(logFiles.stdOutFile, "job manager out"); logs = TestBaseUtils.getFromHTTP("http://localhost:" + getRestPort() + "/jobmanager/stdout"); assertTrue(logs.contains("job manager out")); }
@Test public void getFrontPage() { try { String fromHTTP = TestBaseUtils.getFromHTTP("http://localhost:" + getRestPort() + "/index.html"); String text = "Apache Flink Dashboard"; assertTrue("Startpage should contain " + text, fromHTTP.contains(text)); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
@Test public void testResponseHeaders() throws Exception { // check headers for successful json response URL taskManagersUrl = new URL("http://localhost:" + getRestPort() + "/taskmanagers"); HttpURLConnection taskManagerConnection = (HttpURLConnection) taskManagersUrl.openConnection(); taskManagerConnection.setConnectTimeout(100000); taskManagerConnection.connect(); if (taskManagerConnection.getResponseCode() >= 400) { // error! InputStream is = taskManagerConnection.getErrorStream(); String errorMessage = IOUtils.toString(is, ConfigConstants.DEFAULT_CHARSET); throw new RuntimeException(errorMessage); } // we don't set the content-encoding header Assert.assertNull(taskManagerConnection.getContentEncoding()); Assert.assertEquals("application/json; charset=UTF-8", taskManagerConnection.getContentType()); // check headers in case of an error URL notFoundJobUrl = new URL("http://localhost:" + getRestPort() + "/jobs/dontexist"); HttpURLConnection notFoundJobConnection = (HttpURLConnection) notFoundJobUrl.openConnection(); notFoundJobConnection.setConnectTimeout(100000); notFoundJobConnection.connect(); if (notFoundJobConnection.getResponseCode() >= 400) { // we don't set the content-encoding header Assert.assertNull(notFoundJobConnection.getContentEncoding()); Assert.assertEquals("application/json; charset=UTF-8", notFoundJobConnection.getContentType()); } else { throw new RuntimeException("Request for non-existing job did not return an error."); } }
@Test public void getConfiguration() { try { String config = TestBaseUtils.getFromHTTP("http://localhost:" + getRestPort() + "/jobmanager/config"); Map<String, String> conf = WebMonitorUtils.fromKeyValueJsonArray(config); assertEquals( CLUSTER_CONFIGURATION.getString(ConfigConstants.LOCAL_START_WEBSERVER, null), conf.get(ConfigConstants.LOCAL_START_WEBSERVER)); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
@Test public void getTaskManagerLogAndStdoutFiles() { try { String json = TestBaseUtils.getFromHTTP("http://localhost:" + getRestPort() + "/taskmanagers/"); ObjectMapper mapper = new ObjectMapper(); JsonNode parsed = mapper.readTree(json); ArrayNode taskManagers = (ArrayNode) parsed.get("taskmanagers"); JsonNode taskManager = taskManagers.get(0); String id = taskManager.get("id").asText(); WebMonitorUtils.LogFileLocation logFiles = WebMonitorUtils.LogFileLocation.find(CLUSTER_CONFIGURATION); //we check for job manager log files, since no separate taskmanager logs exist FileUtils.writeStringToFile(logFiles.logFile, "job manager log"); String logs = TestBaseUtils.getFromHTTP("http://localhost:" + getRestPort() + "/taskmanagers/" + id + "/log"); assertTrue(logs.contains("job manager log")); FileUtils.writeStringToFile(logFiles.stdOutFile, "job manager out"); logs = TestBaseUtils.getFromHTTP("http://localhost:" + getRestPort() + "/taskmanagers/" + id + "/stdout"); assertTrue(logs.contains("job manager out")); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
@Test public void getNumberOfTaskManagers() { try { String json = TestBaseUtils.getFromHTTP("http://localhost:" + getRestPort() + "/taskmanagers/"); ObjectMapper mapper = new ObjectMapper(); JsonNode response = mapper.readTree(json); ArrayNode taskManagers = (ArrayNode) response.get("taskmanagers"); assertNotNull(taskManagers); assertEquals(NUM_TASK_MANAGERS, taskManagers.size()); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
final Deadline deadline = testTimeout.fromNow(); try (HttpTestClient client = new HttpTestClient("localhost", getRestPort())) {
final Deadline deadline = testTimeout.fromNow(); try (HttpTestClient client = new HttpTestClient("localhost", getRestPort())) { try (HttpTestClient client = new HttpTestClient("localhost", getRestPort())) { FiniteDuration timeout = new FiniteDuration(30, TimeUnit.SECONDS); client.sendGetRequest("/jobs/" + jid + "/config", timeout);
@Test public void getTaskmanagers() throws Exception { String json = TestBaseUtils.getFromHTTP("http://localhost:" + getRestPort() + "/taskmanagers/"); ObjectMapper mapper = new ObjectMapper(); JsonNode parsed = mapper.readTree(json); ArrayNode taskManagers = (ArrayNode) parsed.get("taskmanagers"); assertNotNull(taskManagers); assertEquals(NUM_TASK_MANAGERS, taskManagers.size()); JsonNode taskManager = taskManagers.get(0); assertNotNull(taskManager); assertEquals(NUM_SLOTS, taskManager.get("slotsNumber").asInt()); assertTrue(taskManager.get("freeSlots").asInt() <= NUM_SLOTS); }