@Test
public void testJobManagerLeaderElection() throws Exception {

	JobID jobId1 = new JobID();
	JobID jobId2 = new JobID();
	LeaderContender leaderContender1 = mock(LeaderContender.class);
	LeaderContender leaderContender2 = mock(LeaderContender.class);
	LeaderContender leaderContenderDifferentJobId = mock(LeaderContender.class);
	LeaderElectionService leaderElectionService1 = embeddedHaServices.getJobManagerLeaderElectionService(jobId1);
	LeaderElectionService leaderElectionService2 = embeddedHaServices.getJobManagerLeaderElectionService(jobId1);
	LeaderElectionService leaderElectionServiceDifferentJobId = embeddedHaServices.getJobManagerLeaderElectionService(jobId2);
	leaderElectionService1.start(leaderContender1);
	leaderElectionService2.start(leaderContender2);
	leaderElectionServiceDifferentJobId.start(leaderContenderDifferentJobId);
	ArgumentCaptor<UUID> leaderIdArgumentCaptor1 = ArgumentCaptor.forClass(UUID.class);
	ArgumentCaptor<UUID> leaderIdArgumentCaptor2 = ArgumentCaptor.forClass(UUID.class);
	verify(leaderContender1, atLeast(0)).grantLeadership(leaderIdArgumentCaptor1.capture());
	verify(leaderContender2, atLeast(0)).grantLeadership(leaderIdArgumentCaptor2.capture());
	assertTrue(leaderIdArgumentCaptor1.getAllValues().isEmpty() ^ leaderIdArgumentCaptor2.getAllValues().isEmpty());
	verify(leaderContenderDifferentJobId).grantLeadership(any(UUID.class));
}