test_class.file: flink-runtime-web/src/test/java/org/apache/flink/runtime/webmonitor/handlers/JobCheckpointsHandlerTest.java
test_class.identifier: JobCheckpointsHandlerTest
test_case.body: @Test
  	public void testStats() throws Exception {
  		JobCheckpointsHandler handler = new JobCheckpointsHandler(
  				mock(ExecutionGraphHolder.class));
  
  		ExecutionGraph graph = mock(ExecutionGraph.class);
  		CheckpointStatsTracker tracker = mock(CheckpointStatsTracker.class);
  
  		when(graph.getCheckpointStatsTracker()).thenReturn(tracker);
  
  		final List<CheckpointStats> history = new ArrayList<>();
  		history.add(new CheckpointStats(0, 1, 1, 124));
  		history.add(new CheckpointStats(1, 5, 177, 0));
  		history.add(new CheckpointStats(2, 6, 8282, 2));
  		history.add(new CheckpointStats(3, 6812, 2800, 1024));
  
  		JobCheckpointStats stats = new JobCheckpointStats() {
  			@Override
  			public List<CheckpointStats> getRecentHistory() {
  				return history;
  			}
  
  			@Override
  			public long getCount() {
  				return 4;
  			}
  
  			@Override
  			public long getMinDuration() {
  				return 1;
  			}
  
  			@Override
  			public long getMaxDuration() {
  				return 8282;
  			}
  
  			@Override
  			public long getAverageDuration() {
  				return 2815;
  			}
  
  			@Override
  			public long getMinStateSize() {
  				return 0;
  			}
  
  			@Override
  			public long getMaxStateSize() {
  				return 1024;
  			}
  
  			@Override
  			public long getAverageStateSize() {
  				return 287;
  			}
  		};
  
  		when(tracker.getJobStats()).thenReturn(Option.apply(stats));
  
  		// Request stats
  		String response = handler.handleRequest(graph, Collections.<String, String>emptyMap());
  
  		ObjectMapper mapper = new ObjectMapper();
  		JsonNode rootNode = mapper.readTree(response);
  
  		// Count
  		int count = rootNode.get("count").asInt();
  		assertEquals(stats.getCount(), count);
  
  		// Duration
  		JsonNode durationNode = rootNode.get("duration");
  		assertNotNull(durationNode);
  
  		long minDuration = durationNode.get("min").asLong();
  		long maxDuration = durationNode.get("max").asLong();
  		long avgDuration = durationNode.get("avg").asLong();
  
  		assertEquals(stats.getMinDuration(), minDuration);
  		assertEquals(stats.getMaxDuration(), maxDuration);
  		assertEquals(stats.getAverageDuration(), avgDuration);
  
  		// State size
  		JsonNode sizeNode = rootNode.get("size");
  		assertNotNull(sizeNode);
  
  		long minSize = sizeNode.get("min").asLong();
  		long maxSize = sizeNode.get("max").asLong();
  		long avgSize = sizeNode.get("avg").asLong();
  
  		assertEquals(stats.getMinStateSize(), minSize);
  		assertEquals(stats.getMaxStateSize(), maxSize);
  		assertEquals(stats.getAverageStateSize(), avgSize);
  
  		JsonNode historyNode = rootNode.get("history");
  		assertNotNull(historyNode);
  		assertTrue(historyNode.isArray());
  
  		Iterator<JsonNode> it = historyNode.elements();
  
  		for (int i = 0; i < history.size(); i++) {
  			CheckpointStats s = history.get(i);
  
  			JsonNode node = it.next();
  
  			long checkpointId = node.get("id").asLong();
  			long timestamp = node.get("timestamp").asLong();
  			long duration = node.get("duration").asLong();
  			long size = node.get("size").asLong();
  
  			assertEquals(s.getCheckpointId(), checkpointId);
  			assertEquals(s.getTriggerTimestamp(), timestamp);
  			assertEquals(s.getDuration(), duration);
  			assertEquals(s.getStateSize(), size);
  		}
  
  		assertFalse(it.hasNext());
  	}
test_case.class_method_signature: JobCheckpointsHandlerTest.testStats()
test_case.full_signature: @Test public void testStats()
test_case.identifier: testStats
test_case.invocations: mock mock mock thenReturn when getCheckpointStatsTracker add add add add thenReturn when getJobStats apply handleRequest emptyMap readTree asInt get assertEquals getCount get assertNotNull asLong get asLong get asLong get assertEquals getMinDuration assertEquals getMaxDuration assertEquals getAverageDuration get assertNotNull asLong get asLong get asLong get assertEquals getMinStateSize assertEquals getMaxStateSize assertEquals getAverageStateSize get assertNotNull assertTrue isArray elements size get next asLong get asLong get asLong get asLong get assertEquals getCheckpointId assertEquals getTriggerTimestamp assertEquals getDuration assertEquals getStateSize assertFalse hasNext
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testStats()
focal_class.file: flink-runtime-web/src/main/java/org/apache/flink/runtime/webmonitor/handlers/JobCheckpointsHandler.java
focal_class.identifier: JobCheckpointsHandler
focal_class.class_method_signature: JobCheckpointsHandler.JobCheckpointsHandler(ExecutionGraphHolder executionGraphHolder)
focal_class.full_signature: public  JobCheckpointsHandler(ExecutionGraphHolder executionGraphHolder)
focal_class.identifier: JobCheckpointsHandler
focal_class.modifiers: public
focal_class.parameters: (ExecutionGraphHolder executionGraphHolder)
focal_class.signature:  JobCheckpointsHandler(ExecutionGraphHolder executionGraphHolder)
focal_class.class_method_signature: JobCheckpointsHandler.handleRequest(ExecutionGraph graph, Map<String, String> params)
focal_class.full_signature: @Override public String handleRequest(ExecutionGraph graph, Map<String, String> params)
focal_class.identifier: handleRequest
focal_class.modifiers: @Override public
focal_class.parameters: (ExecutionGraph graph, Map<String, String> params)
focal_class.return: String
focal_class.signature: String handleRequest(ExecutionGraph graph, Map<String, String> params)
focal_class.superclass: extends AbstractExecutionGraphRequestHandler
focal_method.body: @Override
  	public String handleRequest(ExecutionGraph graph, Map<String, String> params) throws Exception {
  		StringWriter writer = new StringWriter();
  		JsonGenerator gen = JsonFactory.jacksonFactory.createGenerator(writer);
  
  		CheckpointStatsTracker tracker = graph.getCheckpointStatsTracker();
  
  		gen.writeStartObject();
  
  		if (tracker != null) {
  			Option<JobCheckpointStats> stats = tracker.getJobStats();
  
  			if (stats.isDefined()) {
  				// Total number of checkpoints
  				gen.writeNumberField("count", stats.get().getCount());
  
  				// Duration
  				gen.writeFieldName("duration");
  				gen.writeStartObject();
  				gen.writeNumberField("min", stats.get().getMinDuration());
  				gen.writeNumberField("max", stats.get().getMaxDuration());
  				gen.writeNumberField("avg", stats.get().getAverageDuration());
  				gen.writeEndObject();
  
  				// State size
  				gen.writeFieldName("size");
  				gen.writeStartObject();
  				gen.writeNumberField("min", stats.get().getMinStateSize());
  				gen.writeNumberField("max", stats.get().getMaxStateSize());
  				gen.writeNumberField("avg", stats.get().getAverageStateSize());
  				gen.writeEndObject();
  
  				// Recent history
  				gen.writeArrayFieldStart("history");
  				for (CheckpointStats checkpoint : stats.get().getRecentHistory()) {
  					gen.writeStartObject();
  					gen.writeNumberField("id", checkpoint.getCheckpointId());
  					gen.writeNumberField("timestamp", checkpoint.getTriggerTimestamp());
  					gen.writeNumberField("duration", checkpoint.getDuration());
  					gen.writeNumberField("size", checkpoint.getStateSize());
  					gen.writeEndObject();
  				}
  				gen.writeEndArray();
  			}
  		}
  
  		gen.writeEndObject();
  		gen.close();
  
  		return writer.toString();
  	}
focal_method.class_method_signature: JobCheckpointsHandler.handleRequest(ExecutionGraph graph, Map<String, String> params)
focal_method.full_signature: @Override public String handleRequest(ExecutionGraph graph, Map<String, String> params)
focal_method.identifier: handleRequest
focal_method.invocations: createGenerator getCheckpointStatsTracker writeStartObject getJobStats isDefined writeNumberField getCount get writeFieldName writeStartObject writeNumberField getMinDuration get writeNumberField getMaxDuration get writeNumberField getAverageDuration get writeEndObject writeFieldName writeStartObject writeNumberField getMinStateSize get writeNumberField getMaxStateSize get writeNumberField getAverageStateSize get writeEndObject writeArrayFieldStart getRecentHistory get writeStartObject writeNumberField getCheckpointId writeNumberField getTriggerTimestamp writeNumberField getDuration writeNumberField getStateSize writeEndObject writeEndArray writeEndObject close toString
focal_method.modifiers: @Override public
focal_method.parameters: (ExecutionGraph graph, Map<String, String> params)
focal_method.return: String
focal_method.signature: String handleRequest(ExecutionGraph graph, Map<String, String> params)