You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by cu...@apache.org on 2010/12/09 20:47:34 UTC
svn commit: r1044108 - in /avro/trunk: CHANGES.txt
lang/java/src/java/org/apache/avro/ipc/HttpTransceiver.java
lang/java/src/test/java/org/apache/avro/TestProtocolHttp.java
Author: cutting
Date: Thu Dec 9 19:47:34 2010
New Revision: 1044108
URL: http://svn.apache.org/viewvc?rev=1044108&view=rev
Log:
AVRO-689. Java: Permit setting timeout of HttpTransceiver.
Modified:
avro/trunk/CHANGES.txt
avro/trunk/lang/java/src/java/org/apache/avro/ipc/HttpTransceiver.java
avro/trunk/lang/java/src/test/java/org/apache/avro/TestProtocolHttp.java
Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1044108&r1=1044107&r2=1044108&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Thu Dec 9 19:47:34 2010
@@ -22,6 +22,8 @@ Avro 1.5.0 (unreleased)
AVRO-684. Java: Add command-line "recodec" tool to change file
compression codecs. (Patrick Linehan via cutting)
+ AVRO-689. Java: Permit setting timeout of HttpTransceiver. (cutting)
+
IMPROVEMENTS
AVRO-682. Java: Add method DataFileStream.getMetaKeys().
Modified: avro/trunk/lang/java/src/java/org/apache/avro/ipc/HttpTransceiver.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/java/org/apache/avro/ipc/HttpTransceiver.java?rev=1044108&r1=1044107&r2=1044108&view=diff
==============================================================================
--- avro/trunk/lang/java/src/java/org/apache/avro/ipc/HttpTransceiver.java (original)
+++ avro/trunk/lang/java/src/java/org/apache/avro/ipc/HttpTransceiver.java Thu Dec 9 19:47:34 2010
@@ -34,9 +34,13 @@ public class HttpTransceiver extends Tra
private URL url;
private HttpURLConnection connection;
+ private int timeout;
public HttpTransceiver(URL url) { this.url = url; }
+ /** Set the connect and read timeouts, in milliseconds. */
+ public void setTimeout(int timeout) { this.timeout = timeout; }
+
public String getRemoteName() { return this.url.toString(); }
public synchronized List<ByteBuffer> readBuffers() throws IOException {
@@ -51,6 +55,8 @@ public class HttpTransceiver extends Tra
connection.setRequestProperty("Content-Length",
Integer.toString(getLength(buffers)));
connection.setDoOutput(true);
+ connection.setReadTimeout(timeout);
+ connection.setConnectTimeout(timeout);
writeBuffers(buffers, connection.getOutputStream());
}
Modified: avro/trunk/lang/java/src/test/java/org/apache/avro/TestProtocolHttp.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/test/java/org/apache/avro/TestProtocolHttp.java?rev=1044108&r1=1044107&r2=1044108&view=diff
==============================================================================
--- avro/trunk/lang/java/src/test/java/org/apache/avro/TestProtocolHttp.java (original)
+++ avro/trunk/lang/java/src/test/java/org/apache/avro/TestProtocolHttp.java Thu Dec 9 19:47:34 2010
@@ -22,9 +22,14 @@ import org.apache.avro.ipc.HttpTransceiv
import org.apache.avro.specific.SpecificRequestor;
import org.apache.avro.specific.SpecificResponder;
import org.apache.avro.test.Simple;
+
+import org.junit.Test;
import org.junit.Before;
import java.net.URL;
+import java.net.ServerSocket;
+import java.net.SocketTimeoutException;
+import java.lang.reflect.UndeclaredThrowableException;
public class TestProtocolHttp extends TestProtocolSpecific {
@@ -39,4 +44,20 @@ public class TestProtocolHttp extends Te
proxy = SpecificRequestor.getClient(Simple.class, client);
}
+ @Test(expected=SocketTimeoutException.class)
+ public void testTimeout() throws Throwable {
+ ServerSocket s = new ServerSocket(0);
+ HttpTransceiver client =
+ new HttpTransceiver(new URL("http://127.0.0.1:"+s.getLocalPort()+"/"));
+ client.setTimeout(100);
+ Simple proxy = SpecificRequestor.getClient(Simple.class, client);
+ try {
+ proxy.hello("foo");
+ } catch (UndeclaredThrowableException e) {
+ throw e.getCause();
+ } finally {
+ s.close();
+ }
+ }
+
}