Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Http 4.x upgrade fix #64

Merged
merged 2 commits into from

2 participants

@roberttheiv

Two test cases were failing after the latest upgrade from httpclient 3.x to 4.x.

1) HttpStoreTest wasn't initializing the httpclient at setup which was causing most tests to throw a NullPointerException

2) The HttpStoreSwapper was incorrectly passing the parameters to the HttpPost via HttpParams instead of setting the entity with URL encoded parameters.

roberttheiv added some commits
@roberttheiv roberttheiv Fixed HTTP unit test
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.
f7d05f9
@roberttheiv roberttheiv Fixed HttpStoreSwapper
The parameters were being passed incorrectly via POST methods over HTTP.
d2694cf
@afeinberg afeinberg merged commit aee112d into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 5, 2012
  1. @roberttheiv

    Fixed HTTP unit test

    roberttheiv authored
    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.
  2. @roberttheiv

    Fixed HttpStoreSwapper

    roberttheiv authored
    The parameters were being passed incorrectly via POST methods over HTTP.
This page is out of date. Refresh to see the latest.
View
59 src/java/voldemort/store/readonly/swapper/HttpStoreSwapper.java
@@ -3,6 +3,7 @@
import java.io.File;
import java.io.InputStream;
import java.net.HttpURLConnection;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -12,9 +13,11 @@
import java.util.concurrent.Future;
import org.apache.http.HttpResponse;
+import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
-import org.apache.http.params.HttpParams;
+import org.apache.http.message.BasicNameValuePair;
import org.apache.log4j.Logger;
import voldemort.VoldemortException;
@@ -70,13 +73,15 @@ public HttpStoreSwapper(Cluster cluster,
public String call() throws Exception {
String url = node.getHttpUrl() + "/" + readOnlyMgmtPath;
HttpPost post = new HttpPost(url);
- HttpParams params = post.getParams();
- params.setParameter("operation", "fetch");
+
+ List<NameValuePair> params = new ArrayList<NameValuePair>();
+ params.add(new BasicNameValuePair("operation", "fetch"));
String storeDir = basePath + "/node-" + node.getId();
- params.setParameter("dir", storeDir);
- params.setParameter("store", storeName);
+ params.add(new BasicNameValuePair("dir", storeDir));
+ params.add(new BasicNameValuePair("store", storeName));
if(pushVersion > 0)
- params.setParameter("pushVersion", Long.toString(pushVersion));
+ params.add(new BasicNameValuePair("pushVersion", Long.toString(pushVersion)));
+ post.setEntity(new UrlEncodedFormEntity(params));
logger.info("Invoking fetch for node " + node.getId() + " for " + storeDir);
@@ -127,10 +132,13 @@ public String call() throws Exception {
String url = cluster.getNodeById(successfulNodeId).getHttpUrl() + "/"
+ readOnlyMgmtPath;
HttpPost post = new HttpPost(url);
- HttpParams params = post.getParams();
- params.setParameter("operation", "failed-fetch");
- params.setParameter("dir", results.get(successfulNodeId));
- params.setParameter("store", storeName);
+
+ List<NameValuePair> params = new ArrayList<NameValuePair>();
+ params.add(new BasicNameValuePair("operation", "failed-fetch"));
+ params.add(new BasicNameValuePair("dir", results.get(successfulNodeId)));
+ params.add(new BasicNameValuePair("store", storeName));
+ post.setEntity(new UrlEncodedFormEntity(params));
+
logger.info("Deleting fetched data from node " + successfulNodeId);
httpResponse = httpClient.execute(post);
@@ -175,12 +183,14 @@ public void invokeSwap(final String storeName, final List<String> fetchFiles) {
try {
String url = node.getHttpUrl() + "/" + readOnlyMgmtPath;
HttpPost post = new HttpPost(url);
- HttpParams params = post.getParams();
- params.setParameter("operation", "swap");
+
+ List<NameValuePair> params = new ArrayList<NameValuePair>();
+ params.add(new BasicNameValuePair("operation", "swap"));
String dir = fetchFiles.get(node.getId());
logger.info("Attempting swap for node " + node.getId() + " dir = " + dir);
- params.setParameter("dir", dir);
- params.setParameter("store", storeName);
+ params.add(new BasicNameValuePair("dir", dir));
+ params.add(new BasicNameValuePair("store", storeName));
+ post.setEntity(new UrlEncodedFormEntity(params));
httpResponse = httpClient.execute(post);
int responseCode = httpResponse.getStatusLine().getStatusCode();
@@ -211,11 +221,13 @@ public void invokeSwap(final String storeName, final List<String> fetchFiles) {
String url = cluster.getNodeById(successfulNodeId).getHttpUrl() + "/"
+ readOnlyMgmtPath;
HttpPost post = new HttpPost(url);
- HttpParams params = post.getParams();
- params.setParameter("operation", "rollback");
- params.setParameter("store", storeName);
- params.setParameter("pushVersion",
- Long.toString(ReadOnlyUtils.getVersionId(new File(previousDirs.get(successfulNodeId)))));
+
+ List<NameValuePair> params = new ArrayList<NameValuePair>();
+ params.add(new BasicNameValuePair("operation", "rollback"));
+ params.add(new BasicNameValuePair("store", storeName));
+ params.add(new BasicNameValuePair("pushVersion",
+ Long.toString(ReadOnlyUtils.getVersionId(new File(previousDirs.get(successfulNodeId))))));
+ post.setEntity(new UrlEncodedFormEntity(params));
logger.info("Rolling back data on successful node " + successfulNodeId);
@@ -260,11 +272,12 @@ public void invokeRollback(String storeName, final long pushVersion) {
+ storeName);
String url = node.getHttpUrl() + "/" + readOnlyMgmtPath;
HttpPost post = new HttpPost(url);
- HttpParams params = post.getParams();
- params.setParameter("operation", "rollback");
- params.setParameter("store", storeName);
- params.setParameter("pushVersion", Long.toString(pushVersion));
+ List<NameValuePair> params = new ArrayList<NameValuePair>();
+ params.add(new BasicNameValuePair("operation", "rollback"));
+ params.add(new BasicNameValuePair("store", storeName));
+ params.add(new BasicNameValuePair("pushVersion", Long.toString(pushVersion)));
+ post.setEntity(new UrlEncodedFormEntity(params));
httpResponse = httpClient.execute(post);
int responseCode = httpResponse.getStatusLine().getStatusCode();
View
21 test/unit/voldemort/store/http/HttpStoreTest.java
@@ -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(),
@@ -76,15 +81,15 @@ public void setUp() throws Exception {
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()),
@@ -102,8 +107,6 @@ public void setUp() throws Exception {
} catch(Exception e) {
assertTrue(e.getClass().equals(expected));
}
-
- client.getConnectionManager().shutdown();
}
public void testBadUrl() {
Something went wrong with that request. Please try again.