[ 
https://issues.apache.org/jira/browse/FLINK-2477?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14681592#comment-14681592
 ] 

ASF GitHub Bot commented on FLINK-2477:
---------------------------------------

Github user StephanEwen commented on the pull request:

    https://github.com/apache/flink/pull/977#issuecomment-129829151
  
    Looks much better. Two more comments:
    
    1. It would be good to print the exception in addition to failing the test, 
because otherwise the tests only fails and gives no indication why. A typical 
pattern is:
    ```java
    try {
      // some stuff
    } catch (Exception e) {
      e.printStackTrace();
      Assert.fail(e.getMessage());
    }
    ```
    Here, the test prints nothing when working properly, but prints the error 
when it fails.
    
    2. `Assert.fail()` does not work when used in spawned threads. The reason 
is that JUnit communicates the failure with a special 
`AssertionFailedException`, which needs to reach the invoking framework. That 
does not happen if the `fail()` method is called in a spawned thread.
    
    Here is how you can do it. It is a bit clumsy, because you need to forward 
the exception to the main thread, but it works well:
    ```java
    final AtomicReference<Throwable> error = new AtomicReference<>();
    Thread thread = new Thread("server thread") {
        @Override
        public void run() {
            try {
                doStuff();
            }
            catch (Throwable t) {
                ref.set(t);
            }
        }
    };
    thread.start();
    
    // do some test logic
    
    thread.join();
    if (error.get() != null) {
        Throwable t = error.get();
        t.printStackTrace();
        fail("Error in spawned thread: " + t.getMessage());
    }
    ```
    



> Add test for SocketClientSink
> -----------------------------
>
>                 Key: FLINK-2477
>                 URL: https://issues.apache.org/jira/browse/FLINK-2477
>             Project: Flink
>          Issue Type: Test
>          Components: Streaming
>    Affects Versions: 0.10
>         Environment: win7 32bit;linux
>            Reporter: Huang Wei
>            Priority: Minor
>             Fix For: 0.10
>
>   Original Estimate: 168h
>  Remaining Estimate: 168h
>
> Add some tests for SocketClientSink.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to