test_class.file: flink-runtime-web/src/test/java/org/apache/flink/runtime/webmonitor/handlers/JobVertexBackPressureHandlerTest.java
test_class.identifier: JobVertexBackPressureHandlerTest
test_case.body: @Test
  	public void testResponseNoStatsAvailable() throws Exception {
  		ExecutionJobVertex jobVertex = mock(ExecutionJobVertex.class);
  		BackPressureStatsTracker statsTracker = mock(BackPressureStatsTracker.class);
  
  		when(statsTracker.getOperatorBackPressureStats(any(ExecutionJobVertex.class)))
  				.thenReturn(Option.<OperatorBackPressureStats>empty());
  
  		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(1, rootNode.size());
  
  		// Status
  		JsonNode status = rootNode.get("status");
  		assertNotNull(status);
  		assertEquals("deprecated", status.textValue());
  
  		verify(statsTracker).triggerStackTraceSample(any(ExecutionJobVertex.class));
  	}
test_case.class_method_signature: JobVertexBackPressureHandlerTest.testResponseNoStatsAvailable()
test_case.full_signature: @Test public void testResponseNoStatsAvailable()
test_case.identifier: testResponseNoStatsAvailable
test_case.invocations: mock mock thenReturn when getOperatorBackPressureStats any empty mock handleRequest emptyMap readTree assertEquals size get assertNotNull assertEquals textValue triggerStackTraceSample verify any
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testResponseNoStatsAvailable()
focal_class.declarator: backPressureStatsTracker
focal_class.modifier: private final
focal_class.original_string: private final BackPressureStatsTracker backPressureStatsTracker;
focal_class.type: BackPressureStatsTracker
focal_class.var_name: backPressureStatsTracker
focal_class.declarator: refreshInterval
focal_class.modifier: private final
focal_class.original_string: private final int refreshInterval;
focal_class.type: int
focal_class.var_name: refreshInterval
focal_class.file: flink-runtime-web/src/main/java/org/apache/flink/runtime/webmonitor/handlers/JobVertexBackPressureHandler.java
focal_class.identifier: JobVertexBackPressureHandler
focal_class.class_method_signature: JobVertexBackPressureHandler.JobVertexBackPressureHandler(
  			ExecutionGraphHolder executionGraphHolder,
  			BackPressureStatsTracker backPressureStatsTracker,
  			int refreshInterval)
focal_class.full_signature: public  JobVertexBackPressureHandler(
  			ExecutionGraphHolder executionGraphHolder,
  			BackPressureStatsTracker backPressureStatsTracker,
  			int refreshInterval)
focal_class.identifier: JobVertexBackPressureHandler
focal_class.modifiers: public
focal_class.parameters: (
  			ExecutionGraphHolder executionGraphHolder,
  			BackPressureStatsTracker backPressureStatsTracker,
  			int refreshInterval)
focal_class.signature:  JobVertexBackPressureHandler(
  			ExecutionGraphHolder executionGraphHolder,
  			BackPressureStatsTracker backPressureStatsTracker,
  			int refreshInterval)
focal_class.class_method_signature: JobVertexBackPressureHandler.handleRequest(
  			ExecutionJobVertex jobVertex,
  			Map<String, String> params)
focal_class.full_signature: @Override public String handleRequest(
  			ExecutionJobVertex jobVertex,
  			Map<String, String> params)
focal_class.identifier: handleRequest
focal_class.modifiers: @Override public
focal_class.parameters: (
  			ExecutionJobVertex jobVertex,
  			Map<String, String> params)
focal_class.return: String
focal_class.signature: String handleRequest(
  			ExecutionJobVertex jobVertex,
  			Map<String, String> params)
focal_class.class_method_signature: JobVertexBackPressureHandler.getBackPressureLevel(double backPressureRatio)
focal_class.full_signature: static String getBackPressureLevel(double backPressureRatio)
focal_class.identifier: getBackPressureLevel
focal_class.modifiers: static
focal_class.parameters: (double backPressureRatio)
focal_class.return: String
focal_class.signature: String getBackPressureLevel(double backPressureRatio)
focal_class.superclass: extends AbstractJobVertexRequestHandler
focal_method.body: @Override
  	public String handleRequest(
  			ExecutionJobVertex jobVertex,
  			Map<String, String> params) throws Exception {
  
  		try (StringWriter writer = new StringWriter();
  				JsonGenerator gen = JsonFactory.jacksonFactory.createGenerator(writer)) {
  
  			gen.writeStartObject();
  
  			Option<OperatorBackPressureStats> statsOption = backPressureStatsTracker
  					.getOperatorBackPressureStats(jobVertex);
  
  			if (statsOption.isDefined()) {
  				OperatorBackPressureStats stats = statsOption.get();
  
  				// Check whether we need to refresh
  				if (refreshInterval <= System.currentTimeMillis() - stats.getEndTimestamp()) {
  					backPressureStatsTracker.triggerStackTraceSample(jobVertex);
  					gen.writeStringField("status", "deprecated");
  				} else {
  					gen.writeStringField("status", "ok");
  				}
  
  				gen.writeStringField("backpressure-level", getBackPressureLevel(stats.getMaxBackPressureRatio()));
  				gen.writeNumberField("end-timestamp", stats.getEndTimestamp());
  
  				// Sub tasks
  				gen.writeArrayFieldStart("subtasks");
  				int numSubTasks = stats.getNumberOfSubTasks();
  				for (int i = 0; i < numSubTasks; i++) {
  					double ratio = stats.getBackPressureRatio(i);
  
  					gen.writeStartObject();
  					gen.writeNumberField("subtask", i);
  					gen.writeStringField("backpressure-level", getBackPressureLevel(ratio));
  					gen.writeNumberField("ratio", ratio);
  					gen.writeEndObject();
  				}
  				gen.writeEndArray();
  			} else {
  				backPressureStatsTracker.triggerStackTraceSample(jobVertex);
  				gen.writeStringField("status", "deprecated");
  			}
  
  			gen.writeEndObject();
  			gen.close();
  
  			return writer.toString();
  		}
  	}
focal_method.class_method_signature: JobVertexBackPressureHandler.handleRequest(
  			ExecutionJobVertex jobVertex,
  			Map<String, String> params)
focal_method.full_signature: @Override public String handleRequest(
  			ExecutionJobVertex jobVertex,
  			Map<String, String> params)
focal_method.identifier: handleRequest
focal_method.invocations: createGenerator writeStartObject getOperatorBackPressureStats isDefined get currentTimeMillis getEndTimestamp triggerStackTraceSample writeStringField writeStringField writeStringField getBackPressureLevel getMaxBackPressureRatio writeNumberField getEndTimestamp writeArrayFieldStart getNumberOfSubTasks getBackPressureRatio writeStartObject writeNumberField writeStringField getBackPressureLevel writeNumberField writeEndObject writeEndArray triggerStackTraceSample writeStringField writeEndObject close toString
focal_method.modifiers: @Override public
focal_method.parameters: (
  			ExecutionJobVertex jobVertex,
  			Map<String, String> params)
focal_method.return: String
focal_method.signature: String handleRequest(
  			ExecutionJobVertex jobVertex,
  			Map<String, String> params)