use of com.fasterxml.jackson.databind.JsonNode in project flink by apache.
the class SubtaskExecutionAttemptDetailsHandlerTest method compareAttemptDetails.
private static void compareAttemptDetails(AccessExecution originalAttempt, String json) throws IOException {
JsonNode result = ArchivedJobGenerationUtils.mapper.readTree(json);
Assert.assertEquals(originalAttempt.getParallelSubtaskIndex(), result.get("subtask").asInt());
Assert.assertEquals(originalAttempt.getState().name(), result.get("status").asText());
Assert.assertEquals(originalAttempt.getAttemptNumber(), result.get("attempt").asInt());
Assert.assertEquals(originalAttempt.getAssignedResourceLocation().getHostname(), result.get("host").asText());
long start = originalAttempt.getStateTimestamp(ExecutionState.DEPLOYING);
Assert.assertEquals(start, result.get("start-time").asLong());
long end = originalAttempt.getStateTimestamp(ExecutionState.FINISHED);
Assert.assertEquals(end, result.get("end-time").asLong());
Assert.assertEquals(end - start, result.get("duration").asLong());
ArchivedJobGenerationUtils.compareIoMetrics(originalAttempt.getIOMetrics(), result.get("metrics"));
}
use of com.fasterxml.jackson.databind.JsonNode in project flink by apache.
the class SubtasksAllAccumulatorsHandlerTest method compareSubtaskAccumulators.
private static void compareSubtaskAccumulators(AccessExecutionJobVertex originalTask, String json) throws IOException {
JsonNode result = ArchivedJobGenerationUtils.mapper.readTree(json);
Assert.assertEquals(originalTask.getJobVertexId().toString(), result.get("id").asText());
Assert.assertEquals(originalTask.getParallelism(), result.get("parallelism").asInt());
ArrayNode subtasks = (ArrayNode) result.get("subtasks");
Assert.assertEquals(originalTask.getTaskVertices().length, subtasks.size());
for (int x = 0; x < originalTask.getTaskVertices().length; x++) {
JsonNode subtask = subtasks.get(x);
AccessExecutionVertex expectedSubtask = originalTask.getTaskVertices()[x];
Assert.assertEquals(x, subtask.get("subtask").asInt());
Assert.assertEquals(expectedSubtask.getCurrentExecutionAttempt().getAttemptNumber(), subtask.get("attempt").asInt());
Assert.assertEquals(expectedSubtask.getCurrentAssignedResourceLocation().getHostname(), subtask.get("host").asText());
ArchivedJobGenerationUtils.compareStringifiedAccumulators(expectedSubtask.getCurrentExecutionAttempt().getUserAccumulatorsStringified(), (ArrayNode) subtask.get("user-accumulators"));
}
}
use of com.fasterxml.jackson.databind.JsonNode in project flink by apache.
the class SubtasksTimesHandlerTest method compareSubtaskTimes.
private static void compareSubtaskTimes(AccessExecutionJobVertex originalTask, AccessExecution originalAttempt, String json) throws IOException {
JsonNode result = ArchivedJobGenerationUtils.mapper.readTree(json);
Assert.assertEquals(originalTask.getJobVertexId().toString(), result.get("id").asText());
Assert.assertEquals(originalTask.getName(), result.get("name").asText());
Assert.assertTrue(result.get("now").asLong() > 0L);
ArrayNode subtasks = (ArrayNode) result.get("subtasks");
JsonNode subtask = subtasks.get(0);
Assert.assertEquals(0, subtask.get("subtask").asInt());
Assert.assertEquals(originalAttempt.getAssignedResourceLocation().getHostname(), subtask.get("host").asText());
Assert.assertEquals(originalAttempt.getStateTimestamp(originalAttempt.getState()) - originalAttempt.getStateTimestamp(ExecutionState.SCHEDULED), subtask.get("duration").asLong());
JsonNode timestamps = subtask.get("timestamps");
Assert.assertEquals(originalAttempt.getStateTimestamp(ExecutionState.CREATED), timestamps.get(ExecutionState.CREATED.name()).asLong());
Assert.assertEquals(originalAttempt.getStateTimestamp(ExecutionState.SCHEDULED), timestamps.get(ExecutionState.SCHEDULED.name()).asLong());
Assert.assertEquals(originalAttempt.getStateTimestamp(ExecutionState.DEPLOYING), timestamps.get(ExecutionState.DEPLOYING.name()).asLong());
Assert.assertEquals(originalAttempt.getStateTimestamp(ExecutionState.RUNNING), timestamps.get(ExecutionState.RUNNING.name()).asLong());
Assert.assertEquals(originalAttempt.getStateTimestamp(ExecutionState.FINISHED), timestamps.get(ExecutionState.FINISHED.name()).asLong());
Assert.assertEquals(originalAttempt.getStateTimestamp(ExecutionState.CANCELING), timestamps.get(ExecutionState.CANCELING.name()).asLong());
Assert.assertEquals(originalAttempt.getStateTimestamp(ExecutionState.CANCELED), timestamps.get(ExecutionState.CANCELED.name()).asLong());
Assert.assertEquals(originalAttempt.getStateTimestamp(ExecutionState.FAILED), timestamps.get(ExecutionState.FAILED.name()).asLong());
}
use of com.fasterxml.jackson.databind.JsonNode 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.JsonNode in project hadoop by apache.
the class TestLog4Json method testNestedException.
@Test
public void testNestedException() throws Throwable {
Exception e = new NoRouteToHostException("that box caught fire 3 years ago");
Exception ioe = new IOException("Datacenter problems", e);
ThrowableInformation ti = new ThrowableInformation(ioe);
Log4Json l4j = new Log4Json();
long timeStamp = Time.now();
String outcome = l4j.toJson(new StringWriter(), "testNestedException", timeStamp, "INFO", "quoted\"", "new line\n and {}", ti).toString();
println("testNestedException", outcome);
ContainerNode rootNode = Log4Json.parse(outcome);
assertEntryEquals(rootNode, Log4Json.LEVEL, "INFO");
assertEntryEquals(rootNode, Log4Json.NAME, "testNestedException");
assertEntryEquals(rootNode, Log4Json.TIME, timeStamp);
assertEntryEquals(rootNode, Log4Json.EXCEPTION_CLASS, ioe.getClass().getName());
JsonNode node = assertNodeContains(rootNode, Log4Json.STACK);
assertTrue("Not an array: " + node, node.isArray());
node = assertNodeContains(rootNode, Log4Json.DATE);
assertTrue("Not a string: " + node, node.isTextual());
//rather than try and make assertions about the format of the text
//message equalling another ISO date, this test asserts that the hypen
//and colon characters are in the string.
String dateText = node.textValue();
assertTrue("No '-' in " + dateText, dateText.contains("-"));
assertTrue("No '-' in " + dateText, dateText.contains(":"));
}
Aggregations