accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ktur...@apache.org
Subject svn commit: r1480719 - in /accumulo/trunk/server/src: main/java/org/apache/accumulo/server/mini/ test/java/org/apache/accumulo/server/mini/
Date Thu, 09 May 2013 16:30:10 GMT
Author: kturner
Date: Thu May  9 16:30:09 2013
New Revision: 1480719

URL: http://svn.apache.org/r1480719
Log:
ACCUMULO-1357 added some since tags to MAConfig, made some of its methods public, made it
longs internally instead of strings, and made the names more consistent

Modified:
    accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/MemoryUnit.java
    accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/MiniAccumuloCluster.java
    accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/MiniAccumuloConfig.java
    accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/ServerType.java
    accumulo/trunk/server/src/test/java/org/apache/accumulo/server/mini/MiniAccumuloConfigTest.java

Modified: accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/MemoryUnit.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/MemoryUnit.java?rev=1480719&r1=1480718&r2=1480719&view=diff
==============================================================================
--- accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/MemoryUnit.java (original)
+++ accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/MemoryUnit.java Thu
May  9 16:30:09 2013
@@ -16,17 +16,22 @@
  */
 package org.apache.accumulo.server.mini;
 
+/**
+ * 
+ * @since 1.6.0
+ */
+
 public enum MemoryUnit {
   
-  BYTE(""), KILOBYTE("K"), MEGABYTE("M"), GIGABYTE("G"), TERABYTE("T");
+  BYTE(1l), KILOBYTE(1024l), MEGABYTE(1024 * 1024l), GIGABYTE(1024 * 1024 * 1024l);
   
-  private final String printVal;
+  private final long multiplier;
   
-  private MemoryUnit(String printVal) {
-    this.printVal = printVal;
+  private MemoryUnit(long multiplier) {
+    this.multiplier = multiplier;
   }
   
-  public String getPrintVal(long memory) {
-    return memory + printVal;
+  public long toBytes(long memory) {
+    return memory * multiplier;
   }
 }

Modified: accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/MiniAccumuloCluster.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/MiniAccumuloCluster.java?rev=1480719&r1=1480718&r2=1480719&view=diff
==============================================================================
--- accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/MiniAccumuloCluster.java
(original)
+++ accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/MiniAccumuloCluster.java
Thu May  9 16:30:09 2013
@@ -112,7 +112,7 @@ public class MiniAccumuloCluster {
   private MiniAccumuloConfig config;
   
   private Process exec(Class<? extends Object> clazz, String... args) throws IOException
{
-    return exec(clazz, Collections.singletonList("-Xmx" + config.getDefaultMemorySize()),
args);
+    return exec(clazz, Collections.singletonList("-Xmx" + config.getDefaultMemory()), args);
   }
   
   private Process exec(Class<? extends Object> clazz, List<String> extraJvmOpts,
String... args) throws IOException {
@@ -159,7 +159,7 @@ public class MiniAccumuloCluster {
   private Process exec(Class<? extends Object> clazz, ServerType serverType, String...
args) throws IOException {
     
     List<String> jvmOpts = new ArrayList<String>();
-    jvmOpts.add("-Xmx" + config.getMemoryConfig(serverType));
+    jvmOpts.add("-Xmx" + config.getMemory(serverType));
     
     if (config.isDebug()) {
       Integer port = PortUtils.getRandomFreePort();

Modified: accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/MiniAccumuloConfig.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/MiniAccumuloConfig.java?rev=1480719&r1=1480718&r2=1480719&view=diff
==============================================================================
--- accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/MiniAccumuloConfig.java
(original)
+++ accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/MiniAccumuloConfig.java
Thu May  9 16:30:09 2013
@@ -36,7 +36,7 @@ public class MiniAccumuloConfig {
   private String rootPassword = null;
   private Map<String,String> siteConfig = new HashMap<String,String>();
   private int numTservers = 2;
-  private Map<ServerType,String> memoryConfig = new HashMap<ServerType,String>();
+  private Map<ServerType,Long> memoryConfig = new HashMap<ServerType,Long>();
   
   private boolean debug = false;
   
@@ -50,7 +50,7 @@ public class MiniAccumuloConfig {
   private File walogDir;
   
   private Integer zooKeeperPort;
-  private String defaultMemorySize = "128M";
+  private long defaultMemorySize = 128 * 1024 * 1024;
   
   private boolean initialized = false;
   
@@ -189,7 +189,7 @@ public class MiniAccumuloConfig {
    * @since 1.6.0
    */
   public MiniAccumuloConfig setMemory(ServerType serverType, long memory, MemoryUnit memoryUnit)
{
-    this.memoryConfig.put(serverType, memoryUnit.getPrintVal(memory));
+    this.memoryConfig.put(serverType, memoryUnit.toBytes(memory));
     return this;
   }
   
@@ -204,8 +204,8 @@ public class MiniAccumuloConfig {
    * 
    * @since 1.6.0
    */
-  public MiniAccumuloConfig setDefaultMemorySize(long memory, MemoryUnit memoryUnit) {
-    this.defaultMemorySize = memoryUnit.getPrintVal(memory);
+  public MiniAccumuloConfig setDefaultMemory(long memory, MemoryUnit memoryUnit) {
+    this.defaultMemorySize = memoryUnit.toBytes(memory);
     return this;
   }
   
@@ -258,11 +258,23 @@ public class MiniAccumuloConfig {
     return walogDir;
   }
   
-  String getMemoryConfig(ServerType serverType) {
+  /**
+   * @param serverType get configuration for this server type
+   * 
+   * @return memory configured in bytes, returns default if this server type is not configured
+   * 
+   * @since 1.6.0
+   */
+  public long getMemory(ServerType serverType) {
     return memoryConfig.containsKey(serverType) ? memoryConfig.get(serverType) : defaultMemorySize;
   }
   
-  String getDefaultMemorySize() {
+  /**
+   * @return memory configured in bytes
+   * 
+   * @since 1.6.0
+   */
+  public long getDefaultMemory() {
     return defaultMemorySize;
   }
   

Modified: accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/ServerType.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/ServerType.java?rev=1480719&r1=1480718&r2=1480719&view=diff
==============================================================================
--- accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/ServerType.java (original)
+++ accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/ServerType.java Thu
May  9 16:30:09 2013
@@ -16,6 +16,11 @@
  */
 package org.apache.accumulo.server.mini;
 
+/**
+ * 
+ * @since 1.6.0
+ */
+
 public enum ServerType {
   MASTER, ZOOKEEPER, TABLET_SERVER
 }

Modified: accumulo/trunk/server/src/test/java/org/apache/accumulo/server/mini/MiniAccumuloConfigTest.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/server/src/test/java/org/apache/accumulo/server/mini/MiniAccumuloConfigTest.java?rev=1480719&r1=1480718&r2=1480719&view=diff
==============================================================================
--- accumulo/trunk/server/src/test/java/org/apache/accumulo/server/mini/MiniAccumuloConfigTest.java
(original)
+++ accumulo/trunk/server/src/test/java/org/apache/accumulo/server/mini/MiniAccumuloConfigTest.java
Thu May  9 16:30:09 2013
@@ -16,18 +16,18 @@
  */
 package org.apache.accumulo.server.mini;
 
-import org.apache.accumulo.core.conf.Property;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import org.apache.accumulo.core.conf.Property;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
 
 public class MiniAccumuloConfigTest {
 
@@ -64,10 +64,14 @@ public class MiniAccumuloConfigTest {
   public void testMemoryConfig() {
 
     MiniAccumuloConfig config = new MiniAccumuloConfig(tempFolder.getRoot(), "password").initialize();
-    config.setDefaultMemorySize(128, MemoryUnit.MEGABYTE);
-    assertEquals("128M", config.getMemoryConfig(ServerType.MASTER));
+    config.setDefaultMemory(96, MemoryUnit.MEGABYTE);
+    assertEquals(96 * 1024 * 1024l, config.getMemory(ServerType.MASTER));
+    assertEquals(96 * 1024 * 1024l, config.getMemory(ServerType.TABLET_SERVER));
+    assertEquals(96 * 1024 * 1024l, config.getDefaultMemory());
     config.setMemory(ServerType.MASTER, 256, MemoryUnit.MEGABYTE);
-    assertEquals("256M", config.getMemoryConfig(ServerType.MASTER));
+    assertEquals(256 * 1024 * 1024l, config.getMemory(ServerType.MASTER));
+    assertEquals(96 * 1024 * 1024l, config.getDefaultMemory());
+    assertEquals(96 * 1024 * 1024l, config.getMemory(ServerType.TABLET_SERVER));
   }
 
   @AfterClass



Mime
View raw message