Java Code Examples for org.apache.flink.runtime.testutils.CommonTestUtils#waitUntilCondition()

The following examples show how to use org.apache.flink.runtime.testutils.CommonTestUtils#waitUntilCondition() . 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: TaskExecutorITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private CompletableFuture<JobResult> submitJobAndWaitUntilRunning(JobGraph jobGraph) throws Exception {
	miniCluster.submitJob(jobGraph).get();

	final CompletableFuture<JobResult> jobResultFuture = miniCluster.requestJobResult(jobGraph.getJobID());

	assertThat(jobResultFuture.isDone(), is(false));

	CommonTestUtils.waitUntilCondition(
		jobIsRunning(() -> miniCluster.getExecutionGraph(jobGraph.getJobID())),
		Deadline.fromNow(TESTING_TIMEOUT),
		50L);

	return jobResultFuture;
}
 
Example 2
Source File: TaskExecutorITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
private CompletableFuture<JobResult> submitJobAndWaitUntilRunning(JobGraph jobGraph) throws Exception {
	miniCluster.submitJob(jobGraph).get();

	final CompletableFuture<JobResult> jobResultFuture = miniCluster.requestJobResult(jobGraph.getJobID());

	assertThat(jobResultFuture.isDone(), is(false));

	CommonTestUtils.waitUntilCondition(
		jobIsRunning(() -> miniCluster.getExecutionGraph(jobGraph.getJobID())),
		Deadline.fromNow(TESTING_TIMEOUT),
		50L);

	return jobResultFuture;
}
 
Example 3
Source File: YARNHighAvailabilityITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
private static void waitUntilJobIsRestarted(
	final RestClusterClient<ApplicationId> restClusterClient,
	final JobID jobId,
	final int expectedFullRestarts) throws Exception {
	CommonTestUtils.waitUntilCondition(
		() -> getJobFullRestarts(restClusterClient, jobId) >= expectedFullRestarts,
		Deadline.fromNow(TIMEOUT));
}
 
Example 4
Source File: YARNHighAvailabilityITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
private static void waitUntilJobIsRunning(RestClusterClient<ApplicationId> restClusterClient, JobID jobId) throws Exception {
	CommonTestUtils.waitUntilCondition(
		() -> {
			final JobDetailsInfo jobDetails = restClusterClient.getJobDetails(jobId).get();
			return jobDetails.getJobVertexInfos()
				.stream()
				.map(toExecutionState())
				.allMatch(isRunning());
		},
		Deadline.fromNow(TIMEOUT));
}
 
Example 5
Source File: YARNHighAvailabilityITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
private void killApplicationAndWait(final ApplicationId id) throws Exception {
	final YarnClient yarnClient = getYarnClient();
	checkState(yarnClient != null, "yarnClient must be initialized");

	yarnClient.killApplication(id);

	CommonTestUtils.waitUntilCondition(() -> !yarnClient.getApplications(EnumSet.of(YarnApplicationState.KILLED, YarnApplicationState.FINISHED)).isEmpty(),
		Deadline.fromNow(TIMEOUT));
}
 
Example 6
Source File: YARNHighAvailabilityITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
private void waitForApplicationAttempt(final ApplicationId applicationId, final int attemptId) throws Exception {
	final YarnClient yarnClient = getYarnClient();
	checkState(yarnClient != null, "yarnClient must be initialized");

	CommonTestUtils.waitUntilCondition(() -> {
		final ApplicationReport applicationReport = yarnClient.getApplicationReport(applicationId);
		return applicationReport.getCurrentApplicationAttemptId().getAttemptId() >= attemptId;
	}, Deadline.fromNow(TIMEOUT));
}
 
Example 7
Source File: YARNSessionCapacitySchedulerITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
private static void assertNumberOfSlotsPerTask(
		final String host,
		final int port,
		final int slotsNumber) throws Exception {
	try {
		CommonTestUtils.waitUntilCondition(() -> getNumberOfSlotsPerTaskManager(host, port) == slotsNumber, Deadline.fromNow(Duration.ofSeconds(30)));
	} catch (final TimeoutException e) {
		final int currentNumberOfSlots = getNumberOfSlotsPerTaskManager(host, port);
		fail(String.format("Expected slots per TM to be %d, was: %d", slotsNumber, currentNumberOfSlots));
	}
}
 
Example 8
Source File: JobMasterTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private void waitUntilAllExecutionsAreScheduled(final JobMasterGateway jobMasterGateway) throws Exception {
	final Duration duration = Duration.ofMillis(testingTimeout.toMilliseconds());
	final Deadline deadline = Deadline.fromNow(duration);

	CommonTestUtils.waitUntilCondition(
		() -> getExecutions(jobMasterGateway).stream().allMatch(execution -> execution.getState() == ExecutionState.SCHEDULED),
		deadline);
}
 
Example 9
Source File: YARNHighAvailabilityITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
private static void waitUntilJobIsRunning(RestClusterClient<ApplicationId> restClusterClient, JobID jobId) throws Exception {
	CommonTestUtils.waitUntilCondition(
		() -> {
			final JobDetailsInfo jobDetails = restClusterClient.getJobDetails(jobId).get();
			return jobDetails.getJobVertexInfos()
				.stream()
				.map(toExecutionState())
				.allMatch(isRunning());
		},
		Deadline.fromNow(TIMEOUT));
}
 
Example 10
Source File: YARNHighAvailabilityITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
private void waitForApplicationAttempt(final ApplicationId applicationId, final int attemptId) throws Exception {
	final YarnClient yarnClient = getYarnClient();
	checkState(yarnClient != null, "yarnClient must be initialized");

	CommonTestUtils.waitUntilCondition(() -> {
		final ApplicationReport applicationReport = yarnClient.getApplicationReport(applicationId);
		return applicationReport.getCurrentApplicationAttemptId().getAttemptId() >= attemptId;
	}, Deadline.fromNow(TIMEOUT));
}
 
Example 11
Source File: YARNHighAvailabilityITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private static void waitUntilJobIsRestarted(
	final RestClusterClient<ApplicationId> restClusterClient,
	final JobID jobId,
	final int expectedFullRestarts) throws Exception {
	CommonTestUtils.waitUntilCondition(
		() -> getJobFullRestarts(restClusterClient, jobId) >= expectedFullRestarts,
		Deadline.fromNow(TIMEOUT));
}
 
Example 12
Source File: YARNHighAvailabilityITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private static void waitUntilJobIsRunning(RestClusterClient<ApplicationId> restClusterClient, JobID jobId) throws Exception {
	CommonTestUtils.waitUntilCondition(
		() -> {
			final JobDetailsInfo jobDetails = restClusterClient.getJobDetails(jobId).get();
			return jobDetails.getJobVertexInfos()
				.stream()
				.map(toExecutionState())
				.allMatch(isRunning());
		},
		Deadline.fromNow(TIMEOUT));
}
 
Example 13
Source File: YARNHighAvailabilityITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private void killApplicationAndWait(final ApplicationId id) throws Exception {
	final YarnClient yarnClient = getYarnClient();
	checkState(yarnClient != null, "yarnClient must be initialized");

	yarnClient.killApplication(id);

	CommonTestUtils.waitUntilCondition(() -> !yarnClient.getApplications(EnumSet.of(YarnApplicationState.KILLED, YarnApplicationState.FINISHED)).isEmpty(),
		Deadline.fromNow(TIMEOUT));
}
 
Example 14
Source File: YARNHighAvailabilityITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
private void killApplicationAndWait(final ApplicationId id) throws Exception {
	final YarnClient yarnClient = getYarnClient();
	checkState(yarnClient != null, "yarnClient must be initialized");

	yarnClient.killApplication(id);

	CommonTestUtils.waitUntilCondition(() -> !yarnClient.getApplications(EnumSet.of(YarnApplicationState.KILLED, YarnApplicationState.FINISHED)).isEmpty(),
		Deadline.fromNow(TIMEOUT));
}
 
Example 15
Source File: BackPressureStatsTrackerImplITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private void waitUntilBackPressureStatsAvailable() {
	try {
		CommonTestUtils.waitUntilCondition(
			() -> {
				final Optional<OperatorBackPressureStats> stats = getBackPressureStats();
				return stats.isPresent();
				},
			Deadline.fromNow(TIMEOUT));
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
Example 16
Source File: LeaderChangeClusterComponentsTest.java    From flink with Apache License 2.0 4 votes vote down vote up
private void waitUntilTaskExecutorsHaveConnected(int numTaskExecutors, Deadline deadline) throws Exception {
	CommonTestUtils.waitUntilCondition(
		() -> miniCluster.requestClusterOverview().get().getNumTaskManagersConnected() == numTaskExecutors,
		deadline,
		10L);
}
 
Example 17
Source File: YARNSessionCapacitySchedulerITCase.java    From flink with Apache License 2.0 4 votes vote down vote up
private static void waitForTaskManagerRegistration(
		final String host,
		final int port,
		final Duration waitDuration) throws Exception {
	CommonTestUtils.waitUntilCondition(() -> getNumberOfTaskManagers(host, port) > 0, Deadline.fromNow(waitDuration));
}
 
Example 18
Source File: LeaderChangeClusterComponentsTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
private void waitUntilTaskExecutorsHaveConnected(int numTaskExecutors, Deadline deadline) throws Exception {
	CommonTestUtils.waitUntilCondition(
		() -> miniCluster.requestClusterOverview().get().getNumTaskManagersConnected() == numTaskExecutors,
		deadline,
		10L);
}
 
Example 19
Source File: LeaderChangeClusterComponentsTest.java    From flink with Apache License 2.0 4 votes vote down vote up
private void waitUntilTaskExecutorsHaveConnected(int numTaskExecutors, Deadline deadline) throws Exception {
	CommonTestUtils.waitUntilCondition(
		() -> miniCluster.requestClusterOverview().get().getNumTaskManagersConnected() == numTaskExecutors,
		deadline,
		10L);
}
 
Example 20
Source File: CliTableauResultViewTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testCancelStreamingResult() throws Exception {
	ResultDescriptor resultDescriptor = new ResultDescriptor("", schema, true, true);

	TestingExecutor mockExecutor = new TestingExecutorBuilder()
		.setResultChangesSupplier(
			() -> TypedResult.payload(streamingData.subList(0, streamingData.size() / 2)),
			TypedResult::empty)
		.build();

	CliTableauResultView view = new CliTableauResultView(
			terminal, mockExecutor, "session", resultDescriptor);

	// submit result display in another thread
	ExecutorService executorService = Executors.newSingleThreadExecutor();
	Future<?> furture = executorService.submit(view::displayStreamResults);

	// wait until we processed first result
	CommonTestUtils.waitUntilCondition(
		() -> mockExecutor.getNumRetrieveResultChancesCalls() > 1,
		Deadline.now().plus(Duration.ofSeconds(5)),
		50L);

	// send signal to cancel
	terminal.raise(Terminal.Signal.INT);
	furture.get(5, TimeUnit.SECONDS);
	view.close();

	Assert.assertEquals(
			"+-----+---------+-------------+----------------------+----------------------+----------------+----------------------------+" + System.lineSeparator() +
			"| +/- | boolean |         int |               bigint |              varchar | decimal(10, 5) |                  timestamp |" + System.lineSeparator() +
			"+-----+---------+-------------+----------------------+----------------------+----------------+----------------------------+" + System.lineSeparator() +
			"|   + |  (NULL) |           1 |                    2 |                  abc |           1.23 |      2020-03-01 18:39:14.0 |" + System.lineSeparator() +
			"|   - |   false |      (NULL) |                    0 |                      |              1 |      2020-03-01 18:39:14.1 |" + System.lineSeparator() +
			"|   + |    true |  2147483647 |               (NULL) |              abcdefg |     1234567890 |     2020-03-01 18:39:14.12 |" + System.lineSeparator() +
			"|   - |   false | -2147483648 |  9223372036854775807 |               (NULL) |    12345.06789 |    2020-03-01 18:39:14.123 |" + System.lineSeparator() +
			"Query terminated, received a total of 4 rows" + System.lineSeparator(),
			terminalOutput.toString());

	assertThat(mockExecutor.getNumCancelCalls(), is(1));
}