File tree Expand file tree Collapse file tree 2 files changed +18
-29
lines changed
main/java/org/embulk/output/sftp/utils
test/java/org/embulk/output/sftp/utils Expand file tree Collapse file tree 2 files changed +18
-29
lines changed Original file line number Diff line number Diff line change 11package org .embulk .output .sftp .utils ;
22
33import com .google .common .annotations .VisibleForTesting ;
4+ import com .google .common .base .Throwables ;
45
56import java .io .Closeable ;
7+ import java .util .concurrent .ExecutionException ;
68import java .util .concurrent .TimeUnit ;
9+ import java .util .concurrent .TimeoutException ;
710
811public class TimeoutCloser implements Closeable
912{
1013 @ VisibleForTesting
11- int timeout = 120 ;
14+ int timeout = 300 ; // 5 minutes
1215 private Closeable wrapped ;
1316
1417 public TimeoutCloser (Closeable wrapped )
@@ -19,16 +22,21 @@ public TimeoutCloser(Closeable wrapped)
1922 @ Override
2023 public void close ()
2124 {
22- new TimedCallable <Void >()
23- {
24- @ Override
25- public Void call () throws Exception
25+ try {
26+ new TimedCallable <Void >()
2627 {
27- if (wrapped != null ) {
28- wrapped .close ();
28+ @ Override
29+ public Void call () throws Exception
30+ {
31+ if (wrapped != null ) {
32+ wrapped .close ();
33+ }
34+ return null ;
2935 }
30- return null ;
31- }
32- }.callNonInterruptible (timeout , TimeUnit .SECONDS );
36+ }.call (timeout , TimeUnit .SECONDS );
37+ }
38+ catch (InterruptedException | ExecutionException | TimeoutException e ) {
39+ throw Throwables .propagate (e );
40+ }
3341 }
3442}
Original file line number Diff line number Diff line change 77import java .util .concurrent .TimeUnit ;
88import java .util .concurrent .TimeoutException ;
99
10- import static junit .framework .TestCase .fail ;
1110import static org .hamcrest .CoreMatchers .instanceOf ;
1211import static org .hamcrest .MatcherAssert .assertThat ;
1312
@@ -16,24 +15,6 @@ public class TestTimedCallable
1615 @ Rule
1716 public EmbulkTestRuntime runtime = new EmbulkTestRuntime ();
1817
19- @ Test
20- public void testCallNonInterruptible ()
21- {
22- try {
23- new TimedCallable <Void >()
24- {
25- @ Override
26- public Void call () throws Exception
27- {
28- throw new Exception ("Fake error" );
29- }
30- }.callNonInterruptible (1 , TimeUnit .SECONDS );
31- }
32- catch (Exception e ) {
33- fail ("Should not throw exception" );
34- }
35- }
36-
3718 @ Test
3819 public void testCallTimeout ()
3920 {
You can’t perform that action at this time.
0 commit comments