@Test public void testReadiness() throws Exception { String url = "/v1/console/health/readiness"; Mockito.when(persistService.configInfoCount(any(String.class))).thenReturn(0); Mockito.when(apiCommands.metrics(any(HttpServletRequest.class))).thenReturn(JacksonUtils.createEmptyJsonNode()); MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.get(url); Assert.assertEquals(200, mockmvc.perform(builder).andReturn().getResponse().getStatus()); Mockito.when(persistService.configInfoCount(any(String.class))) .thenThrow(new RuntimeException("HealthControllerTest.testReadiness")); Mockito.when(apiCommands.metrics(any(HttpServletRequest.class))) .thenThrow(new RuntimeException("HealthControllerTest.testReadiness")); builder = MockMvcRequestBuilders.get(url); MockHttpServletResponse response = mockmvc.perform(builder).andReturn().getResponse(); Assert.assertEquals(500, response.getStatus()); Assert.assertEquals("Config and Naming are not in readiness", response.getContentAsString()); Mockito.when(persistService.configInfoCount(any(String.class))) .thenThrow(new RuntimeException("HealthControllerTest.testReadiness")); Mockito.when(apiCommands.metrics(any(HttpServletRequest.class))).thenReturn(JacksonUtils.createEmptyJsonNode()); response = mockmvc.perform(builder).andReturn().getResponse(); Assert.assertEquals(500, response.getStatus()); Assert.assertEquals("Config is not in readiness", response.getContentAsString()); Mockito.when(persistService.configInfoCount(any(String.class))).thenReturn(0); Mockito.when(apiCommands.metrics(any(HttpServletRequest.class))) .thenThrow(new RuntimeException("HealthControllerTest.testReadiness")); builder = MockMvcRequestBuilders.get(url); response = mockmvc.perform(builder).andReturn().getResponse(); Assert.assertEquals(500, response.getStatus()); Assert.assertEquals("Naming is not in readiness", response.getContentAsString()); }
@GetMapping("/readiness") public ResponseEntity readiness(HttpServletRequest request) { boolean isConfigReadiness = isConfigReadiness(); boolean isNamingReadiness = isNamingReadiness(request); if (isConfigReadiness && isNamingReadiness) { return ResponseEntity.ok().body("OK"); } if (!isConfigReadiness && !isNamingReadiness) { return ResponseEntity.status(500).body("Config and Naming are not in readiness"); } if (!isConfigReadiness) { return ResponseEntity.status(500).body("Config is not in readiness"); } return ResponseEntity.status(500).body("Naming is not in readiness"); }
HealthController { @GetMapping("/readiness") public ResponseEntity readiness(HttpServletRequest request) { boolean isConfigReadiness = isConfigReadiness(); boolean isNamingReadiness = isNamingReadiness(request); if (isConfigReadiness && isNamingReadiness) { return ResponseEntity.ok().body("OK"); } if (!isConfigReadiness && !isNamingReadiness) { return ResponseEntity.status(500).body("Config and Naming are not in readiness"); } if (!isConfigReadiness) { return ResponseEntity.status(500).body("Config is not in readiness"); } return ResponseEntity.status(500).body("Naming is not in readiness"); } }
HealthController { @GetMapping("/readiness") public ResponseEntity readiness(HttpServletRequest request) { boolean isConfigReadiness = isConfigReadiness(); boolean isNamingReadiness = isNamingReadiness(request); if (isConfigReadiness && isNamingReadiness) { return ResponseEntity.ok().body("OK"); } if (!isConfigReadiness && !isNamingReadiness) { return ResponseEntity.status(500).body("Config and Naming are not in readiness"); } if (!isConfigReadiness) { return ResponseEntity.status(500).body("Config is not in readiness"); } return ResponseEntity.status(500).body("Naming is not in readiness"); } @Autowired  HealthController(PersistService persistService, OperatorController apiCommands); }
HealthController { @GetMapping("/readiness") public ResponseEntity readiness(HttpServletRequest request) { boolean isConfigReadiness = isConfigReadiness(); boolean isNamingReadiness = isNamingReadiness(request); if (isConfigReadiness && isNamingReadiness) { return ResponseEntity.ok().body("OK"); } if (!isConfigReadiness && !isNamingReadiness) { return ResponseEntity.status(500).body("Config and Naming are not in readiness"); } if (!isConfigReadiness) { return ResponseEntity.status(500).body("Config is not in readiness"); } return ResponseEntity.status(500).body("Naming is not in readiness"); } @Autowired  HealthController(PersistService persistService, OperatorController apiCommands); @GetMapping("/liveness") ResponseEntity liveness(); @GetMapping("/readiness") ResponseEntity readiness(HttpServletRequest request); }
HealthController { @GetMapping("/readiness") public ResponseEntity readiness(HttpServletRequest request) { boolean isConfigReadiness = isConfigReadiness(); boolean isNamingReadiness = isNamingReadiness(request); if (isConfigReadiness && isNamingReadiness) { return ResponseEntity.ok().body("OK"); } if (!isConfigReadiness && !isNamingReadiness) { return ResponseEntity.status(500).body("Config and Naming are not in readiness"); } if (!isConfigReadiness) { return ResponseEntity.status(500).body("Config is not in readiness"); } return ResponseEntity.status(500).body("Naming is not in readiness"); } @Autowired  HealthController(PersistService persistService, OperatorController apiCommands); @GetMapping("/liveness") ResponseEntity liveness(); @GetMapping("/readiness") ResponseEntity readiness(HttpServletRequest request);  }