This repository has been archived by the owner on Apr 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 371
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from paradigmsort/fix_restartable
Fix RestartableHttpClient.
- Loading branch information
Showing
4 changed files
with
59 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
hbc-core/src/test/java/com/twitter/hbc/httpclient/RestartableHttpClientTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.twitter.hbc.httpclient; | ||
|
||
import com.twitter.hbc.httpclient.auth.Authentication; | ||
import java.net.UnknownHostException; | ||
import org.apache.http.client.methods.HttpGet; | ||
import org.apache.http.client.methods.HttpUriRequest; | ||
import org.apache.http.conn.scheme.SchemeRegistry; | ||
import org.apache.http.impl.conn.SchemeRegistryFactory; | ||
import org.apache.http.params.HttpParams; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import static org.junit.Assert.fail; | ||
import static org.mockito.Mockito.mock; | ||
|
||
public class RestartableHttpClientTest { | ||
private Authentication mockAuth; | ||
private SchemeRegistry defaultSchemeRegistry; | ||
private HttpParams mockParams; | ||
private HttpUriRequest request; | ||
|
||
@Before | ||
public void setup() throws Exception { | ||
mockAuth = mock(Authentication.class); | ||
mockParams = mock(HttpParams.class); | ||
defaultSchemeRegistry = SchemeRegistryFactory.createDefault(); | ||
request = new HttpGet("http://hi"); | ||
} | ||
|
||
@Test | ||
public void testRestart() throws Exception { | ||
RestartableHttpClient client = new RestartableHttpClient(mockAuth, true, mockParams, defaultSchemeRegistry); | ||
client.setup(); | ||
client.restart(); | ||
try { | ||
client.execute(request); // used to crash, https://github.com/twitter/hbc/issues/113 | ||
fail("should not reach here"); | ||
} catch (UnknownHostException e) { | ||
// expected | ||
} | ||
} | ||
} |