ShrinkManager { public long shrinkNodeGroup(String clusterName, String nodeGroupName, int newInstanceNum) throws Exception { ValidationUtils.validateVersion(clusterEntityMgr, clusterName); ClusterStatus originalStatus = clusterEntityMgr.findByName(clusterName).getStatus(); logger.info("Before shrink, cluster status is:" + originalStatus); List<JobParameters> jobParametersList = buildJobParameters(clusterName, nodeGroupName, newInstanceNum); if (jobParametersList.size() == 0) { throw ShrinkException.NO_NEED_TO_SHRINK(); } try { logger.info("set cluster to maintenace"); clusterEntityMgr.updateClusterStatus(clusterName, ClusterStatus.MAINTENANCE); return jobManager.runSubJobForNodes(JobConstants.SHRINK_CLUSTER_JOB_NAME, jobParametersList, clusterName, originalStatus, ClusterStatus.ERROR); } catch (Throwable t) { logger.error("Failed to shrink cluster " + clusterName, t); clusterEntityMgr.updateClusterStatus(clusterName, originalStatus); throw ShrinkException.SHRINK_NODE_GROUP_FAILED(t, clusterName, t.getMessage()); } }  long shrinkNodeGroup(String clusterName, String nodeGroupName, int newInstanceNum); IClusterEntityManager getClusterEntityMgr(); void setClusterEntityMgr(IClusterEntityManager clusterEntityMgr); JobManager getJobManager(); void setJobManager(JobManager jobManager);  }
@Test public void testShrinkNodeGroup() throws Exception { Mockito.when(shrinkManager.buildJobParameters(Mockito.anyString(), Mockito.anyString(), Mockito.anyInt())). thenReturn(new ArrayList<JobParameters>()); System.out.println("Before test, shrink manager is : " + shrinkManager); try { long result = shrinkManager.shrinkNodeGroup("cluster", "nodeGroup", 1); System.out.println("the result is :" + result); } catch (ShrinkException e) { System.out.println("Got exception: " + e); } }