You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by vi...@apache.org on 2014/01/07 00:32:51 UTC
git commit: ACCUMULO-1933 Make unit on memory parameters
case-insensitive.
Updated Branches:
refs/heads/1.4.5-SNAPSHOT e946ba052 -> 65d5fba87
ACCUMULO-1933 Make unit on memory parameters case-insensitive.
1. Added support for both cases for G, M, K and B
2. Added warning message for lower case b and that the code will consider this bytes
3. Added meaningful error message for any number formatting issues
4. Added unit test that test 1 and 3 from above.
modified: src/core/src/main/java/org/apache/accumulo/core/conf/AccumuloConfiguration.java
new file: src/core/src/test/java/org/apache/accumulo/core/conf/AccumuloConfigurationTest.java
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/65d5fba8
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/65d5fba8
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/65d5fba8
Branch: refs/heads/1.4.5-SNAPSHOT
Commit: 65d5fba87830191844d3812d0ce3ca0a415be6e2
Parents: e946ba0
Author: tmalaska <te...@cloudera.com>
Authored: Thu Jan 2 15:43:08 2014 -0500
Committer: John Vines <vi...@apache.org>
Committed: Mon Jan 6 18:17:48 2014 -0500
----------------------------------------------------------------------
.../core/conf/AccumuloConfiguration.java | 35 +++++++++-----
.../core/conf/AccumuloConfigurationTest.java | 48 ++++++++++++++++++++
2 files changed, 72 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/65d5fba8/src/core/src/main/java/org/apache/accumulo/core/conf/AccumuloConfiguration.java
----------------------------------------------------------------------
diff --git a/src/core/src/main/java/org/apache/accumulo/core/conf/AccumuloConfiguration.java b/src/core/src/main/java/org/apache/accumulo/core/conf/AccumuloConfiguration.java
index ae123bc..1b046e2 100644
--- a/src/core/src/main/java/org/apache/accumulo/core/conf/AccumuloConfiguration.java
+++ b/src/core/src/main/java/org/apache/accumulo/core/conf/AccumuloConfiguration.java
@@ -50,17 +50,30 @@ public abstract class AccumuloConfiguration implements Iterable<Entry<String,Str
static public long getMemoryInBytes(String str) {
int multiplier = 0;
- switch (str.charAt(str.length() - 1)) {
- case 'G':
- multiplier += 10;
- case 'M':
- multiplier += 10;
- case 'K':
- multiplier += 10;
- case 'B':
- return Long.parseLong(str.substring(0, str.length() - 1)) << multiplier;
- default:
- return Long.parseLong(str);
+ char lastChar = str.charAt(str.length() - 1);
+
+ if (lastChar == 'b') {
+ log.warn("The 'b' in " + str +
+ " is being considered as bytes. " +
+ "Setting memory by bits is not supported");
+ }
+ try {
+ switch (Character.toUpperCase(lastChar)) {
+ case 'G':
+ multiplier += 10;
+ case 'M':
+ multiplier += 10;
+ case 'K':
+ multiplier += 10;
+ case 'B':
+ return Long.parseLong(str.substring(0, str.length() - 1)) << multiplier;
+ default:
+ return Long.parseLong(str);
+ }
+ } catch (Exception ex) {
+ throw new IllegalArgumentException("The value '" + str +
+ "' is not a valid memory setting. A valid value would a number " +
+ "possibily followed by an optional 'G', 'M', 'K', or 'B'.");
}
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/65d5fba8/src/core/src/test/java/org/apache/accumulo/core/conf/AccumuloConfigurationTest.java
----------------------------------------------------------------------
diff --git a/src/core/src/test/java/org/apache/accumulo/core/conf/AccumuloConfigurationTest.java b/src/core/src/test/java/org/apache/accumulo/core/conf/AccumuloConfigurationTest.java
new file mode 100644
index 0000000..a115215
--- /dev/null
+++ b/src/core/src/test/java/org/apache/accumulo/core/conf/AccumuloConfigurationTest.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.core.conf;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class AccumuloConfigurationTest {
+
+ @Test
+ public void testGetMemoryInBytes() throws Exception {
+ assertEquals(42l, AccumuloConfiguration.getMemoryInBytes("42"));
+ assertEquals(42l, AccumuloConfiguration.getMemoryInBytes("42b"));
+ assertEquals(42l, AccumuloConfiguration.getMemoryInBytes("42B"));
+ assertEquals(42l * 1024l, AccumuloConfiguration.getMemoryInBytes("42K"));
+ assertEquals(42l * 1024l, AccumuloConfiguration.getMemoryInBytes("42k"));
+ assertEquals(42l * 1024l * 1024l, AccumuloConfiguration.getMemoryInBytes("42M"));
+ assertEquals(42l * 1024l * 1024l, AccumuloConfiguration.getMemoryInBytes("42m"));
+ assertEquals(42l * 1024l * 1024l * 1024l, AccumuloConfiguration.getMemoryInBytes("42G"));
+ assertEquals(42l * 1024l * 1024l * 1024l, AccumuloConfiguration.getMemoryInBytes("42g"));
+
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testGetMemoryInBytesFailureCases1() throws Exception {
+ AccumuloConfiguration.getMemoryInBytes("42x");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testGetMemoryInBytesFailureCases2() throws Exception {
+ AccumuloConfiguration.getMemoryInBytes("FooBar");
+ }
+}
\ No newline at end of file