Skip to content

Commit 7ebdd87

Browse files
committed
Update unit test of time-out closer
1 parent 70a5429 commit 7ebdd87

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/test/java/org/embulk/output/sftp/utils/TestTimeoutCloser.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@
55
import org.junit.Test;
66

77
import java.io.Closeable;
8+
import java.util.concurrent.TimeoutException;
89

910
import static junit.framework.TestCase.fail;
10-
import static org.junit.Assert.assertTrue;
11+
import static org.hamcrest.CoreMatchers.instanceOf;
12+
import static org.hamcrest.MatcherAssert.assertThat;
1113

1214
public class TestTimeoutCloser
1315
{
1416
@Rule
1517
public EmbulkTestRuntime runtime = new EmbulkTestRuntime();
1618

1719
@Test
18-
public void testTimeoutAndResume()
20+
public void testTimeoutAndAbort()
1921
{
2022
TimeoutCloser closer = new TimeoutCloser(new Closeable()
2123
{
@@ -31,10 +33,13 @@ public void close()
3133
}
3234
});
3335
closer.timeout = 1;
34-
long start = System.currentTimeMillis();
35-
closer.close();
36-
long duration = System.currentTimeMillis() - start;
37-
assertTrue("longer than 1s", duration > 1000);
38-
assertTrue("shorter than 5s", duration < 5000);
36+
try {
37+
closer.close();
38+
fail("Should not finish");
39+
}
40+
catch (Exception e) {
41+
assertThat(e, instanceOf(RuntimeException.class));
42+
assertThat(e.getCause(), instanceOf(TimeoutException.class));
43+
}
3944
}
4045
}

0 commit comments

Comments
 (0)