Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void addHeader(String name, String value) {

@Override
public void setTimeout(int connectTimeout, int readTimeout) throws IOException {
requestConfig.setConnectionRequestTimeout(connectTimeout)
requestConfig.setConnectTimeout(connectTimeout)
.setSocketTimeout(readTimeout);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.LowLevelHttpResponse;
import com.google.api.client.util.ByteArrayStreamingContent;
import java.io.IOException;
Expand All @@ -37,6 +39,7 @@
import org.apache.http.HttpVersion;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.conn.HttpHostConnectException;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicHttpResponse;
import org.apache.http.protocol.HttpContext;
Expand Down Expand Up @@ -175,4 +178,18 @@ public void process(HttpRequest request, HttpContext context)
}
assertTrue("Expected to have called our test interceptor", interceptorCalled.get());
}

@Test(timeout = 1000L)
public void testConnectTimeout() {
HttpTransport httpTransport = new ApacheHttpTransport();
GenericUrl url = new GenericUrl("http://google.com:81");
try {
httpTransport.createRequestFactory().buildGetRequest(url).setConnectTimeout(10).execute();
fail("should have thrown an exception");
} catch (HttpHostConnectException expected) {
// expected
} catch (IOException e) {
fail("unexpected IOException: " + e.getClass().getName());
}
}
}