You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by ec...@apache.org on 2013/05/01 22:19:44 UTC

svn commit: r1478175 - in /accumulo/trunk: core/src/test/java/org/apache/accumulo/core/util/shell/ server/src/main/java/org/apache/accumulo/server/tabletserver/ server/src/main/java/org/apache/accumulo/server/util/ test/src/test/java/org/apache/accumul...

Author: ecn
Date: Wed May  1 20:19:44 2013
New Revision: 1478175

URL: http://svn.apache.org/r1478175
Log:
ACCUMULO-1334 add disk usage to the API

Added:
    accumulo/trunk/core/src/test/java/org/apache/accumulo/core/util/shell/TableDiskUsageTest.java   (with props)
Modified:
    accumulo/trunk/server/src/main/java/org/apache/accumulo/server/tabletserver/TabletServer.java
    accumulo/trunk/server/src/main/java/org/apache/accumulo/server/util/TableDiskUsage.java
    accumulo/trunk/test/src/test/java/org/apache/accumulo/test/ShellServerTest.java
    accumulo/trunk/test/src/test/java/org/apache/accumulo/test/TableOperationsIT.java
    accumulo/trunk/test/src/test/java/org/apache/accumulo/test/TabletServerIT.java

Added: accumulo/trunk/core/src/test/java/org/apache/accumulo/core/util/shell/TableDiskUsageTest.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/test/java/org/apache/accumulo/core/util/shell/TableDiskUsageTest.java?rev=1478175&view=auto
==============================================================================
--- accumulo/trunk/core/src/test/java/org/apache/accumulo/core/util/shell/TableDiskUsageTest.java (added)
+++ accumulo/trunk/core/src/test/java/org/apache/accumulo/core/util/shell/TableDiskUsageTest.java Wed May  1 20:19:44 2013
@@ -0,0 +1,39 @@
+/*
+ * 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.util.shell;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.accumulo.core.util.TableDiskUsage;
+import org.junit.Test;
+
+public class TableDiskUsageTest {
+  
+  @Test
+  public void testHumanReadableBytes() {
+    assertEquals("1000B", TableDiskUsage.humanReadableBytes(1000));
+    assertEquals(" 1.0K", TableDiskUsage.humanReadableBytes(1024));
+    assertEquals(" 1.5K", TableDiskUsage.humanReadableBytes(1024 + (1024 / 2)));
+    assertEquals("1024K", TableDiskUsage.humanReadableBytes(1024 * 1024 - 1));
+    assertEquals(" 1.0M", TableDiskUsage.humanReadableBytes(1024 * 1024));
+    assertEquals(" 1.5M", TableDiskUsage.humanReadableBytes(1024 * 1024 + (1024 * 1024 / 2)));
+    assertEquals("1024M", TableDiskUsage.humanReadableBytes(1073741823));
+    assertEquals(" 1.0G", TableDiskUsage.humanReadableBytes(1073741824));
+    assertEquals("1024G", TableDiskUsage.humanReadableBytes(1099511627775l));
+    assertEquals(" 1.0T", TableDiskUsage.humanReadableBytes(1099511627776l));
+  }
+}

Propchange: accumulo/trunk/core/src/test/java/org/apache/accumulo/core/util/shell/TableDiskUsageTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: accumulo/trunk/server/src/main/java/org/apache/accumulo/server/tabletserver/TabletServer.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/server/src/main/java/org/apache/accumulo/server/tabletserver/TabletServer.java?rev=1478175&r1=1478174&r2=1478175&view=diff
==============================================================================
--- accumulo/trunk/server/src/main/java/org/apache/accumulo/server/tabletserver/TabletServer.java (original)
+++ accumulo/trunk/server/src/main/java/org/apache/accumulo/server/tabletserver/TabletServer.java Wed May  1 20:19:44 2013
@@ -2129,7 +2129,7 @@ public class TabletServer extends Abstra
             throw new AccumuloSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
         }
         
-        Map<TreeSet<String>,Long> diskUsage = TableDiskUsage.getDiskUsage(getServerConfig().getConfiguration(), tables, fs, conn);
+        Map<TreeSet<String>,Long> diskUsage = TableDiskUsage.getDiskUsage(getServerConfig().getConfiguration(), tables, fs, conn, false);
         List<DiskUsage> retUsages = new ArrayList<DiskUsage>();
         for (Map.Entry<TreeSet<String>,Long> usageItem : diskUsage.entrySet()) {
           retUsages.add(new DiskUsage(new ArrayList<String>(usageItem.getKey()), usageItem.getValue()));

Modified: accumulo/trunk/server/src/main/java/org/apache/accumulo/server/util/TableDiskUsage.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/server/src/main/java/org/apache/accumulo/server/util/TableDiskUsage.java?rev=1478175&r1=1478174&r2=1478175&view=diff
==============================================================================
--- accumulo/trunk/server/src/main/java/org/apache/accumulo/server/util/TableDiskUsage.java (original)
+++ accumulo/trunk/server/src/main/java/org/apache/accumulo/server/util/TableDiskUsage.java Wed May  1 20:19:44 2013
@@ -42,7 +42,7 @@ public class TableDiskUsage {
     Opts opts = new Opts();
     opts.parseArgs(TableDiskUsage.class.getName(), args);
     Connector conn = opts.getConnector();
-    org.apache.accumulo.core.util.TableDiskUsage.printDiskUsage(DefaultConfiguration.getInstance(), opts.tables, fs, conn);
+    org.apache.accumulo.core.util.TableDiskUsage.printDiskUsage(DefaultConfiguration.getInstance(), opts.tables, fs, conn, false);
   }
   
 }

Modified: accumulo/trunk/test/src/test/java/org/apache/accumulo/test/ShellServerTest.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/test/src/test/java/org/apache/accumulo/test/ShellServerTest.java?rev=1478175&r1=1478174&r2=1478175&view=diff
==============================================================================
--- accumulo/trunk/test/src/test/java/org/apache/accumulo/test/ShellServerTest.java (original)
+++ accumulo/trunk/test/src/test/java/org/apache/accumulo/test/ShellServerTest.java Wed May  1 20:19:44 2013
@@ -112,10 +112,11 @@ public class ShellServerTest {
   static void assertGoodExit(String s, boolean stringPresent) {
     Shell.log.debug(output.get());
     assertEquals(shell.getExitCode(), 0);
-    if (s.length() > 0)
-      assertEquals(s + " present in " + output.get() + " was not " + stringPresent, stringPresent, output.get().contains(s));
-  }
-  
+
+  if (s.length() > 0)
+  assertEquals(s + " present in " + output.get() + " was not " + stringPresent, stringPresent, output.get().contains(s));
+}
+
   static void assertBadExit(String s, boolean stringPresent) {
     Shell.log.debug(output.get());
     assertTrue(shell.getExitCode() > 0);
@@ -123,16 +124,16 @@ public class ShellServerTest {
       assertEquals(s + " present in " + output.get() + " was not " + stringPresent, stringPresent, output.get().contains(s));
     shell.resetExitCode();
   }
-  
+
   @BeforeClass
   public static void setUpBeforeClass() throws Exception {
     folder.create();
     MiniAccumuloConfig cfg = new MiniAccumuloConfig(folder.newFolder("miniAccumulo"), secret);
     cluster = new MiniAccumuloCluster(cfg);
     cluster.start();
-    
+
     System.setProperty("HOME", folder.getRoot().getAbsolutePath());
-    
+
     // start the shell
     output = new TestOutputStream();
     shell = new Shell(new ConsoleReader(new FileInputStream(FileDescriptor.in), new OutputStreamWriter(output)));
@@ -145,14 +146,14 @@ public class ShellServerTest {
     // give the tracer some time to start
     UtilWaitThread.sleep(1000);
   }
-  
+
   @AfterClass
   public static void tearDownAfterClass() throws Exception {
     cluster.stop();
     traceProcess.destroy();
     folder.delete();
   }
-  
+
   @Test(timeout = 30000)
   public void exporttableImporttable() throws Exception {
     // exporttable / importtable
@@ -174,7 +175,6 @@ public class ShellServerTest {
     exec("deletetable -f t", true);
     exec("deletetable -f t2", true);
   }
-  
   private DistCp newDistCp() {
     try {
       @SuppressWarnings("unchecked")
@@ -221,7 +221,7 @@ public class ShellServerTest {
     exec("execfile " + file.getAbsolutePath(), true, Constants.VERSION, true);
     
   }
-  
+
   @Test(timeout = 30000)
   public void egrep() throws Exception {
     // egrep
@@ -239,6 +239,10 @@ public class ShellServerTest {
     make10();
     exec("flush -t t -w");
     exec("du t", true, " [t]", true);
+    output.clear();
+    shell.execCommand("du -h", false, false);
+    String o = output.get();
+    assertTrue(o.matches(".*\\s26[0-9]B\\s\\[t\\]\\n"));  // for some reason, there's 1-2 bytes of fluctuation
     exec("deletetable -f t");
   }
   

Modified: accumulo/trunk/test/src/test/java/org/apache/accumulo/test/TableOperationsIT.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/test/src/test/java/org/apache/accumulo/test/TableOperationsIT.java?rev=1478175&r1=1478174&r2=1478175&view=diff
==============================================================================
--- accumulo/trunk/test/src/test/java/org/apache/accumulo/test/TableOperationsIT.java (original)
+++ accumulo/trunk/test/src/test/java/org/apache/accumulo/test/TableOperationsIT.java Wed May  1 20:19:44 2013
@@ -31,9 +31,7 @@ import org.apache.accumulo.core.client.T
 import org.apache.accumulo.core.client.ZooKeeperInstance;
 import org.apache.accumulo.core.client.admin.DiskUsage;
 import org.apache.accumulo.core.client.security.tokens.PasswordToken;
-import org.apache.accumulo.core.security.CredentialHelper;
 import org.apache.accumulo.core.security.TablePermission;
-import org.apache.accumulo.core.security.thrift.TCredentials;
 import org.apache.accumulo.core.tabletserver.thrift.TabletClientService;
 import org.apache.thrift.TException;
 import org.apache.thrift.transport.TTransportException;
@@ -45,6 +43,7 @@ import org.junit.rules.TemporaryFolder;
 public class TableOperationsIT {
   
   static TemporaryFolder tempFolder = new TemporaryFolder();
+  static final String ROOT = "root";
   static final String ROOT_PASS = "password";
   
   static MiniAccumuloCluster accumuloCluster;
@@ -52,8 +51,6 @@ public class TableOperationsIT {
   static Connector connector;
   static TabletClientService.Client client;
   
-  static TCredentials creds;
-  
   @BeforeClass
   public static void startUp() throws IOException, AccumuloException, AccumuloSecurityException, TTransportException, InterruptedException {
     tempFolder.create();
@@ -62,8 +59,7 @@ public class TableOperationsIT {
     accumuloCluster.start();
     
     ZooKeeperInstance instance = new ZooKeeperInstance(accumuloCluster.getInstanceName(), accumuloCluster.getZooKeepers());
-    connector = instance.getConnector("root", ROOT_PASS.getBytes());
-    creds = CredentialHelper.create("root", new PasswordToken("password"), connector.getInstance().getInstanceID());
+    connector = instance.getConnector(ROOT, new PasswordToken(ROOT_PASS.getBytes()));
   }
   
   @Test
@@ -74,7 +70,7 @@ public class TableOperationsIT {
     assertEquals(0, (long) diskUsage.get(0).getUsage());
     assertEquals("table1", diskUsage.get(0).getTables().iterator().next());
 
-    connector.securityOperations().revokeTablePermission(creds.getPrincipal(), "table1", TablePermission.READ);
+    connector.securityOperations().revokeTablePermission(ROOT, "table1", TablePermission.READ);
     try {
       connector.tableOperations().getDiskUsage(Collections.singleton("table1"));
       fail("Should throw securityexception");

Modified: accumulo/trunk/test/src/test/java/org/apache/accumulo/test/TabletServerIT.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/test/src/test/java/org/apache/accumulo/test/TabletServerIT.java?rev=1478175&r1=1478174&r2=1478175&view=diff
==============================================================================
--- accumulo/trunk/test/src/test/java/org/apache/accumulo/test/TabletServerIT.java (original)
+++ accumulo/trunk/test/src/test/java/org/apache/accumulo/test/TabletServerIT.java Wed May  1 20:19:44 2013
@@ -16,8 +16,8 @@
  */
 package org.apache.accumulo.test;
 
-import static junit.framework.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
 
 import java.io.IOException;
 import java.util.Collections;
@@ -69,7 +69,7 @@ public class TabletServerIT {
     accumuloCluster.start();
     
     ZooKeeperInstance instance = new ZooKeeperInstance(accumuloCluster.getInstanceName(), accumuloCluster.getZooKeepers());
-    connector = instance.getConnector("root", ROOT_PASS.getBytes());
+    connector = instance.getConnector("root", new PasswordToken(ROOT_PASS.getBytes()));
     
     List<String> tservers = connector.instanceOperations().getTabletServers();
     client = ThriftUtil.getTServerClient(tservers.get(0), instance.getConfiguration());