JobOperateAPIImpl implements JobOperateAPI { @Override public void pause(final Optional<String> jobName, final Optional<String> serverIp) { jobOperatorTemplate.operate(jobName, serverIp, new JobOperateCallback() { @Override public boolean doOperate(final String jobName, final String serverIp) { registryCenter.persist(new JobNodePath(jobName).getServerNodePath(serverIp, JobNodePath.PAUSED_NODE), ""); return true; } }); } JobOperateAPIImpl(final CoordinatorRegistryCenter registryCenter); @Override void pause(final Optional<String> jobName, final Optional<String> serverIp); @Override void resume(final Optional<String> jobName, final Optional<String> serverIp); @Override void disable(final Optional<String> jobName, final Optional<String> serverIp); @Override void enable(final Optional<String> jobName, final Optional<String> serverIp); @Override void shutdown(final Optional<String> jobName, final Optional<String> serverIp); @Override Collection<String> remove(final Optional<String> jobName, final Optional<String> serverIp);  }
@Test public void assertPauseWithJobNameAndServerIp() { jobOperateAPI.pause(Optional.of("testJob"), Optional.of("localhost")); verify(registryCenter).persist("/testJob/servers/localhost/paused", ""); }
@Test public void assertPauseWithJobName() { when(registryCenter.getChildrenKeys("/testJob/servers")).thenReturn(Arrays.asList("ip1", "ip2")); jobOperateAPI.pause(Optional.of("testJob"), Optional.<String>absent()); verify(registryCenter).getChildrenKeys("/testJob/servers"); verify(registryCenter).persist("/testJob/servers/ip1/paused", ""); verify(registryCenter).persist("/testJob/servers/ip2/paused", ""); }
@Test public void assertPauseWithServerIp() { when(registryCenter.getChildrenKeys("/")).thenReturn(Arrays.asList("testJob1", "testJob2")); jobOperateAPI.pause(Optional.<String>absent(), Optional.of("localhost")); verify(registryCenter).getChildrenKeys("/"); verify(registryCenter).persist("/testJob1/servers/localhost/paused", ""); verify(registryCenter).persist("/testJob2/servers/localhost/paused", ""); }