org.apache.flink.runtime.webmonitor.testutils.HttpTestClient Java Examples

The following examples show how to use org.apache.flink.runtime.webmonitor.testutils.HttpTestClient. 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: WebFrontendITCase.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Test
public void testStopYarn() throws Exception {
	// this only works if there is no active job at this point
	assertTrue(getRunningJobs(CLUSTER.getClusterClient()).isEmpty());

	// Create a task
	final JobVertex sender = new JobVertex("Sender");
	sender.setParallelism(2);
	sender.setInvokableClass(BlockingInvokable.class);

	final JobGraph jobGraph = new JobGraph("Stoppable streaming test job", sender);
	final JobID jid = jobGraph.getJobID();

	ClusterClient<?> clusterClient = CLUSTER.getClusterClient();
	clusterClient.setDetached(true);
	clusterClient.submitJob(jobGraph, WebFrontendITCase.class.getClassLoader());

	// wait for job to show up
	while (getRunningJobs(CLUSTER.getClusterClient()).isEmpty()) {
		Thread.sleep(10);
	}

	// wait for tasks to be properly running
	BlockingInvokable.latch.await();

	final FiniteDuration testTimeout = new FiniteDuration(2, TimeUnit.MINUTES);
	final Deadline deadline = testTimeout.fromNow();

	try (HttpTestClient client = new HttpTestClient("localhost", getRestPort())) {
		// Request the file from the web server
		client.sendGetRequest("/jobs/" + jid + "/yarn-stop", deadline.timeLeft());

		HttpTestClient.SimpleHttpResponse response = client
			.getNextResponse(deadline.timeLeft());

		assertEquals(HttpResponseStatus.ACCEPTED, response.getStatus());
		assertEquals("application/json; charset=UTF-8", response.getType());
		assertEquals("{}", response.getContent());
	}

	// wait for cancellation to finish
	while (!getRunningJobs(CLUSTER.getClusterClient()).isEmpty()) {
		Thread.sleep(20);
	}

	BlockingInvokable.reset();
}
 
Example #2
Source File: LeaderRetrievalHandlerTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Tests the behaviour of the LeaderRetrievalHandler under the following conditions.
 *
 * <p>1. No gateway resolved --> service unavailable
 * 2. leader gateway
 * @throws Exception
 */
@Test
public void testLeaderRetrievalGateway() throws Exception {
	final String restPath = "/testing";

	final Configuration configuration = new Configuration();
	final Router router = new Router();
	final Time timeout = Time.seconds(10L);
	final CompletableFuture<RestfulGateway> gatewayFuture = new CompletableFuture<>();
	final GatewayRetriever<RestfulGateway> gatewayRetriever = () -> gatewayFuture;
	final RestfulGateway gateway = TestingRestfulGateway.newBuilder().build();

	final TestingHandler testingHandler = new TestingHandler(
		gatewayRetriever,
		timeout);

	router.addGet(restPath, testingHandler);
	WebFrontendBootstrap bootstrap = new WebFrontendBootstrap(
		router,
		log,
		null,
		null,
		"localhost",
		0,
		configuration);

	try (HttpTestClient httpClient = new HttpTestClient("localhost", bootstrap.getServerPort())) {
		// 1. no leader gateway available --> Service unavailable
		httpClient.sendGetRequest(restPath, FutureUtils.toFiniteDuration(timeout));

		HttpTestClient.SimpleHttpResponse response = httpClient.getNextResponse(FutureUtils.toFiniteDuration(timeout));

		Assert.assertEquals(HttpResponseStatus.SERVICE_UNAVAILABLE, response.getStatus());

		// 2. with leader
		gatewayFuture.complete(gateway);

		httpClient.sendGetRequest(restPath, FutureUtils.toFiniteDuration(timeout));

		response = httpClient.getNextResponse(FutureUtils.toFiniteDuration(timeout));

		Assert.assertEquals(HttpResponseStatus.OK, response.getStatus());
		Assert.assertEquals(RESPONSE_MESSAGE, response.getContent());

	} finally {
		bootstrap.shutdown();
	}
}
 
Example #3
Source File: WebFrontendITCase.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testCancelYarn() throws Exception {
	// this only works if there is no active job at this point
	assertTrue(getRunningJobs(CLUSTER.getClusterClient()).isEmpty());

	// Create a task
	final JobVertex sender = new JobVertex("Sender");
	sender.setParallelism(2);
	sender.setInvokableClass(BlockingInvokable.class);

	final JobGraph jobGraph = new JobGraph("Stoppable streaming test job", sender);
	final JobID jid = jobGraph.getJobID();

	ClusterClient<?> clusterClient = CLUSTER.getClusterClient();
	clusterClient.setDetached(true);
	clusterClient.submitJob(jobGraph, WebFrontendITCase.class.getClassLoader());

	// wait for job to show up
	while (getRunningJobs(CLUSTER.getClusterClient()).isEmpty()) {
		Thread.sleep(10);
	}

	// wait for tasks to be properly running
	BlockingInvokable.latch.await();

	final FiniteDuration testTimeout = new FiniteDuration(2, TimeUnit.MINUTES);
	final Deadline deadline = testTimeout.fromNow();

	try (HttpTestClient client = new HttpTestClient("localhost", getRestPort())) {
		// Request the file from the web server
		client.sendGetRequest("/jobs/" + jid + "/yarn-cancel", deadline.timeLeft());

		HttpTestClient.SimpleHttpResponse response = client
			.getNextResponse(deadline.timeLeft());

		assertEquals(HttpResponseStatus.ACCEPTED, response.getStatus());
		assertEquals("application/json; charset=UTF-8", response.getType());
		assertEquals("{}", response.getContent());
	}

	// wait for cancellation to finish
	while (!getRunningJobs(CLUSTER.getClusterClient()).isEmpty()) {
		Thread.sleep(20);
	}

	BlockingInvokable.reset();
}
 
Example #4
Source File: LeaderRetrievalHandlerTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Tests the behaviour of the LeaderRetrievalHandler under the following conditions.
 *
 * <p>1. No gateway resolved --> service unavailable
 * 2. leader gateway
 * @throws Exception
 */
@Test
public void testLeaderRetrievalGateway() throws Exception {
	final String restPath = "/testing";

	final Configuration configuration = new Configuration();
	final Router router = new Router();
	final Time timeout = Time.seconds(10L);
	final CompletableFuture<RestfulGateway> gatewayFuture = new CompletableFuture<>();
	final GatewayRetriever<RestfulGateway> gatewayRetriever = () -> gatewayFuture;
	final RestfulGateway gateway = TestingRestfulGateway.newBuilder().build();

	final TestingHandler testingHandler = new TestingHandler(
		gatewayRetriever,
		timeout);

	router.addGet(restPath, testingHandler);
	WebFrontendBootstrap bootstrap = new WebFrontendBootstrap(
		router,
		log,
		null,
		null,
		"localhost",
		0,
		configuration);

	try (HttpTestClient httpClient = new HttpTestClient("localhost", bootstrap.getServerPort())) {
		// 1. no leader gateway available --> Service unavailable
		httpClient.sendGetRequest(restPath, FutureUtils.toFiniteDuration(timeout));

		HttpTestClient.SimpleHttpResponse response = httpClient.getNextResponse(FutureUtils.toFiniteDuration(timeout));

		Assert.assertEquals(HttpResponseStatus.SERVICE_UNAVAILABLE, response.getStatus());

		// 2. with leader
		gatewayFuture.complete(gateway);

		httpClient.sendGetRequest(restPath, FutureUtils.toFiniteDuration(timeout));

		response = httpClient.getNextResponse(FutureUtils.toFiniteDuration(timeout));

		Assert.assertEquals(HttpResponseStatus.OK, response.getStatus());
		Assert.assertEquals(RESPONSE_MESSAGE, response.getContent());

	} finally {
		bootstrap.shutdown();
	}
}
 
Example #5
Source File: WebFrontendITCase.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testCancelYarn() throws Exception {
	// this only works if there is no active job at this point
	assertTrue(getRunningJobs(CLUSTER.getClusterClient()).isEmpty());

	// Create a task
	final JobVertex sender = new JobVertex("Sender");
	sender.setParallelism(2);
	sender.setInvokableClass(BlockingInvokable.class);

	final JobGraph jobGraph = new JobGraph("Stoppable streaming test job", sender);
	final JobID jid = jobGraph.getJobID();

	ClusterClient<?> clusterClient = CLUSTER.getClusterClient();
	ClientUtils.submitJob(clusterClient, jobGraph);

	// wait for job to show up
	while (getRunningJobs(CLUSTER.getClusterClient()).isEmpty()) {
		Thread.sleep(10);
	}

	// wait for tasks to be properly running
	BlockingInvokable.latch.await();

	final Duration testTimeout = Duration.ofMinutes(2);
	final LocalTime deadline = LocalTime.now().plus(testTimeout);

	try (HttpTestClient client = new HttpTestClient("localhost", getRestPort())) {
		// Request the file from the web server
		client.sendGetRequest("/jobs/" + jid + "/yarn-cancel", getTimeLeft(deadline));

		HttpTestClient.SimpleHttpResponse response = client.getNextResponse(getTimeLeft(deadline));

		assertEquals(HttpResponseStatus.ACCEPTED, response.getStatus());
		assertEquals("application/json; charset=UTF-8", response.getType());
		assertEquals("{}", response.getContent());
	}

	// wait for cancellation to finish
	while (!getRunningJobs(CLUSTER.getClusterClient()).isEmpty()) {
		Thread.sleep(20);
	}

	BlockingInvokable.reset();
}
 
Example #6
Source File: LeaderRetrievalHandlerTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Tests the behaviour of the LeaderRetrievalHandler under the following conditions.
 *
 * <p>1. No gateway resolved --> service unavailable
 * 2. leader gateway
 * @throws Exception
 */
@Test
public void testLeaderRetrievalGateway() throws Exception {
	final String restPath = "/testing";

	final Configuration configuration = new Configuration();
	final Router router = new Router();
	final Time timeout = Time.seconds(10L);
	final CompletableFuture<RestfulGateway> gatewayFuture = new CompletableFuture<>();
	final GatewayRetriever<RestfulGateway> gatewayRetriever = () -> gatewayFuture;
	final RestfulGateway gateway = new TestingRestfulGateway.Builder().build();

	final TestingHandler testingHandler = new TestingHandler(
		gatewayRetriever,
		timeout);

	router.addGet(restPath, testingHandler);
	WebFrontendBootstrap bootstrap = new WebFrontendBootstrap(
		router,
		log,
		null,
		null,
		"localhost",
		0,
		configuration);

	try (HttpTestClient httpClient = new HttpTestClient("localhost", bootstrap.getServerPort())) {
		// 1. no leader gateway available --> Service unavailable
		httpClient.sendGetRequest(restPath, FutureUtils.toDuration(timeout));

		HttpTestClient.SimpleHttpResponse response = httpClient.getNextResponse(FutureUtils.toDuration(timeout));

		Assert.assertEquals(HttpResponseStatus.SERVICE_UNAVAILABLE, response.getStatus());

		// 2. with leader
		gatewayFuture.complete(gateway);

		httpClient.sendGetRequest(restPath, FutureUtils.toDuration(timeout));

		response = httpClient.getNextResponse(FutureUtils.toDuration(timeout));

		Assert.assertEquals(HttpResponseStatus.OK, response.getStatus());
		Assert.assertEquals(RESPONSE_MESSAGE, response.getContent());

	} finally {
		bootstrap.shutdown();
	}
}