Skip to content

Commit 6c21554

Browse files
committed
Make HttpClientGitHubConnector the default for Java 11+
1 parent 988f603 commit 6c21554

File tree

5 files changed

+32
-9
lines changed

5 files changed

+32
-9
lines changed

pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,19 @@
825825
<argLine>@{jacoco.surefire.argLine} ${surefire.argLine} -Dtest.github.connector=httpclient</argLine>
826826
</configuration>
827827
</execution>
828+
<execution>
829+
<id>java11-urlconnection-test</id>
830+
<phase>integration-test</phase>
831+
<goals>
832+
<goal>test</goal>
833+
</goals>
834+
<configuration>
835+
<classesDirectory>${project.basedir}/target/github-api-${project.version}.jar</classesDirectory>
836+
<useSystemClassLoader>false</useSystemClassLoader>
837+
<excludesFile>src/test/resources/slow-or-flaky-tests.txt</excludesFile>
838+
<argLine>@{jacoco.surefire.argLine} ${surefire.argLine} -Dtest.github.connector=urlconnection</argLine>
839+
</configuration>
840+
</execution>
828841
</executions>
829842
</plugin>
830843
</plugins>

src/main/java/org/kohsuke/github/GitHubClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ public <T> GitHubResponse<T> sendRequest(GitHubRequest request, @CheckForNull Bo
391391
connectorRequest = e.connectorRequest;
392392
}
393393
} catch (SocketException | SocketTimeoutException | SSLHandshakeException e) {
394-
// These transient errors the
394+
// These transient errors thrown by HttpURLConnection
395395
if (retries > 0) {
396396
logRetryConnectionError(e, request.url(), retries);
397397
continue;

src/main/java/org/kohsuke/github/internal/DefaultGitHubConnector.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ static GitHubConnector create(String defaultConnectorProperty) {
5050
} else if (defaultConnectorProperty.equalsIgnoreCase("httpclient")) {
5151
return new HttpClientGitHubConnector();
5252
} else if (defaultConnectorProperty.equalsIgnoreCase("default")) {
53-
// try {
54-
// return new HttpClientGitHubConnector();
55-
// } catch (UnsupportedOperationException | LinkageError e) {
56-
return new GitHubConnectorHttpConnectorAdapter(HttpConnector.DEFAULT);
57-
// }
53+
try {
54+
return new HttpClientGitHubConnector();
55+
} catch (UnsupportedOperationException | LinkageError e) {
56+
return new GitHubConnectorHttpConnectorAdapter(HttpConnector.DEFAULT);
57+
}
5858
} else {
5959
throw new IllegalStateException(
6060
"Property 'test.github.connector' must reference a valid built-in connector - okhttp, okhttpconnector, urlconnection, or default.");

src/test/java/org/kohsuke/github/RequesterRetryTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
import com.github.tomakehurst.wiremock.stubbing.Scenario;
55
import okhttp3.ConnectionPool;
66
import okhttp3.OkHttpClient;
7+
import org.junit.Assume;
78
import org.junit.Before;
89
import org.junit.Ignore;
910
import org.junit.Test;
11+
import org.kohsuke.github.extras.HttpClientGitHubConnector;
1012
import org.kohsuke.github.extras.ImpatientHttpConnector;
1113
import org.kohsuke.github.extras.okhttp3.OkHttpGitHubConnector;
14+
import org.kohsuke.github.internal.DefaultGitHubConnector;
1215
import org.mockito.Mockito;
1316

1417
import java.io.ByteArrayOutputStream;
@@ -78,7 +81,7 @@ public void resetTestCapturedLog() throws IOException {
7881
attachLogCapturer();
7982
}
8083

81-
@Ignore("Used okhttp3 and this to verify connection closing. To variable for CI system.")
84+
@Ignore("Used okhttp3 and this to verify connection closing. Too flaky for CI system.")
8285
@Test
8386
public void testGitHubIsApiUrlValid() throws Exception {
8487

@@ -109,6 +112,9 @@ public void testGitHubIsApiUrlValid() throws Exception {
109112
// Issue #539
110113
@Test
111114
public void testSocketConnectionAndRetry() throws Exception {
115+
// Only implemented for HttpURLConnection connectors
116+
Assume.assumeThat(DefaultGitHubConnector.create(), not(instanceOf(HttpClientGitHubConnector.class)));
117+
112118
// CONNECTION_RESET_BY_PEER errors result in two requests each
113119
// to get this failure for "3" tries we have to do 6 queries.
114120
this.mockGitHub.apiServer()
@@ -136,6 +142,9 @@ public void testSocketConnectionAndRetry() throws Exception {
136142
// Issue #539
137143
@Test
138144
public void testSocketConnectionAndRetry_StatusCode() throws Exception {
145+
// Only implemented for HttpURLConnection connectors
146+
Assume.assumeThat(DefaultGitHubConnector.create(), not(instanceOf(HttpClientGitHubConnector.class)));
147+
139148
// CONNECTION_RESET_BY_PEER errors result in two requests each
140149
// to get this failure for "3" tries we have to do 6 queries.
141150
this.mockGitHub.apiServer()
@@ -164,6 +173,9 @@ public void testSocketConnectionAndRetry_StatusCode() throws Exception {
164173

165174
@Test
166175
public void testSocketConnectionAndRetry_Success() throws Exception {
176+
// Only implemented for HttpURLConnection connectors
177+
Assume.assumeThat(DefaultGitHubConnector.create(), not(instanceOf(HttpClientGitHubConnector.class)));
178+
167179
// CONNECTION_RESET_BY_PEER errors result in two requests each
168180
// to get this failure for "3" tries we have to do 6 queries.
169181
// If there are only 5 errors we succeed.

src/test/java/org/kohsuke/github/internal/DefaultGitHubConnectorTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ public void testCreate() throws Exception {
3737

3838
connector = DefaultGitHubConnector.create("default");
3939

40-
// Current implementation never uses httpclient for default.
41-
usingHttpClient = false;
4240
if (usingHttpClient) {
4341
assertThat(connector, instanceOf(HttpClientGitHubConnector.class));
4442
} else {

0 commit comments

Comments
 (0)