org.apache.flink.runtime.heartbeat.TestingHeartbeatServices Java Examples

The following examples show how to use org.apache.flink.runtime.heartbeat.TestingHeartbeatServices. 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: YarnResourceManagerTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
MockResourceManagerRuntimeServices() throws Exception {
	highAvailabilityServices = new TestingHighAvailabilityServices();
	rmLeaderElectionService = new TestingLeaderElectionService();
	highAvailabilityServices.setResourceManagerLeaderElectionService(rmLeaderElectionService);
	heartbeatServices = new TestingHeartbeatServices();
	metricRegistry = NoOpMetricRegistry.INSTANCE;
	slotManager = SlotManagerBuilder.newBuilder()
		.setScheduledExecutor(new ScheduledExecutorServiceAdapter(new DirectScheduledExecutorService()))
		.setTaskManagerRequestTimeout(Time.seconds(10))
		.setSlotRequestTimeout(Time.seconds(10))
		.setTaskManagerTimeout(Time.minutes(1))
		.build();
	jobLeaderIdService = new JobLeaderIdService(
			highAvailabilityServices,
			rpcService.getScheduledExecutor(),
			Time.minutes(5L));
}
 
Example #2
Source File: StandaloneResourceManagerFactoryTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void createResourceManager_WithLessMemoryThanContainerizedHeapCutoffMin_ShouldSucceed() throws Exception {
	final StandaloneResourceManagerFactory resourceManagerFactory = StandaloneResourceManagerFactory.INSTANCE;

	final TestingRpcService rpcService = new TestingRpcService();
	try {
		final Configuration configuration = new Configuration();
		configuration.setString(TaskManagerOptions.TASK_MANAGER_HEAP_MEMORY, new MemorySize(128 * 1024 * 1024).toString());
		configuration.setInteger(ResourceManagerOptions.CONTAINERIZED_HEAP_CUTOFF_MIN, 600);

		final ResourceManager<ResourceID> ignored = resourceManagerFactory.createResourceManager(
			configuration,
			ResourceID.generate(),
			rpcService,
			new TestingHighAvailabilityServices(),
			new TestingHeartbeatServices(),
			NoOpMetricRegistry.INSTANCE,
			new TestingFatalErrorHandler(),
			new ClusterInformation("foobar", 1234),
			null,
			UnregisteredMetricGroups.createUnregisteredJobManagerMetricGroup());
	} finally {
		RpcUtils.terminateRpcService(rpcService, Time.seconds(10L));
	}
}
 
Example #3
Source File: ActiveResourceManagerFactoryTest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Test which ensures that the {@link ActiveResourceManagerFactory} sets the correct managed
 * memory when creating a resource manager.
 */
@Test
public void createResourceManager_WithDefaultConfiguration_ShouldSetManagedMemory() throws Exception {
	final Configuration configuration = new Configuration();

	final TestingActiveResourceManagerFactory resourceManagerFactory = new TestingActiveResourceManagerFactory();

	final TestingRpcService rpcService = new TestingRpcService();

	try {
		final ResourceManager<ResourceID> ignored = resourceManagerFactory.createResourceManager(
			configuration,
			ResourceID.generate(),
			rpcService,
			new TestingHighAvailabilityServices(),
			new TestingHeartbeatServices(),
			NoOpMetricRegistry.INSTANCE,
			new TestingFatalErrorHandler(),
			new ClusterInformation("foobar", 1234),
			null,
			UnregisteredMetricGroups.createUnregisteredJobManagerMetricGroup());
	} finally {
		RpcUtils.terminateRpcService(rpcService, Time.seconds(10L));
	}
}
 
Example #4
Source File: DefaultDispatcherRunnerITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
	dispatcherRunnerFactory = DefaultDispatcherRunnerFactory.createSessionRunner(SessionDispatcherFactory.INSTANCE);
	jobGraph = createJobGraph();
	dispatcherLeaderElectionService = new TestingLeaderElectionService();
	fatalErrorHandler = new TestingFatalErrorHandler();
	jobGraphStore = TestingJobGraphStore.newBuilder().build();

	partialDispatcherServices = new PartialDispatcherServices(
		new Configuration(),
		new TestingHighAvailabilityServicesBuilder().build(),
		CompletableFuture::new,
		blobServerResource.getBlobServer(),
		new TestingHeartbeatServices(),
		UnregisteredMetricGroups::createUnregisteredJobManagerMetricGroup,
		new MemoryArchivedExecutionGraphStore(),
		fatalErrorHandler,
		VoidHistoryServerArchivist.INSTANCE,
		null);
}
 
Example #5
Source File: TaskExecutorSlotLifetimeTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private TaskExecutor createTaskExecutor(Configuration configuration, TestingRpcService rpcService, TestingHighAvailabilityServices haServices, LocalUnresolvedTaskManagerLocation unresolvedTaskManagerLocation) throws IOException {
	return new TaskExecutor(
		rpcService,
		TaskManagerConfiguration.fromConfiguration(
			configuration,
			TaskExecutorResourceUtils.resourceSpecFromConfigForLocalExecution(configuration),
			InetAddress.getLoopbackAddress().getHostAddress()),
		haServices,
		new TaskManagerServicesBuilder()
			.setTaskSlotTable(TaskSlotUtils.createTaskSlotTable(1))
			.setUnresolvedTaskManagerLocation(unresolvedTaskManagerLocation)
			.build(),
		ExternalResourceInfoProvider.NO_EXTERNAL_RESOURCES,
		new TestingHeartbeatServices(),
		UnregisteredMetricGroups.createUnregisteredTaskManagerMetricGroup(),
		null,
		new BlobCacheService(
			configuration,
			new VoidBlobStore(),
			null),
		testingFatalErrorHandlerResource.getFatalErrorHandler(),
		new TestingTaskExecutorPartitionTracker(),
		TaskManagerRunner.createBackPressureSampleService(configuration, rpcService.getScheduledExecutor()));
}
 
Example #6
Source File: TaskManagerRunnerStartupTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private static void startTaskManager(
	Configuration configuration,
	RpcService rpcService,
	HighAvailabilityServices highAvailabilityServices
) throws Exception {

	TaskManagerRunner.startTaskManager(
		configuration,
		ResourceID.generate(),
		rpcService,
		highAvailabilityServices,
		new TestingHeartbeatServices(),
		NoOpMetricRegistry.INSTANCE,
		new BlobCacheService(
			configuration,
			new VoidBlobStore(),
			null),
		false,
		ExternalResourceInfoProvider.NO_EXTERNAL_RESOURCES,
		error -> {});
}
 
Example #7
Source File: MockResourceManagerRuntimeServices.java    From flink with Apache License 2.0 5 votes vote down vote up
public MockResourceManagerRuntimeServices(RpcService rpcService, Time timeout, SlotManager slotManager) {
	this.rpcService = checkNotNull(rpcService);
	this.timeout = checkNotNull(timeout);
	this.slotManager = slotManager;
	highAvailabilityServices = new TestingHighAvailabilityServices();
	rmLeaderElectionService = new TestingLeaderElectionService();
	highAvailabilityServices.setResourceManagerLeaderElectionService(rmLeaderElectionService);
	heartbeatServices = new TestingHeartbeatServices();
	metricRegistry = NoOpMetricRegistry.INSTANCE;
	jobLeaderIdService = new JobLeaderIdService(
		highAvailabilityServices,
		rpcService.getScheduledExecutor(),
		Time.minutes(5L));
}
 
Example #8
Source File: JobMasterTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testJobFailureWhenTaskExecutorHeartbeatTimeout() throws Exception {
	final TestingHeartbeatServices testingHeartbeatService = new TestingHeartbeatServices(heartbeatInterval, heartbeatTimeout);

	runJobFailureWhenTaskExecutorTerminatesTest(
		testingHeartbeatService,
		(localTaskManagerLocation, jobMasterGateway) ->
			testingHeartbeatService.triggerHeartbeatTimeout(
				jmResourceId,
				localTaskManagerLocation.getResourceID()),
		(jobMasterGateway, taskManagerResourceId) -> (resourceId, ignored) -> {
			jobMasterGateway.heartbeatFromTaskManager(taskManagerResourceId, new AccumulatorReport(Collections.emptyList()));
		}
	);
}
 
Example #9
Source File: MockResourceManagerRuntimeServices.java    From flink with Apache License 2.0 5 votes vote down vote up
public MockResourceManagerRuntimeServices(RpcService rpcService, Time timeout, SlotManager slotManager) {
	this.rpcService = checkNotNull(rpcService);
	this.timeout = checkNotNull(timeout);
	this.slotManager = slotManager;
	highAvailabilityServices = new TestingHighAvailabilityServices();
	rmLeaderElectionService = new TestingLeaderElectionService();
	highAvailabilityServices.setResourceManagerLeaderElectionService(rmLeaderElectionService);
	heartbeatServices = new TestingHeartbeatServices();
	jobLeaderIdService = new JobLeaderIdService(
		highAvailabilityServices,
		rpcService.getScheduledExecutor(),
		Time.minutes(5L));
}
 
Example #10
Source File: ZooKeeperDefaultDispatcherRunnerTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * See FLINK-11665.
 */
@Test
public void testResourceCleanupUnderLeadershipChange() throws Exception {
	final TestingRpcService rpcService = testingRpcServiceResource.getTestingRpcService();
	final TestingLeaderElectionService dispatcherLeaderElectionService = new TestingLeaderElectionService();

	final CuratorFramework client = ZooKeeperUtils.startCuratorFramework(configuration);
	try (final TestingHighAvailabilityServices highAvailabilityServices = new TestingHighAvailabilityServicesBuilder()
			.setRunningJobsRegistry(new ZooKeeperRunningJobsRegistry(client, configuration))
			.setDispatcherLeaderElectionService(dispatcherLeaderElectionService)
			.setJobMasterLeaderRetrieverFunction(jobId -> ZooKeeperUtils.createLeaderRetrievalService(client, configuration))
			.build()) {

		final PartialDispatcherServices partialDispatcherServices = new PartialDispatcherServices(
			configuration,
			highAvailabilityServices,
			CompletableFuture::new,
			blobServer,
			new TestingHeartbeatServices(),
			UnregisteredMetricGroups::createUnregisteredJobManagerMetricGroup,
			new MemoryArchivedExecutionGraphStore(),
			fatalErrorHandler,
			VoidHistoryServerArchivist.INSTANCE,
			null);

		final JobGraph jobGraph = createJobGraphWithBlobs();

		final DefaultDispatcherRunnerFactory defaultDispatcherRunnerFactory = DefaultDispatcherRunnerFactory.createSessionRunner(SessionDispatcherFactory.INSTANCE);

		try (final DispatcherRunner dispatcherRunner = createDispatcherRunner(
			rpcService,
			dispatcherLeaderElectionService,
			() -> createZooKeeperJobGraphStore(client),
			partialDispatcherServices,
			defaultDispatcherRunnerFactory)) {

			// initial run
			DispatcherGateway dispatcherGateway = grantLeadership(dispatcherLeaderElectionService);

			LOG.info("Initial job submission {}.", jobGraph.getJobID());
			dispatcherGateway.submitJob(jobGraph, TESTING_TIMEOUT).get();

			dispatcherLeaderElectionService.notLeader();

			// recovering submitted jobs
			LOG.info("Re-grant leadership first time.");
			dispatcherGateway = grantLeadership(dispatcherLeaderElectionService);

			LOG.info("Cancel recovered job {}.", jobGraph.getJobID());
			// cancellation of the job should remove everything
			final CompletableFuture<JobResult> jobResultFuture = dispatcherGateway.requestJobResult(jobGraph.getJobID(), TESTING_TIMEOUT);
			dispatcherGateway.cancelJob(jobGraph.getJobID(), TESTING_TIMEOUT).get();

			// a successful cancellation should eventually remove all job information
			final JobResult jobResult = jobResultFuture.get();

			assertThat(jobResult.getApplicationStatus(), is(ApplicationStatus.CANCELED));

			dispatcherLeaderElectionService.notLeader();

			// check that the job has been removed from ZooKeeper
			final ZooKeeperJobGraphStore submittedJobGraphStore = createZooKeeperJobGraphStore(client);

			CommonTestUtils.waitUntilCondition(() -> submittedJobGraphStore.getJobIds().isEmpty(), Deadline.fromNow(VERIFICATION_TIMEOUT), 20L);
		}
	}

	// check resource clean up
	assertThat(clusterHaStorageDir.listFiles(), is(emptyArray()));
}