Java Code Examples for org.apache.flink.runtime.leaderelection.LeaderElectionService#start()
The following examples show how to use
org.apache.flink.runtime.leaderelection.LeaderElectionService#start() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EmbeddedLeaderServiceTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
/** * Tests that the {@link EmbeddedLeaderService} can handle a concurrent grant * leadership call and a shutdown. */ @Test public void testConcurrentGrantLeadershipAndShutdown() throws Exception { final EmbeddedLeaderService embeddedLeaderService = new EmbeddedLeaderService(TestingUtils.defaultExecutor()); try { final LeaderElectionService leaderElectionService = embeddedLeaderService.createLeaderElectionService(); final TestingLeaderContender contender = new TestingLeaderContender(); leaderElectionService.start(contender); leaderElectionService.stop(); try { // check that no exception occurred contender.getLeaderSessionFuture().get(10L, TimeUnit.MILLISECONDS); } catch (TimeoutException ignored) { // we haven't participated in the leader election } // the election service should still be running Assert.assertThat(embeddedLeaderService.isShutdown(), is(false)); } finally { embeddedLeaderService.shutdown(); } }
Example 2
Source File: StandaloneHaServicesTest.java From flink with Apache License 2.0 | 6 votes |
/** * Tests that the standalone leader election services return a fixed address and leader session * id. */ @Test public void testLeaderElection() throws Exception { JobID jobId = new JobID(); LeaderContender jmLeaderContender = mock(LeaderContender.class); LeaderContender rmLeaderContender = mock(LeaderContender.class); LeaderElectionService jmLeaderElectionService = standaloneHaServices.getJobManagerLeaderElectionService(jobId); LeaderElectionService rmLeaderElectionService = standaloneHaServices.getResourceManagerLeaderElectionService(); jmLeaderElectionService.start(jmLeaderContender); rmLeaderElectionService.start(rmLeaderContender); verify(jmLeaderContender).grantLeadership(eq(HighAvailabilityServices.DEFAULT_LEADER_ID)); verify(rmLeaderContender).grantLeadership(eq(HighAvailabilityServices.DEFAULT_LEADER_ID)); }
Example 3
Source File: EmbeddedHaServicesTest.java From flink with Apache License 2.0 | 6 votes |
/** * Tests the ResourceManager leader retrieval for a given job. */ @Test public void testResourceManagerLeaderRetrieval() throws Exception { final String address = "foobar"; LeaderRetrievalListener leaderRetrievalListener = mock(LeaderRetrievalListener.class); LeaderContender leaderContender = mock(LeaderContender.class); when(leaderContender.getAddress()).thenReturn(address); LeaderElectionService leaderElectionService = embeddedHaServices.getResourceManagerLeaderElectionService(); LeaderRetrievalService leaderRetrievalService = embeddedHaServices.getResourceManagerLeaderRetriever(); leaderRetrievalService.start(leaderRetrievalListener); leaderElectionService.start(leaderContender); ArgumentCaptor<UUID> leaderIdArgumentCaptor = ArgumentCaptor.forClass(UUID.class); verify(leaderContender).grantLeadership(leaderIdArgumentCaptor.capture()); final UUID leaderId = leaderIdArgumentCaptor.getValue(); leaderElectionService.confirmLeaderSessionID(leaderId); verify(leaderRetrievalListener).notifyLeaderAddress(eq(address), eq(leaderId)); }
Example 4
Source File: EmbeddedHaServicesTest.java From flink with Apache License 2.0 | 6 votes |
/** * Tests that exactly one ResourceManager is elected as the leader. */ @Test public void testResourceManagerLeaderElection() throws Exception { LeaderContender leaderContender1 = mock(LeaderContender.class); LeaderContender leaderContender2 = mock(LeaderContender.class); LeaderElectionService leaderElectionService1 = embeddedHaServices.getResourceManagerLeaderElectionService(); LeaderElectionService leaderElectionService2 = embeddedHaServices.getResourceManagerLeaderElectionService(); leaderElectionService1.start(leaderContender1); leaderElectionService2.start(leaderContender2); 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()); }
Example 5
Source File: EmbeddedHaServicesTest.java From flink with Apache License 2.0 | 6 votes |
/** * Tests that exactly one ResourceManager is elected as the leader. */ @Test public void testResourceManagerLeaderElection() throws Exception { LeaderContender leaderContender1 = mock(LeaderContender.class); LeaderContender leaderContender2 = mock(LeaderContender.class); LeaderElectionService leaderElectionService1 = embeddedHaServices.getResourceManagerLeaderElectionService(); LeaderElectionService leaderElectionService2 = embeddedHaServices.getResourceManagerLeaderElectionService(); leaderElectionService1.start(leaderContender1); leaderElectionService2.start(leaderContender2); 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()); }
Example 6
Source File: YarnIntraNonHaMasterServicesTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testClosingReportsToLeader() throws Exception { final Configuration flinkConfig = new Configuration(); try (YarnHighAvailabilityServices services = new YarnIntraNonHaMasterServices(flinkConfig, hadoopConfig)) { final LeaderElectionService elector = services.getResourceManagerLeaderElectionService(); final LeaderRetrievalService retrieval = services.getResourceManagerLeaderRetriever(); final LeaderContender contender = mockContender(elector); final LeaderRetrievalListener listener = mock(LeaderRetrievalListener.class); elector.start(contender); retrieval.start(listener); // wait until the contender has become the leader verify(listener, timeout(1000L).times(1)).notifyLeaderAddress(anyString(), any(UUID.class)); // now we can close the election service services.close(); verify(contender, timeout(1000L).times(1)).handleError(any(Exception.class)); } }
Example 7
Source File: StandaloneHaServicesTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
/** * Tests that the standalone leader election services return a fixed address and leader session * id. */ @Test public void testLeaderElection() throws Exception { JobID jobId = new JobID(); LeaderContender jmLeaderContender = mock(LeaderContender.class); LeaderContender rmLeaderContender = mock(LeaderContender.class); LeaderElectionService jmLeaderElectionService = standaloneHaServices.getJobManagerLeaderElectionService(jobId); LeaderElectionService rmLeaderElectionService = standaloneHaServices.getResourceManagerLeaderElectionService(); jmLeaderElectionService.start(jmLeaderContender); rmLeaderElectionService.start(rmLeaderContender); verify(jmLeaderContender).grantLeadership(eq(HighAvailabilityServices.DEFAULT_LEADER_ID)); verify(rmLeaderContender).grantLeadership(eq(HighAvailabilityServices.DEFAULT_LEADER_ID)); }
Example 8
Source File: EmbeddedHaServicesTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
/** * Tests the ResourceManager leader retrieval for a given job. */ @Test public void testResourceManagerLeaderRetrieval() throws Exception { final String address = "foobar"; LeaderRetrievalListener leaderRetrievalListener = mock(LeaderRetrievalListener.class); LeaderContender leaderContender = mock(LeaderContender.class); when(leaderContender.getAddress()).thenReturn(address); LeaderElectionService leaderElectionService = embeddedHaServices.getResourceManagerLeaderElectionService(); LeaderRetrievalService leaderRetrievalService = embeddedHaServices.getResourceManagerLeaderRetriever(); leaderRetrievalService.start(leaderRetrievalListener); leaderElectionService.start(leaderContender); ArgumentCaptor<UUID> leaderIdArgumentCaptor = ArgumentCaptor.forClass(UUID.class); verify(leaderContender).grantLeadership(leaderIdArgumentCaptor.capture()); final UUID leaderId = leaderIdArgumentCaptor.getValue(); leaderElectionService.confirmLeaderSessionID(leaderId); verify(leaderRetrievalListener).notifyLeaderAddress(eq(address), eq(leaderId)); }
Example 9
Source File: EmbeddedHaServicesTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
/** * Tests the JobManager leader retrieval for a given job. */ @Test public void testJobManagerLeaderRetrieval() throws Exception { final String address = "foobar"; JobID jobId = new JobID(); LeaderRetrievalListener leaderRetrievalListener = mock(LeaderRetrievalListener.class); LeaderContender leaderContender = mock(LeaderContender.class); when(leaderContender.getAddress()).thenReturn(address); LeaderElectionService leaderElectionService = embeddedHaServices.getJobManagerLeaderElectionService(jobId); LeaderRetrievalService leaderRetrievalService = embeddedHaServices.getJobManagerLeaderRetriever(jobId); leaderRetrievalService.start(leaderRetrievalListener); leaderElectionService.start(leaderContender); ArgumentCaptor<UUID> leaderIdArgumentCaptor = ArgumentCaptor.forClass(UUID.class); verify(leaderContender).grantLeadership(leaderIdArgumentCaptor.capture()); final UUID leaderId = leaderIdArgumentCaptor.getValue(); leaderElectionService.confirmLeaderSessionID(leaderId); verify(leaderRetrievalListener).notifyLeaderAddress(eq(address), eq(leaderId)); }
Example 10
Source File: EmbeddedHaServicesTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
/** * Tests that exactly one ResourceManager is elected as the leader. */ @Test public void testResourceManagerLeaderElection() throws Exception { LeaderContender leaderContender1 = mock(LeaderContender.class); LeaderContender leaderContender2 = mock(LeaderContender.class); LeaderElectionService leaderElectionService1 = embeddedHaServices.getResourceManagerLeaderElectionService(); LeaderElectionService leaderElectionService2 = embeddedHaServices.getResourceManagerLeaderElectionService(); leaderElectionService1.start(leaderContender1); leaderElectionService2.start(leaderContender2); 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()); }
Example 11
Source File: YarnIntraNonHaMasterServicesTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testClosingReportsToLeader() throws Exception { final Configuration flinkConfig = new Configuration(); try (YarnHighAvailabilityServices services = new YarnIntraNonHaMasterServices(flinkConfig, hadoopConfig)) { final LeaderElectionService elector = services.getResourceManagerLeaderElectionService(); final LeaderRetrievalService retrieval = services.getResourceManagerLeaderRetriever(); final LeaderContender contender = mockContender(elector); final LeaderRetrievalListener listener = mock(LeaderRetrievalListener.class); elector.start(contender); retrieval.start(listener); // wait until the contender has become the leader verify(listener, timeout(1000L).times(1)).notifyLeaderAddress(anyString(), any(UUID.class)); // now we can close the election service services.close(); verify(contender, timeout(1000L).times(1)).handleError(any(Exception.class)); } }
Example 12
Source File: EmbeddedLeaderServiceTest.java From flink with Apache License 2.0 | 5 votes |
/** * Tests that the {@link EmbeddedLeaderService} can handle a concurrent revoke * leadership call and a shutdown. */ @Test public void testConcurrentRevokeLeadershipAndShutdown() throws Exception { final EmbeddedLeaderService embeddedLeaderService = new EmbeddedLeaderService(TestingUtils.defaultExecutor()); try { final LeaderElectionService leaderElectionService = embeddedLeaderService.createLeaderElectionService(); final TestingLeaderContender contender = new TestingLeaderContender(); leaderElectionService.start(contender); // wait for the leadership contender.getLeaderSessionFuture().get(); final CompletableFuture<Void> revokeLeadershipFuture = embeddedLeaderService.revokeLeadership(); leaderElectionService.stop(); try { // check that no exception occurred revokeLeadershipFuture.get(10L, TimeUnit.MILLISECONDS); } catch (TimeoutException ignored) { // the leader election service has been stopped before revoking could be executed } // the election service should still be running Assert.assertThat(embeddedLeaderService.isShutdown(), is(false)); } finally { embeddedLeaderService.shutdown(); } }
Example 13
Source File: ZooKeeperHaServicesTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private void runCleanupTest( Configuration configuration, TestingBlobStoreService blobStoreService, ThrowingConsumer<ZooKeeperHaServices, Exception> zooKeeperHaServicesConsumer) throws Exception { try (ZooKeeperHaServices zooKeeperHaServices = new ZooKeeperHaServices( ZooKeeperUtils.startCuratorFramework(configuration), Executors.directExecutor(), configuration, blobStoreService)) { // create some Zk services to trigger the generation of paths final LeaderRetrievalService resourceManagerLeaderRetriever = zooKeeperHaServices.getResourceManagerLeaderRetriever(); final LeaderElectionService resourceManagerLeaderElectionService = zooKeeperHaServices.getResourceManagerLeaderElectionService(); final RunningJobsRegistry runningJobsRegistry = zooKeeperHaServices.getRunningJobsRegistry(); final TestingListener listener = new TestingListener(); resourceManagerLeaderRetriever.start(listener); resourceManagerLeaderElectionService.start(new TestingContender("foobar", resourceManagerLeaderElectionService)); final JobID jobId = new JobID(); runningJobsRegistry.setJobRunning(jobId); listener.waitForNewLeader(2000L); resourceManagerLeaderRetriever.stop(); resourceManagerLeaderElectionService.stop(); runningJobsRegistry.clearJob(jobId); zooKeeperHaServicesConsumer.accept(zooKeeperHaServices); } }
Example 14
Source File: EmbeddedHaServicesTest.java From flink with Apache License 2.0 | 5 votes |
/** * Tests that exactly one JobManager is elected as the leader for a given job id. */ @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)); }
Example 15
Source File: EmbeddedLeaderServiceTest.java From flink with Apache License 2.0 | 5 votes |
/** * Tests that the {@link EmbeddedLeaderService} can handle a concurrent revoke * leadership call and a shutdown. */ @Test public void testConcurrentRevokeLeadershipAndShutdown() throws Exception { final EmbeddedLeaderService embeddedLeaderService = new EmbeddedLeaderService(TestingUtils.defaultExecutor()); try { final LeaderElectionService leaderElectionService = embeddedLeaderService.createLeaderElectionService(); final TestingLeaderContender contender = new TestingLeaderContender(); leaderElectionService.start(contender); // wait for the leadership contender.getLeaderSessionFuture().get(); final CompletableFuture<Void> revokeLeadershipFuture = embeddedLeaderService.revokeLeadership(); leaderElectionService.stop(); try { // check that no exception occurred revokeLeadershipFuture.get(10L, TimeUnit.MILLISECONDS); } catch (TimeoutException ignored) { // the leader election service has been stopped before revoking could be executed } // the election service should still be running Assert.assertThat(embeddedLeaderService.isShutdown(), is(false)); } finally { embeddedLeaderService.shutdown(); } }
Example 16
Source File: EmbeddedHaServicesTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * Tests that exactly one JobManager is elected as the leader for a given job id. */ @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)); }
Example 17
Source File: EmbeddedLeaderServiceTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * Tests that the {@link EmbeddedLeaderService} can handle a concurrent revoke * leadership call and a shutdown. */ @Test public void testConcurrentRevokeLeadershipAndShutdown() throws Exception { final EmbeddedLeaderService embeddedLeaderService = new EmbeddedLeaderService(TestingUtils.defaultExecutor()); try { final LeaderElectionService leaderElectionService = embeddedLeaderService.createLeaderElectionService(); final TestingLeaderContender contender = new TestingLeaderContender(); leaderElectionService.start(contender); // wait for the leadership contender.getLeaderSessionFuture().get(); final CompletableFuture<Void> revokeLeadershipFuture = embeddedLeaderService.revokeLeadership(); leaderElectionService.stop(); try { // check that no exception occurred revokeLeadershipFuture.get(10L, TimeUnit.MILLISECONDS); } catch (TimeoutException ignored) { // the leader election service has been stopped before revoking could be executed } // the election service should still be running Assert.assertThat(embeddedLeaderService.isShutdown(), is(false)); } finally { embeddedLeaderService.shutdown(); } }
Example 18
Source File: ZooKeeperHaServicesTest.java From flink with Apache License 2.0 | 5 votes |
private void runCleanupTest( Configuration configuration, TestingBlobStoreService blobStoreService, ThrowingConsumer<ZooKeeperHaServices, Exception> zooKeeperHaServicesConsumer) throws Exception { try (ZooKeeperHaServices zooKeeperHaServices = new ZooKeeperHaServices( ZooKeeperUtils.startCuratorFramework(configuration), Executors.directExecutor(), configuration, blobStoreService)) { // create some Zk services to trigger the generation of paths final LeaderRetrievalService resourceManagerLeaderRetriever = zooKeeperHaServices.getResourceManagerLeaderRetriever(); final LeaderElectionService resourceManagerLeaderElectionService = zooKeeperHaServices.getResourceManagerLeaderElectionService(); final RunningJobsRegistry runningJobsRegistry = zooKeeperHaServices.getRunningJobsRegistry(); final TestingListener listener = new TestingListener(); resourceManagerLeaderRetriever.start(listener); resourceManagerLeaderElectionService.start(new TestingContender("foobar", resourceManagerLeaderElectionService)); final JobID jobId = new JobID(); runningJobsRegistry.setJobRunning(jobId); listener.waitForNewLeader(2000L); resourceManagerLeaderRetriever.stop(); resourceManagerLeaderElectionService.stop(); runningJobsRegistry.clearJob(jobId); zooKeeperHaServicesConsumer.accept(zooKeeperHaServices); } }
Example 19
Source File: DispatcherRunnerLeaderElectionLifecycleManager.java From flink with Apache License 2.0 | 4 votes |
private DispatcherRunnerLeaderElectionLifecycleManager(T dispatcherRunner, LeaderElectionService leaderElectionService) throws Exception { this.dispatcherRunner = dispatcherRunner; this.leaderElectionService = leaderElectionService; leaderElectionService.start(dispatcherRunner); }
Example 20
Source File: EmbeddedHaServicesTest.java From flink with Apache License 2.0 | 3 votes |
/** * Tests that concurrent leadership operations (granting and revoking) leadership leave the * system in a sane state. */ @Test public void testConcurrentLeadershipOperations() throws Exception { final LeaderElectionService dispatcherLeaderElectionService = embeddedHaServices.getDispatcherLeaderElectionService(); final TestingLeaderContender leaderContender = new TestingLeaderContender(); dispatcherLeaderElectionService.start(leaderContender); final UUID oldLeaderSessionId = leaderContender.getLeaderSessionFuture().get(); assertThat(dispatcherLeaderElectionService.hasLeadership(oldLeaderSessionId), is(true)); embeddedHaServices.getDispatcherLeaderService().revokeLeadership().get(); assertThat(dispatcherLeaderElectionService.hasLeadership(oldLeaderSessionId), is(false)); embeddedHaServices.getDispatcherLeaderService().grantLeadership(); final UUID newLeaderSessionId = leaderContender.getLeaderSessionFuture().get(); assertThat(dispatcherLeaderElectionService.hasLeadership(newLeaderSessionId), is(true)); dispatcherLeaderElectionService.confirmLeaderSessionID(oldLeaderSessionId); dispatcherLeaderElectionService.confirmLeaderSessionID(newLeaderSessionId); assertThat(dispatcherLeaderElectionService.hasLeadership(newLeaderSessionId), is(true)); leaderContender.tryRethrowException(); }