use of com.fasterxml.jackson.databind.ObjectMapper in project flink by apache.
the class CheckpointStatsHandlerTest method testCheckpointStatsRequest.
/**
* Tests a complete checkpoint stats snapshot.
*/
@Test
public void testCheckpointStatsRequest() throws Exception {
TestCheckpointStats testCheckpointStats = createTestCheckpointStats();
CheckpointStatsHandler handler = new CheckpointStatsHandler(mock(ExecutionGraphHolder.class));
String json = handler.handleRequest(testCheckpointStats.graph, Collections.<String, String>emptyMap());
ObjectMapper mapper = new ObjectMapper();
JsonNode rootNode = mapper.readTree(json);
compareCheckpointStats(testCheckpointStats, rootNode);
}
use of com.fasterxml.jackson.databind.ObjectMapper in project flink by apache.
the class CheckpointStatsHandlerTest method testArchiver.
@Test
public void testArchiver() throws IOException {
JsonArchivist archivist = new CheckpointStatsDetailsHandler.CheckpointStatsDetailsJsonArchivist();
TestCheckpointStats testCheckpointStats = createTestCheckpointStats();
when(testCheckpointStats.graph.getJobID()).thenReturn(new JobID());
Collection<ArchivedJson> archives = archivist.archiveJsonWithPath(testCheckpointStats.graph);
Assert.assertEquals(3, archives.size());
ObjectMapper mapper = new ObjectMapper();
Iterator<ArchivedJson> iterator = archives.iterator();
ArchivedJson archive1 = iterator.next();
Assert.assertEquals("/jobs/" + testCheckpointStats.graph.getJobID() + "/checkpoints/details/" + testCheckpointStats.inProgress.getCheckpointId(), archive1.getPath());
compareInProgressCheckpoint(testCheckpointStats.inProgress, mapper.readTree(archive1.getJson()));
ArchivedJson archive2 = iterator.next();
Assert.assertEquals("/jobs/" + testCheckpointStats.graph.getJobID() + "/checkpoints/details/" + testCheckpointStats.completedSavepoint.getCheckpointId(), archive2.getPath());
compareCompletedSavepoint(testCheckpointStats.completedSavepoint, mapper.readTree(archive2.getJson()));
ArchivedJson archive3 = iterator.next();
Assert.assertEquals("/jobs/" + testCheckpointStats.graph.getJobID() + "/checkpoints/details/" + testCheckpointStats.failed.getCheckpointId(), archive3.getPath());
compareFailedCheckpoint(testCheckpointStats.failed, mapper.readTree(archive3.getJson()));
}
use of com.fasterxml.jackson.databind.ObjectMapper in project flink by apache.
the class JobVertexBackPressureHandlerTest method testResponseStatsAvailable.
/** Tests the response when stats are available */
@Test
public void testResponseStatsAvailable() throws Exception {
ExecutionJobVertex jobVertex = mock(ExecutionJobVertex.class);
BackPressureStatsTracker statsTracker = mock(BackPressureStatsTracker.class);
OperatorBackPressureStats stats = new OperatorBackPressureStats(0, System.currentTimeMillis(), new double[] { 0.31, 0.48, 1.0, 0.0 });
when(statsTracker.getOperatorBackPressureStats(any(ExecutionJobVertex.class))).thenReturn(Option.apply(stats));
JobVertexBackPressureHandler handler = new JobVertexBackPressureHandler(mock(ExecutionGraphHolder.class), statsTracker, 9999);
String response = handler.handleRequest(jobVertex, Collections.<String, String>emptyMap());
ObjectMapper mapper = new ObjectMapper();
JsonNode rootNode = mapper.readTree(response);
// Single element
assertEquals(4, rootNode.size());
// Status
JsonNode status = rootNode.get("status");
assertNotNull(status);
assertEquals("ok", status.textValue());
// Back pressure level
JsonNode backPressureLevel = rootNode.get("backpressure-level");
assertNotNull(backPressureLevel);
assertEquals("high", backPressureLevel.textValue());
// End time stamp
JsonNode endTimeStamp = rootNode.get("end-timestamp");
assertNotNull(endTimeStamp);
assertEquals(stats.getEndTimestamp(), endTimeStamp.longValue());
// Subtasks
JsonNode subTasks = rootNode.get("subtasks");
assertEquals(stats.getNumberOfSubTasks(), subTasks.size());
for (int i = 0; i < subTasks.size(); i++) {
JsonNode subTask = subTasks.get(i);
JsonNode index = subTask.get("subtask");
assertEquals(i, index.intValue());
JsonNode level = subTask.get("backpressure-level");
assertEquals(JobVertexBackPressureHandler.getBackPressureLevel(stats.getBackPressureRatio(i)), level.textValue());
JsonNode ratio = subTask.get("ratio");
assertEquals(stats.getBackPressureRatio(i), ratio.doubleValue(), 0.0);
}
// Verify not triggered
verify(statsTracker, never()).triggerStackTraceSample(any(ExecutionJobVertex.class));
}
use of com.fasterxml.jackson.databind.ObjectMapper in project flink by apache.
the class CheckpointConfigHandlerTest method testAtLeastOnce.
/**
* Tests the that the isExactlyOnce flag is respected.
*/
@Test
public void testAtLeastOnce() throws Exception {
GraphAndSettings graphAndSettings = createGraphAndSettings(false, false);
AccessExecutionGraph graph = graphAndSettings.graph;
CheckpointConfigHandler handler = new CheckpointConfigHandler(mock(ExecutionGraphHolder.class));
String json = handler.handleRequest(graph, Collections.<String, String>emptyMap());
ObjectMapper mapper = new ObjectMapper();
JsonNode rootNode = mapper.readTree(json);
assertEquals("at_least_once", rootNode.get("mode").asText());
}
use of com.fasterxml.jackson.databind.ObjectMapper in project hadoop by apache.
the class KMSClientProvider method writeJson.
private static void writeJson(Map map, OutputStream os) throws IOException {
Writer writer = new OutputStreamWriter(os, StandardCharsets.UTF_8);
ObjectMapper jsonMapper = new ObjectMapper();
jsonMapper.writerWithDefaultPrettyPrinter().writeValue(writer, map);
}
Aggregations