aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/remote/blobstore/http
diff options
context:
space:
mode:
authorGravatar Jakob Buchgraber <buchgr@google.com>2018-03-22 05:37:32 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-03-22 05:39:17 -0700
commitd2ab0cecb823ceed4525d3ab3d917418076bec59 (patch)
treeeaae7f813dc83667181cb9f6969104131d2c2862 /src/test/java/com/google/devtools/build/lib/remote/blobstore/http
parent561274e8183ff22dfe2614b77cc8c2217d0fa846 (diff)
remote/http: properly support read timeout
Also, remove unused SO_TIMEOUT. Fixes #4890 cc @benjaminp Closes #4895. PiperOrigin-RevId: 190051030
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/remote/blobstore/http')
-rw-r--r--src/test/java/com/google/devtools/build/lib/remote/blobstore/http/HttpBlobStoreTest.java41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/remote/blobstore/http/HttpBlobStoreTest.java b/src/test/java/com/google/devtools/build/lib/remote/blobstore/http/HttpBlobStoreTest.java
index 7854cb53e7..6850f9e17d 100644
--- a/src/test/java/com/google/devtools/build/lib/remote/blobstore/http/HttpBlobStoreTest.java
+++ b/src/test/java/com/google/devtools/build/lib/remote/blobstore/http/HttpBlobStoreTest.java
@@ -32,6 +32,7 @@ import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandler.Sharable;
+import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
@@ -49,8 +50,10 @@ import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.codec.http.HttpUtil;
import io.netty.handler.codec.http.HttpVersion;
+import io.netty.handler.timeout.ReadTimeoutException;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.net.ConnectException;
import java.net.URI;
import java.util.HashMap;
import java.util.List;
@@ -82,6 +85,44 @@ public class HttpBlobStoreTest {
return ((ServerSocketChannel) sb.bind("localhost", 0).sync().channel());
}
+ @Test(expected = ConnectException.class, timeout = 30000)
+ public void timeoutShouldWork_connect() throws Exception {
+ ServerSocketChannel server = startServer(new ChannelHandlerAdapter() {});
+ int serverPort = server.localAddress().getPort();
+ closeServerChannel(server);
+
+ Credentials credentials = newCredentials();
+ HttpBlobStore blobStore =
+ new HttpBlobStore(new URI("http://localhost:" + serverPort), 5, credentials);
+ blobStore.get("key", new ByteArrayOutputStream());
+ fail("Exception expected");
+ }
+
+ @Test(expected = ReadTimeoutException.class, timeout = 30000)
+ public void timeoutShouldWork_read() throws Exception {
+ ServerSocketChannel server = null;
+ try {
+ server =
+ startServer(
+ new SimpleChannelInboundHandler<FullHttpRequest>() {
+ @Override
+ protected void channelRead0(
+ ChannelHandlerContext channelHandlerContext, FullHttpRequest fullHttpRequest) {
+ // Don't respond and force a client timeout.
+ }
+ });
+ int serverPort = server.localAddress().getPort();
+
+ Credentials credentials = newCredentials();
+ HttpBlobStore blobStore =
+ new HttpBlobStore(new URI("http://localhost:" + serverPort), 5, credentials);
+ blobStore.get("key", new ByteArrayOutputStream());
+ fail("Exception expected");
+ } finally {
+ closeServerChannel(server);
+ }
+ }
+
@Test
public void expiredAuthTokensShouldBeRetried_get() throws Exception {
expiredAuthTokensShouldBeRetried_get(ErrorType.UNAUTHORIZED);