org.apache.flink.runtime.webmonitor.TestingRestfulGateway Java Examples

The following examples show how to use org.apache.flink.runtime.webmonitor.TestingRestfulGateway. 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: AbstractAsynchronousOperationHandlersTest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that an querying an unknown trigger id will return an exceptionally completed
 * future.
 */
@Test
public void testUnknownTriggerId() throws Exception {
	final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder().build();

	try {
		testingStatusHandler.handleRequest(
			statusOperationRequest(new TriggerId()),
			testingRestfulGateway).get();

		fail("This should have failed with a RestHandlerException.");
	} catch (ExecutionException ee) {
		final Optional<RestHandlerException> optionalRestHandlerException = ExceptionUtils.findThrowable(ee, RestHandlerException.class);

		assertThat(optionalRestHandlerException.isPresent(), is(true));

		final RestHandlerException restHandlerException = optionalRestHandlerException.get();

		assertThat(restHandlerException.getMessage(), containsString("Operation not found"));
		assertThat(restHandlerException.getHttpResponseStatus(), is(HttpResponseStatus.NOT_FOUND));
	}
}
 
Example #2
Source File: AbstractAsynchronousOperationHandlersTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that an querying an unknown trigger id will return an exceptionally completed
 * future.
 */
@Test
public void testUnknownTriggerId() throws Exception {
	final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder().build();

	try {
		testingStatusHandler.handleRequest(
			statusOperationRequest(new TriggerId()),
			testingRestfulGateway).get();

		fail("This should have failed with a RestHandlerException.");
	} catch (ExecutionException ee) {
		final Optional<RestHandlerException> optionalRestHandlerException = ExceptionUtils.findThrowable(ee, RestHandlerException.class);

		assertThat(optionalRestHandlerException.isPresent(), is(true));

		final RestHandlerException restHandlerException = optionalRestHandlerException.get();

		assertThat(restHandlerException.getMessage(), containsString("Operation not found"));
		assertThat(restHandlerException.getHttpResponseStatus(), is(HttpResponseStatus.NOT_FOUND));
	}
}
 
Example #3
Source File: SavepointHandlersTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testTriggerSavepointWithDefaultDirectory() throws Exception {
	final CompletableFuture<String> targetDirectoryFuture = new CompletableFuture<>();
	final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
		.setTriggerSavepointFunction(
			(JobID jobId, String targetDirectory) -> {
				targetDirectoryFuture.complete(targetDirectory);
				return CompletableFuture.completedFuture(COMPLETED_SAVEPOINT_EXTERNAL_POINTER);
			})
		.build();
	final String defaultSavepointDir = "/other/dir";
	final SavepointHandlers savepointHandlers = new SavepointHandlers(defaultSavepointDir);
	final SavepointHandlers.SavepointTriggerHandler savepointTriggerHandler = savepointHandlers.new SavepointTriggerHandler(
		leaderRetriever,
		TIMEOUT,
		Collections.emptyMap());

	savepointTriggerHandler.handleRequest(
		triggerSavepointRequestWithDefaultDirectory(),
		testingRestfulGateway).get();

	assertThat(targetDirectoryFuture.get(), equalTo(defaultSavepointDir));
}
 
Example #4
Source File: JobVertexBackPressureHandlerTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
	restfulGateway = TestingRestfulGateway.newBuilder().setRequestOperatorBackPressureStatsFunction(
		(jobId, jobVertexId) -> {
			if (jobId.equals(TEST_JOB_ID_BACK_PRESSURE_STATS_AVAILABLE)) {
				return CompletableFuture.completedFuture(OperatorBackPressureStatsResponse.of(new OperatorBackPressureStats(
					4711,
					Integer.MAX_VALUE,
					new double[]{1.0, 0.5, 0.1}
				)));
			} else if (jobId.equals(TEST_JOB_ID_BACK_PRESSURE_STATS_ABSENT)) {
				return CompletableFuture.completedFuture(OperatorBackPressureStatsResponse.of(null));
			} else {
				throw new AssertionError();
			}
		}
	).build();
	jobVertexBackPressureHandler = new JobVertexBackPressureHandler(
		() -> CompletableFuture.completedFuture(restfulGateway),
		Time.seconds(10),
		Collections.emptyMap(),
		JobVertexBackPressureHeaders.getInstance()
	);
}
 
Example #5
Source File: SavepointHandlersTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testSavepointCompletedSuccessfully() throws Exception {
	final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
		.setTriggerSavepointFunction((JobID jobId, String targetDirectory) -> CompletableFuture.completedFuture(COMPLETED_SAVEPOINT_EXTERNAL_POINTER))
		.build();

	final TriggerId triggerId = savepointTriggerHandler.handleRequest(
		triggerSavepointRequest(),
		testingRestfulGateway).get().getTriggerId();

	AsynchronousOperationResult<SavepointInfo> savepointResponseBody;
	savepointResponseBody = savepointStatusHandler.handleRequest(
		savepointStatusRequest(triggerId),
		testingRestfulGateway).get();

	assertThat(
		savepointResponseBody.queueStatus().getId(),
		equalTo(QueueStatus.Id.COMPLETED));
	assertThat(savepointResponseBody.resource(), notNullValue());
	assertThat(
		savepointResponseBody.resource().getLocation(),
		equalTo(COMPLETED_SAVEPOINT_EXTERNAL_POINTER));
}
 
Example #6
Source File: JobExecutionResultHandlerTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testPropagateFlinkJobNotFoundExceptionAsRestHandlerException() throws Exception {
	final TestingRestfulGateway testingRestfulGateway = TestingRestfulGateway.newBuilder()
		.setRequestJobStatusFunction(
			jobId -> FutureUtils.completedExceptionally(new FlinkJobNotFoundException(jobId))
		)
		.build();

	try {
		jobExecutionResultHandler.handleRequest(
			testRequest,
			testingRestfulGateway).get();
		fail("Expected exception not thrown");
	} catch (final ExecutionException e) {
		final Throwable cause = ExceptionUtils.stripCompletionException(e.getCause());
		assertThat(cause, instanceOf(RestHandlerException.class));
		assertThat(
			((RestHandlerException) cause).getHttpResponseStatus(),
			equalTo(HttpResponseStatus.NOT_FOUND));
	}
}
 
Example #7
Source File: JobVertexBackPressureHandlerTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
	restfulGateway = TestingRestfulGateway.newBuilder().setRequestOperatorBackPressureStatsFunction(
		(jobId, jobVertexId) -> {
			if (jobId.equals(TEST_JOB_ID_BACK_PRESSURE_STATS_AVAILABLE)) {
				return CompletableFuture.completedFuture(OperatorBackPressureStatsResponse.of(new OperatorBackPressureStats(
					4711,
					Integer.MAX_VALUE,
					new double[]{1.0, 0.5, 0.1}
				)));
			} else if (jobId.equals(TEST_JOB_ID_BACK_PRESSURE_STATS_ABSENT)) {
				return CompletableFuture.completedFuture(OperatorBackPressureStatsResponse.of(null));
			} else {
				throw new AssertionError();
			}
		}
	).build();
	jobVertexBackPressureHandler = new JobVertexBackPressureHandler(
		() -> CompletableFuture.completedFuture(restfulGateway),
		Time.seconds(10),
		Collections.emptyMap(),
		JobVertexBackPressureHeaders.getInstance()
	);
}
 
Example #8
Source File: SavepointHandlersTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testSavepointCompletedSuccessfully() throws Exception {
	final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
		.setTriggerSavepointFunction((JobID jobId, String targetDirectory) -> CompletableFuture.completedFuture(COMPLETED_SAVEPOINT_EXTERNAL_POINTER))
		.build();

	final TriggerId triggerId = savepointTriggerHandler.handleRequest(
		triggerSavepointRequest(),
		testingRestfulGateway).get().getTriggerId();

	AsynchronousOperationResult<SavepointInfo> savepointResponseBody;
	savepointResponseBody = savepointStatusHandler.handleRequest(
		savepointStatusRequest(triggerId),
		testingRestfulGateway).get();

	assertThat(
		savepointResponseBody.queueStatus().getId(),
		equalTo(QueueStatus.Id.COMPLETED));
	assertThat(savepointResponseBody.resource(), notNullValue());
	assertThat(
		savepointResponseBody.resource().getLocation(),
		equalTo(COMPLETED_SAVEPOINT_EXTERNAL_POINTER));
}
 
Example #9
Source File: SavepointHandlersTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testTriggerSavepointWithDefaultDirectory() throws Exception {
	final CompletableFuture<String> targetDirectoryFuture = new CompletableFuture<>();
	final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
		.setTriggerSavepointFunction(
			(JobID jobId, String targetDirectory) -> {
				targetDirectoryFuture.complete(targetDirectory);
				return CompletableFuture.completedFuture(COMPLETED_SAVEPOINT_EXTERNAL_POINTER);
			})
		.build();
	final String defaultSavepointDir = "/other/dir";
	final SavepointHandlers savepointHandlers = new SavepointHandlers(defaultSavepointDir);
	final SavepointHandlers.SavepointTriggerHandler savepointTriggerHandler = savepointHandlers.new SavepointTriggerHandler(
		leaderRetriever,
		TIMEOUT,
		Collections.emptyMap());

	savepointTriggerHandler.handleRequest(
		triggerSavepointRequestWithDefaultDirectory(),
		testingRestfulGateway).get();

	assertThat(targetDirectoryFuture.get(), equalTo(defaultSavepointDir));
}
 
Example #10
Source File: SavepointHandlersTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testTriggerSavepointNoDirectory() throws Exception {
	TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
		.setTriggerSavepointFunction((JobID jobId, String directory) -> CompletableFuture.completedFuture(COMPLETED_SAVEPOINT_EXTERNAL_POINTER))
		.build();

	try {
		savepointTriggerHandler.handleRequest(
			triggerSavepointRequestWithDefaultDirectory(),
			testingRestfulGateway).get();
		fail("Expected exception not thrown.");
	} catch (RestHandlerException rhe) {
		assertThat(
			rhe.getMessage(),
			equalTo("Config key [state.savepoints.dir] is not set. " +
				"Property [target-directory] must be provided."));
		assertThat(rhe.getHttpResponseStatus(), equalTo(HttpResponseStatus.BAD_REQUEST));
	}
}
 
Example #11
Source File: SavepointHandlersTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testSavepointCompletedWithException() throws Exception {
	TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
		.setTriggerSavepointFunction((JobID jobId, String directory) -> FutureUtils.completedExceptionally(new RuntimeException("expected")))
		.build();

	final TriggerId triggerId = savepointTriggerHandler.handleRequest(
		triggerSavepointRequest(),
		testingRestfulGateway).get().getTriggerId();

	final AsynchronousOperationResult<SavepointInfo> savepointResponseBody = savepointStatusHandler.handleRequest(
		savepointStatusRequest(triggerId),
		testingRestfulGateway).get();

	assertThat(savepointResponseBody.queueStatus().getId(), equalTo(QueueStatus.Id.COMPLETED));
	assertThat(savepointResponseBody.resource(), notNullValue());
	assertThat(savepointResponseBody.resource().getFailureCause(), notNullValue());
	final Throwable savepointError = savepointResponseBody.resource()
		.getFailureCause()
		.deserializeError(ClassLoader.getSystemClassLoader());
	assertThat(savepointError.getMessage(), equalTo("expected"));
	assertThat(savepointError, instanceOf(RuntimeException.class));
}
 
Example #12
Source File: StopWithSavepointHandlersTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testSavepointCompletedSuccessfully() throws Exception {
	final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
			.setStopWithSavepointFunction((JobID jobId, String targetDirectory) -> CompletableFuture.completedFuture(COMPLETED_SAVEPOINT_EXTERNAL_POINTER))
			.build();

	final TriggerId triggerId = savepointTriggerHandler.handleRequest(
			triggerSavepointRequest(),
			testingRestfulGateway).get().getTriggerId();

	AsynchronousOperationResult<SavepointInfo> savepointResponseBody;
	savepointResponseBody = savepointStatusHandler.handleRequest(
			savepointStatusRequest(triggerId),
			testingRestfulGateway).get();

	assertThat(
			savepointResponseBody.queueStatus().getId(),
			equalTo(QueueStatus.Id.COMPLETED));
	assertThat(savepointResponseBody.resource(), notNullValue());
	assertThat(
			savepointResponseBody.resource().getLocation(),
			equalTo(COMPLETED_SAVEPOINT_EXTERNAL_POINTER));
}
 
Example #13
Source File: StopWithSavepointHandlersTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testTriggerSavepointNoDirectory() throws Exception {
	TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
			.setStopWithSavepointFunction((JobID jobId, String directory) -> CompletableFuture.completedFuture(COMPLETED_SAVEPOINT_EXTERNAL_POINTER))
			.build();

	try {
		savepointTriggerHandler.handleRequest(
				triggerSavepointRequestWithDefaultDirectory(),
				testingRestfulGateway).get();
		fail("Expected exception not thrown.");
	} catch (RestHandlerException rhe) {
		assertThat(
				rhe.getMessage(),
				equalTo("Config key [state.savepoints.dir] is not set. " +
						"Property [targetDirectory] must be provided."));
		assertThat(rhe.getHttpResponseStatus(), equalTo(HttpResponseStatus.BAD_REQUEST));
	}
}
 
Example #14
Source File: StopWithSavepointHandlersTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testSavepointCompletedWithException() throws Exception {
	TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
			.setStopWithSavepointFunction((JobID jobId, String directory) -> FutureUtils.completedExceptionally(new RuntimeException("expected")))
			.build();

	final TriggerId triggerId = savepointTriggerHandler.handleRequest(
			triggerSavepointRequest(),
			testingRestfulGateway).get().getTriggerId();

	final AsynchronousOperationResult<SavepointInfo> savepointResponseBody = savepointStatusHandler.handleRequest(
			savepointStatusRequest(triggerId),
			testingRestfulGateway).get();

	assertThat(savepointResponseBody.queueStatus().getId(), equalTo(QueueStatus.Id.COMPLETED));
	assertThat(savepointResponseBody.resource(), notNullValue());
	assertThat(savepointResponseBody.resource().getFailureCause(), notNullValue());
	final Throwable savepointError = savepointResponseBody.resource()
			.getFailureCause()
			.deserializeError(ClassLoader.getSystemClassLoader());
	assertThat(savepointError.getMessage(), equalTo("expected"));
	assertThat(savepointError, instanceOf(RuntimeException.class));
}
 
Example #15
Source File: AbstractAsynchronousOperationHandlersTest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the triggering and exceptional completion of an asynchronous operation.
 */
@Test
public void testOperationFailure() throws Exception {
	final FlinkException testException = new FlinkException("Test exception");
	final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
		.setTriggerSavepointFunction((JobID jobId, String directory) -> FutureUtils.completedExceptionally(testException))
		.build();

	// trigger the operation
	final TriggerId triggerId = testingTriggerHandler.handleRequest(
		triggerOperationRequest(),
		testingRestfulGateway).get().getTriggerId();

	AsynchronousOperationResult<OperationResult> operationResult = testingStatusHandler.handleRequest(
		statusOperationRequest(triggerId),
		testingRestfulGateway).get();

	assertThat(operationResult.queueStatus().getId(), is(QueueStatus.completed().getId()));

	final OperationResult resource = operationResult.resource();
	assertThat(resource.throwable, is(testException));
}
 
Example #16
Source File: StopWithSavepointHandlersTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testTriggerSavepointWithDefaultDirectory() throws Exception {
	final CompletableFuture<String> targetDirectoryFuture = new CompletableFuture<>();
	final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
			.setStopWithSavepointFunction(
					(JobID jobId, String targetDirectory) -> {
						targetDirectoryFuture.complete(targetDirectory);
						return CompletableFuture.completedFuture(COMPLETED_SAVEPOINT_EXTERNAL_POINTER);
					})
			.build();
	final String defaultSavepointDir = "/other/dir";
	final SavepointHandlers savepointHandlers = new SavepointHandlers(defaultSavepointDir);
	final SavepointHandlers.StopWithSavepointHandler savepointTriggerHandler = savepointHandlers.new StopWithSavepointHandler(
			leaderRetriever,
			TIMEOUT,
			Collections.emptyMap());

	savepointTriggerHandler.handleRequest(
			triggerSavepointRequestWithDefaultDirectory(),
			testingRestfulGateway).get();

	assertThat(targetDirectoryFuture.get(), equalTo(defaultSavepointDir));
}
 
Example #17
Source File: AbstractAsynchronousOperationHandlersTest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that the future returned by {@link AbstractAsynchronousOperationHandlers.StatusHandler#closeAsync()}
 * completes when the result of the asynchronous operation is served.
 */
@Test
public void testCloseShouldFinishOnFirstServedResult() throws Exception {
	final CompletableFuture<String> savepointFuture = new CompletableFuture<>();
	final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
		.setTriggerSavepointFunction((JobID jobId, String directory) -> savepointFuture)
		.build();

	final TriggerId triggerId = testingTriggerHandler.handleRequest(
		triggerOperationRequest(),
		testingRestfulGateway).get().getTriggerId();
	final CompletableFuture<Void> closeFuture = testingStatusHandler.closeAsync();

	testingStatusHandler.handleRequest(statusOperationRequest(triggerId), testingRestfulGateway).get();

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

	savepointFuture.complete("foobar");
	testingStatusHandler.handleRequest(statusOperationRequest(triggerId), testingRestfulGateway).get();

	assertThat(closeFuture.isDone(), is(true));
}
 
Example #18
Source File: JobExecutionResultHandlerTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testPropagateFlinkJobNotFoundExceptionAsRestHandlerException() throws Exception {
	final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
		.setRequestJobStatusFunction(
			jobId -> FutureUtils.completedExceptionally(new FlinkJobNotFoundException(jobId))
		)
		.build();

	try {
		jobExecutionResultHandler.handleRequest(
			testRequest,
			testingRestfulGateway).get();
		fail("Expected exception not thrown");
	} catch (final ExecutionException e) {
		final Throwable cause = ExceptionUtils.stripCompletionException(e.getCause());
		assertThat(cause, instanceOf(RestHandlerException.class));
		assertThat(
			((RestHandlerException) cause).getHttpResponseStatus(),
			equalTo(HttpResponseStatus.NOT_FOUND));
	}
}
 
Example #19
Source File: JobVertexBackPressureHandlerTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
	restfulGateway = new TestingRestfulGateway.Builder().setRequestOperatorBackPressureStatsFunction(
		(jobId, jobVertexId) -> {
			if (jobId.equals(TEST_JOB_ID_BACK_PRESSURE_STATS_AVAILABLE)) {
				return CompletableFuture.completedFuture(OperatorBackPressureStatsResponse.of(new OperatorBackPressureStats(
					4711,
					Integer.MAX_VALUE,
					new double[]{1.0, 0.5, 0.1}
				)));
			} else if (jobId.equals(TEST_JOB_ID_BACK_PRESSURE_STATS_ABSENT)) {
				return CompletableFuture.completedFuture(OperatorBackPressureStatsResponse.of(null));
			} else {
				throw new AssertionError();
			}
		}
	).build();
	jobVertexBackPressureHandler = new JobVertexBackPressureHandler(
		() -> CompletableFuture.completedFuture(restfulGateway),
		Time.seconds(10),
		Collections.emptyMap(),
		JobVertexBackPressureHeaders.getInstance()
	);
}
 
Example #20
Source File: SavepointHandlersTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testSavepointCompletedSuccessfully() throws Exception {
	final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
		.setTriggerSavepointFunction((JobID jobId, String targetDirectory) -> CompletableFuture.completedFuture(COMPLETED_SAVEPOINT_EXTERNAL_POINTER))
		.build();

	final TriggerId triggerId = savepointTriggerHandler.handleRequest(
		triggerSavepointRequest(),
		testingRestfulGateway).get().getTriggerId();

	AsynchronousOperationResult<SavepointInfo> savepointResponseBody;
	savepointResponseBody = savepointStatusHandler.handleRequest(
		savepointStatusRequest(triggerId),
		testingRestfulGateway).get();

	assertThat(
		savepointResponseBody.queueStatus().getId(),
		equalTo(QueueStatus.Id.COMPLETED));
	assertThat(savepointResponseBody.resource(), notNullValue());
	assertThat(
		savepointResponseBody.resource().getLocation(),
		equalTo(COMPLETED_SAVEPOINT_EXTERNAL_POINTER));
}
 
Example #21
Source File: SavepointHandlersTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testTriggerSavepointWithDefaultDirectory() throws Exception {
	final CompletableFuture<String> targetDirectoryFuture = new CompletableFuture<>();
	final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
		.setTriggerSavepointFunction(
			(JobID jobId, String targetDirectory) -> {
				targetDirectoryFuture.complete(targetDirectory);
				return CompletableFuture.completedFuture(COMPLETED_SAVEPOINT_EXTERNAL_POINTER);
			})
		.build();
	final String defaultSavepointDir = "/other/dir";
	final SavepointHandlers savepointHandlers = new SavepointHandlers(defaultSavepointDir);
	final SavepointHandlers.SavepointTriggerHandler savepointTriggerHandler = savepointHandlers.new SavepointTriggerHandler(
		leaderRetriever,
		TIMEOUT,
		Collections.emptyMap());

	savepointTriggerHandler.handleRequest(
		triggerSavepointRequestWithDefaultDirectory(),
		testingRestfulGateway).get();

	assertThat(targetDirectoryFuture.get(), equalTo(defaultSavepointDir));
}
 
Example #22
Source File: SavepointHandlersTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testTriggerSavepointNoDirectory() throws Exception {
	TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
		.setTriggerSavepointFunction((JobID jobId, String directory) -> CompletableFuture.completedFuture(COMPLETED_SAVEPOINT_EXTERNAL_POINTER))
		.build();

	try {
		savepointTriggerHandler.handleRequest(
			triggerSavepointRequestWithDefaultDirectory(),
			testingRestfulGateway).get();
		fail("Expected exception not thrown.");
	} catch (RestHandlerException rhe) {
		assertThat(
			rhe.getMessage(),
			equalTo("Config key [state.savepoints.dir] is not set. " +
				"Property [target-directory] must be provided."));
		assertThat(rhe.getHttpResponseStatus(), equalTo(HttpResponseStatus.BAD_REQUEST));
	}
}
 
Example #23
Source File: SavepointHandlersTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testSavepointCompletedWithException() throws Exception {
	TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
		.setTriggerSavepointFunction((JobID jobId, String directory) -> FutureUtils.completedExceptionally(new RuntimeException("expected")))
		.build();

	final TriggerId triggerId = savepointTriggerHandler.handleRequest(
		triggerSavepointRequest(),
		testingRestfulGateway).get().getTriggerId();

	final AsynchronousOperationResult<SavepointInfo> savepointResponseBody = savepointStatusHandler.handleRequest(
		savepointStatusRequest(triggerId),
		testingRestfulGateway).get();

	assertThat(savepointResponseBody.queueStatus().getId(), equalTo(QueueStatus.Id.COMPLETED));
	assertThat(savepointResponseBody.resource(), notNullValue());
	assertThat(savepointResponseBody.resource().getFailureCause(), notNullValue());
	final Throwable savepointError = savepointResponseBody.resource()
		.getFailureCause()
		.deserializeError(ClassLoader.getSystemClassLoader());
	assertThat(savepointError.getMessage(), equalTo("expected"));
	assertThat(savepointError, instanceOf(RuntimeException.class));
}
 
Example #24
Source File: StopWithSavepointHandlersTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testSavepointCompletedSuccessfully() throws Exception {
	final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
			.setStopWithSavepointFunction((JobID jobId, String targetDirectory) -> CompletableFuture.completedFuture(COMPLETED_SAVEPOINT_EXTERNAL_POINTER))
			.build();

	final TriggerId triggerId = savepointTriggerHandler.handleRequest(
			triggerSavepointRequest(),
			testingRestfulGateway).get().getTriggerId();

	AsynchronousOperationResult<SavepointInfo> savepointResponseBody;
	savepointResponseBody = savepointStatusHandler.handleRequest(
			savepointStatusRequest(triggerId),
			testingRestfulGateway).get();

	assertThat(
			savepointResponseBody.queueStatus().getId(),
			equalTo(QueueStatus.Id.COMPLETED));
	assertThat(savepointResponseBody.resource(), notNullValue());
	assertThat(
			savepointResponseBody.resource().getLocation(),
			equalTo(COMPLETED_SAVEPOINT_EXTERNAL_POINTER));
}
 
Example #25
Source File: StopWithSavepointHandlersTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testTriggerSavepointWithDefaultDirectory() throws Exception {
	final CompletableFuture<String> targetDirectoryFuture = new CompletableFuture<>();
	final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
			.setStopWithSavepointFunction(
					(JobID jobId, String targetDirectory) -> {
						targetDirectoryFuture.complete(targetDirectory);
						return CompletableFuture.completedFuture(COMPLETED_SAVEPOINT_EXTERNAL_POINTER);
					})
			.build();
	final String defaultSavepointDir = "/other/dir";
	final SavepointHandlers savepointHandlers = new SavepointHandlers(defaultSavepointDir);
	final SavepointHandlers.StopWithSavepointHandler savepointTriggerHandler = savepointHandlers.new StopWithSavepointHandler(
			leaderRetriever,
			TIMEOUT,
			Collections.emptyMap());

	savepointTriggerHandler.handleRequest(
			triggerSavepointRequestWithDefaultDirectory(),
			testingRestfulGateway).get();

	assertThat(targetDirectoryFuture.get(), equalTo(defaultSavepointDir));
}
 
Example #26
Source File: StopWithSavepointHandlersTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testTriggerSavepointNoDirectory() throws Exception {
	TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
			.setStopWithSavepointFunction((JobID jobId, String directory) -> CompletableFuture.completedFuture(COMPLETED_SAVEPOINT_EXTERNAL_POINTER))
			.build();

	try {
		savepointTriggerHandler.handleRequest(
				triggerSavepointRequestWithDefaultDirectory(),
				testingRestfulGateway).get();
		fail("Expected exception not thrown.");
	} catch (RestHandlerException rhe) {
		assertThat(
				rhe.getMessage(),
				equalTo("Config key [state.savepoints.dir] is not set. " +
						"Property [targetDirectory] must be provided."));
		assertThat(rhe.getHttpResponseStatus(), equalTo(HttpResponseStatus.BAD_REQUEST));
	}
}
 
Example #27
Source File: StopWithSavepointHandlersTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testSavepointCompletedWithException() throws Exception {
	TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
			.setStopWithSavepointFunction((JobID jobId, String directory) -> FutureUtils.completedExceptionally(new RuntimeException("expected")))
			.build();

	final TriggerId triggerId = savepointTriggerHandler.handleRequest(
			triggerSavepointRequest(),
			testingRestfulGateway).get().getTriggerId();

	final AsynchronousOperationResult<SavepointInfo> savepointResponseBody = savepointStatusHandler.handleRequest(
			savepointStatusRequest(triggerId),
			testingRestfulGateway).get();

	assertThat(savepointResponseBody.queueStatus().getId(), equalTo(QueueStatus.Id.COMPLETED));
	assertThat(savepointResponseBody.resource(), notNullValue());
	assertThat(savepointResponseBody.resource().getFailureCause(), notNullValue());
	final Throwable savepointError = savepointResponseBody.resource()
			.getFailureCause()
			.deserializeError(ClassLoader.getSystemClassLoader());
	assertThat(savepointError.getMessage(), equalTo("expected"));
	assertThat(savepointError, instanceOf(RuntimeException.class));
}
 
Example #28
Source File: AbstractAsynchronousOperationHandlersTest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the triggering and exceptional completion of an asynchronous operation.
 */
@Test
public void testOperationFailure() throws Exception {
	final FlinkException testException = new FlinkException("Test exception");
	final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
		.setTriggerSavepointFunction((JobID jobId, String directory) -> FutureUtils.completedExceptionally(testException))
		.build();

	// trigger the operation
	final TriggerId triggerId = testingTriggerHandler.handleRequest(
		triggerOperationRequest(),
		testingRestfulGateway).get().getTriggerId();

	AsynchronousOperationResult<OperationResult> operationResult = testingStatusHandler.handleRequest(
		statusOperationRequest(triggerId),
		testingRestfulGateway).get();

	assertThat(operationResult.queueStatus().getId(), is(QueueStatus.completed().getId()));

	final OperationResult resource = operationResult.resource();
	assertThat(resource.throwable, is(testException));
}
 
Example #29
Source File: AbstractAsynchronousOperationHandlersTest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that an querying an unknown trigger id will return an exceptionally completed
 * future.
 */
@Test
public void testUnknownTriggerId() throws Exception {
	final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder().build();

	try {
		testingStatusHandler.handleRequest(
			statusOperationRequest(new TriggerId()),
			testingRestfulGateway).get();

		fail("This should have failed with a RestHandlerException.");
	} catch (ExecutionException ee) {
		final Optional<RestHandlerException> optionalRestHandlerException = ExceptionUtils.findThrowable(ee, RestHandlerException.class);

		assertThat(optionalRestHandlerException.isPresent(), is(true));

		final RestHandlerException restHandlerException = optionalRestHandlerException.get();

		assertThat(restHandlerException.getMessage(), containsString("Operation not found"));
		assertThat(restHandlerException.getHttpResponseStatus(), is(HttpResponseStatus.NOT_FOUND));
	}
}
 
Example #30
Source File: AbstractAsynchronousOperationHandlersTest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that the future returned by {@link AbstractAsynchronousOperationHandlers.StatusHandler#closeAsync()}
 * completes when the result of the asynchronous operation is served.
 */
@Test
public void testCloseShouldFinishOnFirstServedResult() throws Exception {
	final CompletableFuture<String> savepointFuture = new CompletableFuture<>();
	final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
		.setTriggerSavepointFunction((JobID jobId, String directory) -> savepointFuture)
		.build();

	final TriggerId triggerId = testingTriggerHandler.handleRequest(
		triggerOperationRequest(),
		testingRestfulGateway).get().getTriggerId();
	final CompletableFuture<Void> closeFuture = testingStatusHandler.closeAsync();

	testingStatusHandler.handleRequest(statusOperationRequest(triggerId), testingRestfulGateway).get();

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

	savepointFuture.complete("foobar");
	testingStatusHandler.handleRequest(statusOperationRequest(triggerId), testingRestfulGateway).get();

	assertThat(closeFuture.isDone(), is(true));
}