|
|
@@ -10,6 +10,7 @@ import static net.ranides.assira.io.uri.URIFlags.*;
|
|
|
import static net.ranides.assira.junit.NewAssert.*;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.net.SocketTimeoutException;
|
|
|
import java.net.URI;
|
|
|
import java.net.URISyntaxException;
|
|
|
import java.nio.charset.Charset;
|
|
|
@@ -200,6 +201,40 @@ public class CFTPHandlerTest {
|
|
|
handle1.close();
|
|
|
handle2.close();
|
|
|
}
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testTimeout() throws URISyntaxException, IOException {
|
|
|
+
|
|
|
+ URI u1 = new URI("ftp://user@ftp.ranides.net/readme.txt?timeout=750");
|
|
|
+ URI u2 = new URI("ftp://user@ftp.ranides.net/readme.txt?timeout=1");
|
|
|
+ URI u3 = new URI("ftp://user@ftp.ranides.net/readme.txt?timeout=2");
|
|
|
+ URI u4 = new URI("ftp://user@ftp.ranides.net/readme.txt?timeout=800");
|
|
|
+
|
|
|
+
|
|
|
+ URIHandle handle1 = re.resolve(u1);
|
|
|
+ URIHandle handle2 = re.resolve(u2);
|
|
|
+
|
|
|
+ // we will use timeout from "u1"
|
|
|
+ assertEquals(TEXT_1, IOStrings.read(handle1.reader()));
|
|
|
+ // we are already connected
|
|
|
+ // we won't use any timeout
|
|
|
+ assertEquals(TEXT_1, IOStrings.read(handle2.reader()));
|
|
|
+
|
|
|
+ handle1.close();
|
|
|
+ handle2.close();
|
|
|
+
|
|
|
+ URIHandle handle3 = re.resolve(u3);
|
|
|
+ URIHandle handle4 = re.resolve(u4);
|
|
|
+
|
|
|
+ // we will use timeout from "u3"
|
|
|
+ assertThrows(IOException.class, () -> {
|
|
|
+ assertEquals(TEXT_1, IOStrings.read(handle3.reader()));
|
|
|
+ });
|
|
|
+
|
|
|
+ // we are not connected yet
|
|
|
+ // we will use timeout from "u4"
|
|
|
+ assertEquals(TEXT_1, IOStrings.read(handle4.reader()));
|
|
|
+ }
|
|
|
|
|
|
@Test
|
|
|
public void testCopy() throws URISyntaxException, IOException {
|