org.apache.flink.runtime.leaderelection.TestingListener Java Examples

The following examples show how to use org.apache.flink.runtime.leaderelection.TestingListener. 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: SettableLeaderRetrievalServiceTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testNotifyListenerLater() throws Exception {
	final String localhost = "localhost";
	settableLeaderRetrievalService.notifyListener(localhost, HighAvailabilityServices.DEFAULT_LEADER_ID);

	final TestingListener listener = new TestingListener();
	settableLeaderRetrievalService.start(listener);

	assertThat(listener.getAddress(), equalTo(localhost));
	assertThat(listener.getLeaderSessionID(), equalTo(HighAvailabilityServices.DEFAULT_LEADER_ID));
}
 
Example #2
Source File: SettableLeaderRetrievalServiceTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testNotifyListenerImmediately() throws Exception {
	final TestingListener listener = new TestingListener();
	settableLeaderRetrievalService.start(listener);

	final String localhost = "localhost";
	settableLeaderRetrievalService.notifyListener(localhost, HighAvailabilityServices.DEFAULT_LEADER_ID);

	assertThat(listener.getAddress(), equalTo(localhost));
	assertThat(listener.getLeaderSessionID(), equalTo(HighAvailabilityServices.DEFAULT_LEADER_ID));
}
 
Example #3
Source File: ZooKeeperHaServicesTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
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 #4
Source File: SettableLeaderRetrievalServiceTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testNotifyListenerLater() throws Exception {
	final String localhost = "localhost";
	settableLeaderRetrievalService.notifyListener(localhost, HighAvailabilityServices.DEFAULT_LEADER_ID);

	final TestingListener listener = new TestingListener();
	settableLeaderRetrievalService.start(listener);

	assertThat(listener.getAddress(), equalTo(localhost));
	assertThat(listener.getLeaderSessionID(), equalTo(HighAvailabilityServices.DEFAULT_LEADER_ID));
}
 
Example #5
Source File: SettableLeaderRetrievalServiceTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testNotifyListenerImmediately() throws Exception {
	final TestingListener listener = new TestingListener();
	settableLeaderRetrievalService.start(listener);

	final String localhost = "localhost";
	settableLeaderRetrievalService.notifyListener(localhost, HighAvailabilityServices.DEFAULT_LEADER_ID);

	assertThat(listener.getAddress(), equalTo(localhost));
	assertThat(listener.getLeaderSessionID(), equalTo(HighAvailabilityServices.DEFAULT_LEADER_ID));
}
 
Example #6
Source File: ZooKeeperHaServicesTest.java    From flink with Apache License 2.0 5 votes vote down vote up
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 #7
Source File: SettableLeaderRetrievalServiceTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testNotifyListenerLater() throws Exception {
	final String localhost = "localhost";
	settableLeaderRetrievalService.notifyListener(localhost, HighAvailabilityServices.DEFAULT_LEADER_ID);

	final TestingListener listener = new TestingListener();
	settableLeaderRetrievalService.start(listener);

	assertThat(listener.getAddress(), equalTo(localhost));
	assertThat(listener.getLeaderSessionID(), equalTo(HighAvailabilityServices.DEFAULT_LEADER_ID));
}
 
Example #8
Source File: SettableLeaderRetrievalServiceTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testNotifyListenerImmediately() throws Exception {
	final TestingListener listener = new TestingListener();
	settableLeaderRetrievalService.start(listener);

	final String localhost = "localhost";
	settableLeaderRetrievalService.notifyListener(localhost, HighAvailabilityServices.DEFAULT_LEADER_ID);

	assertThat(listener.getAddress(), equalTo(localhost));
	assertThat(listener.getLeaderSessionID(), equalTo(HighAvailabilityServices.DEFAULT_LEADER_ID));
}
 
Example #9
Source File: ZooKeeperHaServicesTest.java    From flink with Apache License 2.0 5 votes vote down vote up
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);
	}
}