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

Etienne Chauchot commented on BEAM-3158:
----------------------------------------

My bad, did not see that {{DoFnTester}} implements {{AutoCloseable}}. Using 
try-with-resources works with the {{ExpectedException}} indeed. Thanks! I'm 
closing this ticket.

> DoFnTester should call close() in catch bloc and then re-throw exception to 
> allow using @Rule ExpectedException
> ---------------------------------------------------------------------------------------------------------------
>
>                 Key: BEAM-3158
>                 URL: https://issues.apache.org/jira/browse/BEAM-3158
>             Project: Beam
>          Issue Type: Improvement
>          Components: testing
>            Reporter: Etienne Chauchot
>            Assignee: Etienne Chauchot
>            Priority: Minor
>
> In {{CLONE_ONCE}} and {{DO_NOT_CLONE}} cloning behaviors, it is required to 
> explicitly call {{DoFnTester.close()}}. If an exception is raised by the 
> DoFnTester, the user needs to use a try/catch bloc to call DoFnTester.close() 
> himself. If this DoFnTester were doing 
> {code}
> try{
> ...
> } catch(Exception e){
> close();
> throw e;
> }
> {code}
> then the user would no longer need to call {{DoFnTester.close()}} (to release 
> resources, stop threads ...) and thus no longer need the try/catch. This will 
> allow him to use the Junit {{@Rule ExpectedException}} in place of something 
> ugly like 
> {code}
> // need to avoid flow interruption to close the DoFnTester
>     Exception raisedException = null;
>     try {
>       fnTester.processBundle(input);
>     } catch (IOException exception) {
>       raisedException = exception;
>     }
>     fnTester.close();
>     assertTrue(raisedException != null);
> {code}
> But maybe {{DoFnTester}} cannot always be safely closed if a exception was 
> raised.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to