flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [flink] zentol commented on a change in pull request #8534: [FLINK-12614][yarn] Refactor test to not do assertions in @After methods
Date Tue, 28 May 2019 10:47:31 GMT
zentol commented on a change in pull request #8534: [FLINK-12614][yarn] Refactor test to not
do assertions in @After methods 
URL: https://github.com/apache/flink/pull/8534#discussion_r288039865
 
 

 ##########
 File path: flink-yarn-tests/src/test/java/org/apache/flink/yarn/YarnTestBase.java
 ##########
 @@ -212,30 +212,45 @@ public void checkClusterEmpty() {
 	 * Sleep a bit between the tests (we are re-using the YARN cluster for the tests).
 	 */
 	@After
-	public void sleep() throws IOException, YarnException {
-		Deadline deadline = Deadline.now().plus(Duration.ofSeconds(10));
+	public void shutdownYarnClient() {
+		yarnClient.stop();
+	}
 
-		boolean isAnyJobRunning = yarnClient.getApplications().stream()
-			.anyMatch(YarnTestBase::isApplicationRunning);
+	protected void runTest(RunnableWithException test) {
+		Throwable testFailure = null;
+		try {
+			test.run();
+		} catch (Throwable t) {
+			testFailure = t;
 
 Review comment:
   are you saying that, given the piece of code below, exception "2" would be automatically
suppressed?
   ```
   try {
   	throw new Exception("1");
   } finally {
   	throw new Exception("2");
   }
   ```
   According to this [SO post](https://stackoverflow.com/questions/19583374/are-exceptions-thrown-in-a-finally-block-added-to-the-list-of-suppressed-excepti)
this only works when using try-with-resources.
   Thus in order to suppress an exception thrown in the `finally` part we'd still have to
catch the test failure exception beforehand.
   Which we could of course, but we'd end up with:
   ```
   Throwable testFailure = null;
   try {
   	test.run();
   } catch (Throwable t) {
   	testFailure = t;
   } finally {
   	try {
   		Deadline deadline = Deadline.now().plus(Duration.ofSeconds(10));
   
   		boolean isAnyJobRunning = yarnClient.getApplications().stream()
   			.anyMatch(YarnTestBase::isApplicationRunning);
   
   		while (deadline.hasTimeLeft() && isAnyJobRunning) {
   			try {
   				Thread.sleep(500);
   			} catch (InterruptedException e) {
   				Assert.fail("Should not happen");
   			}
   			isAnyJobRunning = yarnClient.getApplications().stream()
   				.anyMatch(YarnTestBase::isApplicationRunning);
   		}
   
   		if (isAnyJobRunning) {
   			final List<String> runningApps = yarnClient.getApplications().stream()
   				.filter(YarnTestBase::isApplicationRunning)
   				.map(app -> "App " + app.getApplicationId() + " is in state " + app.getYarnApplicationState()
+ '.')
   				.collect(Collectors.toList());
   			if (!runningApps.isEmpty()) {
   				Assert.fail("There is at least one application on the cluster that is not finished."
+ runningApps);
   			}
   		}
   	} catch (Throwable t) {
   		throw new AssertionError(ExceptionUtils.firstOrSuppressed(t, testFailure));
   	}
   }
   
   if (testFailure != null) {
   	throw new AssertionError(testFailure);
   }
   ```
   
   This is what I meant in my other comment about having to retain both try-catch blocks.
We need the outer one to catch the test exception so _can_ suppress later exceptions, and
we need the inner one to _do_ the actual suppression.
   
   I don't think the `finally` adds anything here.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message