Skip to content

Commit

Permalink
Fixed HTTP unit test
Browse files Browse the repository at this point in the history
The HTTP client was not being created before the tests. Thus several tests were throwing NullPointerExceptions. It broke as part of the move to httpclient 4.x.
  • Loading branch information
Robert Butler committed Jan 5, 2012
1 parent ce113ee commit f7d05f9
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions test/unit/voldemort/store/http/HttpStoreTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public void setUp() throws Exception {
RequestFormatType.VOLDEMORT_V1,
node.getHttpPort());
server = context.getServer();

ThreadSafeClientConnManager connectionManager = new ThreadSafeClientConnManager(SchemeRegistryFactory.createDefault(),
5000,
TimeUnit.MILLISECONDS);
httpClient = new DefaultHttpClient(connectionManager);
httpStore = ServerTestUtils.getHttpStore("users",
RequestFormatType.VOLDEMORT_V1,
node.getHttpPort(),
Expand All @@ -76,15 +81,15 @@ public <T extends Exception> void testBadUrlOrPort(String url, int port, Class<T
ByteArray key = new ByteArray("test".getBytes());
RequestFormat requestFormat = new RequestFormatFactory().getRequestFormat(RequestFormatType.VOLDEMORT_V1);

ThreadSafeClientConnManager connectionManager = new ThreadSafeClientConnManager(SchemeRegistryFactory.createDefault(),
5000,
TimeUnit.MILLISECONDS);

DefaultHttpClient client = new DefaultHttpClient(connectionManager);
HttpParams clientParams = client.getParams();
HttpParams clientParams = httpClient.getParams();
HttpConnectionParams.setConnectionTimeout(clientParams, 5000);

HttpStore badUrlHttpStore = new HttpStore("test", url, port, client, requestFormat, false);
HttpStore badUrlHttpStore = new HttpStore("test",
url,
port,
httpClient,
requestFormat,
false);
try {
badUrlHttpStore.put(key,
new Versioned<byte[]>("value".getBytes(), new VectorClock()),
Expand All @@ -102,8 +107,6 @@ public <T extends Exception> void testBadUrlOrPort(String url, int port, Class<T
} catch(Exception e) {
assertTrue(e.getClass().equals(expected));
}

client.getConnectionManager().shutdown();
}

public void testBadUrl() {
Expand Down

0 comments on commit f7d05f9

Please sign in to comment.