From c07b777533cdbdfe4042258dbf44f2d9d51e3bc0 Mon Sep 17 00:00:00 2001 From: Xu Ha Date: Thu, 14 Aug 2014 16:40:59 -0700 Subject: [PATCH] fix duplicate error message bug and add large value size test for coordinator --- .../rest/coordinator/CoordinatorWorkerThread.java | 27 ++++--- .../coordinator/CoordinatorRestAPITest.java | 84 ++++++++++++++++++++-- 2 files changed, 91 insertions(+), 20 deletions(-) diff --git a/src/java/voldemort/rest/coordinator/CoordinatorWorkerThread.java b/src/java/voldemort/rest/coordinator/CoordinatorWorkerThread.java index d6548f324..5b254eb32 100644 --- a/src/java/voldemort/rest/coordinator/CoordinatorWorkerThread.java +++ b/src/java/voldemort/rest/coordinator/CoordinatorWorkerThread.java @@ -100,9 +100,9 @@ public class CoordinatorWorkerThread implements Runnable { REQUEST_TIMEOUT, "GET METADATA request timed out: " + e.getMessage()); + } else { + getErrorHandler.handleExceptions(messageEvent, e); } - - getErrorHandler.handleExceptions(messageEvent, e); } break; @@ -157,9 +157,9 @@ public class CoordinatorWorkerThread implements Runnable { REQUEST_TIMEOUT, "GET request timed out: " + e.getMessage()); + } else { + getErrorHandler.handleExceptions(messageEvent, e); } - - getErrorHandler.handleExceptions(messageEvent, e); } break; @@ -203,9 +203,9 @@ public class CoordinatorWorkerThread implements Runnable { REQUEST_TIMEOUT, "GET ALL request timed out: " + e.getMessage()); + } else { + getErrorHandler.handleExceptions(messageEvent, e); } - - getErrorHandler.handleExceptions(messageEvent, e); } break; @@ -234,9 +234,9 @@ public class CoordinatorWorkerThread implements Runnable { REQUEST_TIMEOUT, "GET VERSION request timed out: " + e.getMessage()); + } else { + getVersionErrorHandler.handleExceptions(messageEvent, e); } - - getVersionErrorHandler.handleExceptions(messageEvent, e); } break; @@ -278,9 +278,9 @@ public class CoordinatorWorkerThread implements Runnable { REQUEST_TIMEOUT, "PUT request timed out: " + e.getMessage()); + } else { + putErrorHandler.handleExceptions(messageEvent, e); } - - putErrorHandler.handleExceptions(messageEvent, e); } break; @@ -324,21 +324,18 @@ public class CoordinatorWorkerThread implements Runnable { 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; - } } - } - } } diff --git a/test/unit/voldemort/coordinator/CoordinatorRestAPITest.java b/test/unit/voldemort/coordinator/CoordinatorRestAPITest.java index a0eae63be..e49ee71ec 100644 --- a/test/unit/voldemort/coordinator/CoordinatorRestAPITest.java +++ b/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 @@ -138,6 +138,41 @@ public class CoordinatorRestAPITest { } } + 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); } @@ -306,8 +341,7 @@ public class CoordinatorRestAPITest { 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]; @@ -421,6 +455,46 @@ public class CoordinatorRestAPITest { } @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"; String payload = "Pliny the Younger"; -- 2.11.4.GIT