SentinelUpdateController { @RequestMapping(value = "/rebalance/sentinels/{dcName}/{numOfClusters}", method = RequestMethod.POST) public RetMessage reBalanceSentinels(@PathVariable String dcName, @PathVariable int numOfClusters) { logger.info("[reBalanceSentinels] Start re-balance sentinels for {} clusters", numOfClusters); try { List<String> modifiedClusters = clusterService.reBalanceSentinels(dcName, numOfClusters, true); logger.info("[reBalanceSentinels] Successfully balanced {} clusters", numOfClusters); return RetMessage.createSuccessMessage("clusters: " + jsonTool.encode(modifiedClusters)); } catch (Exception e) { logger.error("[reBalanceSentinels] {}", e); return RetMessage.createFailMessage(e.getMessage()); } }  @RequestMapping(value = "/rebalance/sentinels/{dcName}/{numOfClusters}", method = RequestMethod.POST) RetMessage reBalanceSentinels(@PathVariable String dcName, @PathVariable int numOfClusters); @RequestMapping(value = "/rebalance/sentinels/force/{dcName}/{numOfClusters}", method = RequestMethod.POST) RetMessage reBalanceSentinelsForce(@PathVariable String dcName, @PathVariable int numOfClusters); @RequestMapping(value = "/sentinels", method = RequestMethod.POST) RetMessage addSentinel(@RequestBody SentinelModel sentinelModel); @RequestMapping(value = "/sentinels/{sentinelId}", method = RequestMethod.DELETE) RetMessage deleteSentinel(@PathVariable Long sentinelId); @RequestMapping(value = "/sentinels/{sentinelId}", method = RequestMethod.PATCH) RetMessage rehealSentinel(@PathVariable Long sentinelId); @RequestMapping(value = "/rebalance/sentinels/{dcName}", method = RequestMethod.POST) RetMessage reBalanceSentinels(@PathVariable String dcName, @RequestBody(required = false) List<String> clusterNames); @RequestMapping(value = "/sentinels/usage", method = RequestMethod.GET) RetMessage sentinelUsage(); @RequestMapping(value = "/sentinel/address", method = RequestMethod.PUT) RetMessage updateSentinelAddr(@RequestBody SentinelModel model); @RequestMapping(value = "/sentinel/monitor/{clusterName}", method = RequestMethod.DELETE) RetMessage removeSentinelMonitor(@PathVariable String clusterName);  }
@Test public void validateMock() { Assert.assertEquals(Collections.emptyList(), clusterService.reBalanceSentinels("jq", 0, true)); Assert.assertEquals(Arrays.asList(clusters), clusterService.reBalanceSentinels("test", 2, true)); }
@Test public void testReBalanceSentinels() throws Exception { RetMessage message = RetMessage.createSuccessMessage("clusters: " + jsonCodec.encode(Arrays.asList(clusters))); Assert.assertEquals(message.getMessage(), controller.reBalanceSentinels("sfo", 3).getMessage()); }
@Test public void reBalanceSentinels1() throws Exception { RetMessage message = RetMessage.createSuccessMessage("clusters: " + jsonCodec.encode(Arrays.asList(clusters))); Assert.assertEquals(message.getMessage(), controller.reBalanceSentinels("oy", null).getMessage()); }
@Test public void reBalanceSentinels2() throws Exception { String expectedMessage = "Expected Message"; when(clusterService.reBalanceSentinels("fra", -1, true)).thenThrow(new RuntimeException(expectedMessage)); RetMessage message = controller.reBalanceSentinels("fra", -1); Assert.assertEquals(-1, message.getState()); Assert.assertEquals(expectedMessage, message.getMessage()); }