Java Code Examples for org.apache.flink.runtime.leaderelection.LeaderElectionService#stop()
The following examples show how to use
org.apache.flink.runtime.leaderelection.LeaderElectionService#stop() .
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: EmbeddedLeaderServiceTest.java From flink 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 3
Source File: EmbeddedLeaderServiceTest.java From flink 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 4
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 5
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 6
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 7
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 8
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 9
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); } }