@Test public void assertIsLeaderUntilBlockWhenHasLeader() { JobRegistry.getInstance().registerRegistryCenter("test_job", regCenter); JobRegistry.getInstance().registerJob("test_job", jobScheduleController); when(jobNodeStorage.isJobNodeExisted("leader/election/instance")).thenReturn(false, true); when(serverService.hasAvailableServers()).thenReturn(true); when(serverService.isAvailableServer("127.0.0.1")).thenReturn(true); when(jobNodeStorage.getJobNodeData("leader/election/instance")).thenReturn("127.0.0.1@-@0"); assertTrue(leaderService.isLeaderUntilBlock()); verify(jobNodeStorage).executeInLeader(eq("leader/election/latch"), ArgumentMatchers.<LeaderElectionExecutionCallback>any()); JobRegistry.getInstance().shutdown("test_job"); }
public boolean isLeaderUntilBlock() { while (!hasLeader() && serverService.hasAvailableServers()) { log.info("Leader is electing, waiting for {} ms", 100); BlockUtils.waitingShortTime(); if (!JobRegistry.getInstance().isShutdown(jobName) && serverService.isAvailableServer(JobRegistry.getInstance().getJobInstance(jobName).getIp())) { electLeader(); } } return isLeader(); }
LeaderService { public boolean isLeaderUntilBlock() { while (!hasLeader() && serverService.hasAvailableServers()) { log.info("Leader is electing, waiting for {} ms", 100); BlockUtils.waitingShortTime(); if (!JobRegistry.getInstance().isShutdown(jobName) && serverService.isAvailableServer(JobRegistry.getInstance().getJobInstance(jobName).getIp())) { electLeader(); } } return isLeader(); } }
LeaderService { public boolean isLeaderUntilBlock() { while (!hasLeader() && serverService.hasAvailableServers()) { log.info("Leader is electing, waiting for {} ms", 100); BlockUtils.waitingShortTime(); if (!JobRegistry.getInstance().isShutdown(jobName) && serverService.isAvailableServer(JobRegistry.getInstance().getJobInstance(jobName).getIp())) { electLeader(); } } return isLeader(); } LeaderService(final CoordinatorRegistryCenter regCenter, final String jobName); }
LeaderService { public boolean isLeaderUntilBlock() { while (!hasLeader() && serverService.hasAvailableServers()) { log.info("Leader is electing, waiting for {} ms", 100); BlockUtils.waitingShortTime(); if (!JobRegistry.getInstance().isShutdown(jobName) && serverService.isAvailableServer(JobRegistry.getInstance().getJobInstance(jobName).getIp())) { electLeader(); } } return isLeader(); } LeaderService(final CoordinatorRegistryCenter regCenter, final String jobName); void electLeader(); boolean isLeaderUntilBlock(); boolean isLeader(); boolean hasLeader(); void removeLeader(); }
LeaderService { public boolean isLeaderUntilBlock() { while (!hasLeader() && serverService.hasAvailableServers()) { log.info("Leader is electing, waiting for {} ms", 100); BlockUtils.waitingShortTime(); if (!JobRegistry.getInstance().isShutdown(jobName) && serverService.isAvailableServer(JobRegistry.getInstance().getJobInstance(jobName).getIp())) { electLeader(); } } return isLeader(); } LeaderService(final CoordinatorRegistryCenter regCenter, final String jobName); void electLeader(); boolean isLeaderUntilBlock(); boolean isLeader(); boolean hasLeader(); void removeLeader();  }