You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by tillrohrmann <gi...@git.apache.org> on 2016/04/25 18:11:03 UTC

[GitHub] flink pull request: [FLINK-1827] and small fixes in some tests

Github user tillrohrmann commented on a diff in the pull request:

    https://github.com/apache/flink/pull/1915#discussion_r60940770
  
    --- Diff: flink-runtime/src/test/java/org/apache/flink/runtime/taskmanager/TaskManagerStartupTest.java ---
    @@ -53,41 +59,55 @@ public void testStartupWhenTaskmanagerActorPortIsUsed() {
     			blocker = new ServerSocket(0, 50, localAddress);
     			final int port = blocker.getLocalPort();
     
    -			try {
    -				TaskManager.runTaskManager(
    -					localHostName,
    -					ResourceID.generate(),
    -					port,
    -					new Configuration(),
    +			TaskManager.runTaskManager(localHostName, ResourceID.generate(), port, new Configuration(),
     					TaskManager.class);
    -				fail("This should fail with an IOException");
    -			}
    -			catch (IOException e) {
    -				// expected. validate the error message
    -				assertNotNull(e.getMessage());
    -				assertTrue(e.getMessage().contains("Address already in use"));
    +			fail("This should fail with an IOException");
    +
    +		} catch (IOException e) {
    +			// expected. validate the error messagex
    +			List<Throwable> causes = getExceptionCauses(e, new ArrayList<Throwable>());
    +			for (Throwable cause : causes) {
    +				if (cause instanceof BindException) {
    +					throw (BindException) cause;
    +				}
     			}
    -
    -		}
    -		catch (Exception e) {
    +			fail("This should fail with an exception caused by BindException");
    +		} catch (Exception e) {
     			e.printStackTrace();
     			fail(e.getMessage());
    -		}
    -		finally {
    +		} finally {
     			if (blocker != null) {
     				try {
     					blocker.close();
    -				}
    -				catch (IOException e) {
    +				} catch (IOException e) {
     					// no need to log here
     				}
     			}
     		}
     	}
     
     	/**
    -	 * Tests that the TaskManager startup fails synchronously when the I/O directories are
    -	 * not writable.
    +	 * A utility method to analyze the exceptions and collect the clauses
    +	 * 
    +	 * @param e
    +	 *            the root exception (Throwable) object
    +	 * @param causes
    +	 *            the list of exceptions that caused the root exceptions
    +	 * @return
    +	 */
    +	private List<Throwable> getExceptionCauses(Throwable e, List<Throwable> causes) {
    --- End diff --
    
    What about factoring this method out into a Utils class so that it can be used by multiple tests. This would avoid code duplication.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---