Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
test: add timeout test
  • Loading branch information
chingor13 committed Aug 29, 2019
commit f4b7044ef5e8ea0535e634f7a4b4c8635d583dbe
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());
}
}
}