{"action":"created","issue":{"url":"https://api.github.com/repos/apache/flink/issues/977","labels_url":"https://api.github.com/repos/apache/flink/issues/977/labels{/name}","comments_url":"https://api.github.com/repos/apache/flink/issues/977/comments","events_url":"https://api.github.com/repos/apache/flink/issues/977/events","html_url":"https://github.com/apache/flink/pull/977","id":98881541,"number":977,"title":"[FLINK-2477][Add]Add tests for SocketClientSink","user":{"login":"HuangWHWHW","id":13193847,"avatar_url":"https://avatars.githubusercontent.com/u/13193847?v=3","gravatar_id":"","url":"https://api.github.com/users/HuangWHWHW","html_url":"https://github.com/HuangWHWHW","followers_url":"https://api.github.com/users/HuangWHWHW/followers","following_url":"https://api.github.com/users/HuangWHWHW/following{/other_user}","gists_url":"https://api.github.com/users/HuangWHWHW/gists{/gist_id}","starred_url":"https://api.github.com/users/HuangWHWHW/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HuangWHWHW/subscriptions","organizations_url":"https://api.github.com/users/HuangWHWHW/orgs","repos_url":"https://api.github.com/users/HuangWHWHW/repos","events_url":"https://api.github.com/users/HuangWHWHW/events{/privacy}","received_events_url":"https://api.github.com/users/HuangWHWHW/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":19,"created_at":"2015-08-04T03:32:20Z","updated_at":"2015-08-11T10:37:34Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/apache/flink/pulls/977","html_url":"https://github.com/apache/flink/pull/977","diff_url":"https://github.com/apache/flink/pull/977.diff","patch_url":"https://github.com/apache/flink/pull/977.patch"},"body":"Add tests for SocketClientSink.\r\n1.Test SocketClientSink open function:\r\nsetup a socket server --> using SocketClientSink to connect the server.\r\n2.Test SocketClientSink open and invoke function:\r\nsetup a socket server --> using SocketClientSink to connect the server and send a message."},"comment":{"url":"https://api.github.com/repos/apache/flink/issues/comments/129829151","html_url":"https://github.com/apache/flink/pull/977#issuecomment-129829151","issue_url":"https://api.github.com/repos/apache/flink/issues/977","id":129829151,"user":{"login":"StephanEwen","id":1727146,"avatar_url":"https://avatars.githubusercontent.com/u/1727146?v=3","gravatar_id":"","url":"https://api.github.com/users/StephanEwen","html_url":"https://github.com/StephanEwen","followers_url":"https://api.github.com/users/StephanEwen/followers","following_url":"https://api.github.com/users/StephanEwen/following{/other_user}","gists_url":"https://api.github.com/users/StephanEwen/gists{/gist_id}","starred_url":"https://api.github.com/users/StephanEwen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/StephanEwen/subscriptions","organizations_url":"https://api.github.com/users/StephanEwen/orgs","repos_url":"https://api.github.com/users/StephanEwen/repos","events_url":"https://api.github.com/users/StephanEwen/events{/privacy}","received_events_url":"https://api.github.com/users/StephanEwen/received_events","type":"User","site_admin":false},"created_at":"2015-08-11T10:37:34Z","updated_at":"2015-08-11T10:37:34Z","body":"Looks much better. Two more comments:\r\n\r\n1. 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:\r\n```java\r\ntry {\r\n  // some stuff\r\n} catch (Exception e) {\r\n  e.printStackTrace();\r\n  Assert.fail(e.getMessage());\r\n}\r\n```\r\nHere, the test prints nothing when working properly, but prints the error when it fails.\r\n\r\n2. `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.\r\n\r\nHere 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:\r\n```java\r\nfinal AtomicReference<Throwable> error = new AtomicReference<>();\r\nThread thread = new Thread(\"server thread\") {\r\n    @Override\r\n    public void run() {\r\n        try {\r\n            doStuff();\r\n        }\r\n        catch (Throwable t) {\r\n            ref.set(t);\r\n        }\r\n    }\r\n};\r\nthread.start();\r\n\r\n// do some test logic\r\n\r\nthread.join();\r\nif (error.get() != null) {\r\n    Throwable t = error.get();\r\n    t.printStackTrace();\r\n    fail(\"Error in spawned thread: \" + t.getMessage());\r\n}\r\n```\r\n\r\n"}}