Skip to content

Commit

Permalink
fix duplicate error message bug and add large value size test for coo…
Browse files Browse the repository at this point in the history
…rdinator
  • Loading branch information
Xu Ha committed Aug 18, 2014
1 parent 6644d32 commit c07b777
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 20 deletions.
27 changes: 12 additions & 15 deletions src/java/voldemort/rest/coordinator/CoordinatorWorkerThread.java
Expand Up @@ -100,9 +100,9 @@ public void run() {
REQUEST_TIMEOUT,
"GET METADATA request timed out: "
+ e.getMessage());
} else {
getErrorHandler.handleExceptions(messageEvent, e);
}

getErrorHandler.handleExceptions(messageEvent, e);
}
break;

Expand Down Expand Up @@ -157,9 +157,9 @@ public void run() {
REQUEST_TIMEOUT,
"GET request timed out: "
+ e.getMessage());
} else {
getErrorHandler.handleExceptions(messageEvent, e);
}

getErrorHandler.handleExceptions(messageEvent, e);
}
break;

Expand Down Expand Up @@ -203,9 +203,9 @@ public void run() {
REQUEST_TIMEOUT,
"GET ALL request timed out: "
+ e.getMessage());
} else {
getErrorHandler.handleExceptions(messageEvent, e);
}

getErrorHandler.handleExceptions(messageEvent, e);
}
break;

Expand Down Expand Up @@ -234,9 +234,9 @@ public void run() {
REQUEST_TIMEOUT,
"GET VERSION request timed out: "
+ e.getMessage());
} else {
getVersionErrorHandler.handleExceptions(messageEvent, e);
}

getVersionErrorHandler.handleExceptions(messageEvent, e);
}
break;

Expand Down Expand Up @@ -278,9 +278,9 @@ public void run() {
REQUEST_TIMEOUT,
"PUT request timed out: "
+ e.getMessage());
} else {
putErrorHandler.handleExceptions(messageEvent, e);
}

putErrorHandler.handleExceptions(messageEvent, e);
}

break;
Expand Down Expand Up @@ -324,21 +324,18 @@ public void run() {
REQUEST_TIMEOUT,
"DELETE request timed out: "
+ e.getMessage());
} else {
deleteErrorHandler.handleExceptions(messageEvent, e);
}

deleteErrorHandler.handleExceptions(messageEvent, e);
}
break;

default:
System.err.println("Illegal operation.");
return;

}

}

}

}
}
84 changes: 79 additions & 5 deletions test/unit/voldemort/coordinator/CoordinatorRestAPITest.java
@@ -1,12 +1,12 @@
/*
* Copyright 2013 LinkedIn, Inc
*
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
Expand Down Expand Up @@ -138,6 +138,41 @@ public void tearDown() throws Exception {
}
}

public static enum ValueType {
ALPHA,
ALPHANUMERIC,
NUMERIC
}

public static String generateRandomString(int length, ValueType type) {

StringBuffer buffer = new StringBuffer();
String characters = "";

switch(type) {

case ALPHA:
characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
break;

case ALPHANUMERIC:
characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
break;

case NUMERIC:
characters = "1234567890";
break;
}

int charactersLength = characters.length();

for(int i = 0; i < length; i++) {
double index = Math.random() * charactersLength;
buffer.append(characters.charAt((int) index));
}
return buffer.toString();
}

private VectorClock doPut(String key, String payload, VectorClock vc) {
return doPut(key, payload, vc, null);
}
Expand Down Expand Up @@ -306,8 +341,7 @@ private TestVersionedValue doGet(String key, Map<String, Object> options) {
assertEquals("The number of body parts expected is not 1", 1, mp.getCount());

MimeBodyPart part = (MimeBodyPart) mp.getBodyPart(0);
VectorClock vc =
RestUtils.deserializeVectorClock(part.getHeader(RestMessageHeaders.X_VOLD_VECTOR_CLOCK)[0]);
VectorClock vc = RestUtils.deserializeVectorClock(part.getHeader(RestMessageHeaders.X_VOLD_VECTOR_CLOCK)[0]);
int contentLength = Integer.parseInt(part.getHeader(RestMessageHeaders.CONTENT_LENGTH)[0]);
byte[] bodyPartBytes = new byte[contentLength];

Expand Down Expand Up @@ -420,6 +454,46 @@ public void testVersionedPut() {
}
}

@Test
public void testLargeValueSizeVersionedPut() {
String key = "amigo";
String payload = generateRandomString(new CoordinatorConfig().getHttpMessageDecoderMaxChunkSize() * 10,
ValueType.ALPHA);
String newPayload = generateRandomString(new CoordinatorConfig().getHttpMessageDecoderMaxChunkSize() * 10,
ValueType.ALPHA);

// 1. Do a put
doPut(key, payload, null);

// 2. Do a get on the same key
TestVersionedValue response = doGet(key, null);
if(response == null) {
fail("key does not exist after a put. ");
}
System.out.println("Received value: " + response.getValue());

// 3. Do a versioned put based on the version received previously
doPut(key, newPayload, response.getVc());

// 4. Do a get again on the same key
TestVersionedValue newResponse = doGet(key);
if(newResponse == null) {
fail("key does not exist after the versioned put. ");
}
assertEquals("Returned response does not have a higer version",
Occurred.AFTER,
newResponse.getVc().compare(response.getVc()));
assertEquals("Returned response does not have a higer version",
Occurred.BEFORE,
response.getVc().compare(newResponse.getVc()));

System.out.println("Received value after the Versioned put: " + newResponse.getValue());
if(!newResponse.getValue().equals(newPayload)) {
fail("Received value is incorrect ! Expected : " + newPayload + " but got : "
+ newResponse.getValue());
}
}

@Test
public void testWriteWithTimeout() {
String key = "Which_Imperial_IPA_do_I_want_to_drink";
Expand Down

0 comments on commit c07b777

Please sign in to comment.