accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e..@apache.org
Subject svn commit: r1495020 - in /accumulo/trunk: minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java server/src/main/java/org/apache/accumulo/server/ServerConstants.java test/src/main/java/org/apache/accumulo/test/VolumeTest.java
Date Thu, 20 Jun 2013 14:31:09 GMT
Author: ecn
Date: Thu Jun 20 14:31:09 2013
New Revision: 1495020

URL: http://svn.apache.org/r1495020
Log:
ACCUMULO-118 add unit test for multiple volumes

Added:
    accumulo/trunk/test/src/main/java/org/apache/accumulo/test/VolumeTest.java   (with props)
Modified:
    accumulo/trunk/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java
    accumulo/trunk/server/src/main/java/org/apache/accumulo/server/ServerConstants.java

Modified: accumulo/trunk/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java?rev=1495020&r1=1495019&r2=1495020&view=diff
==============================================================================
--- accumulo/trunk/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java
(original)
+++ accumulo/trunk/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java
Thu Jun 20 14:31:09 2013
@@ -32,6 +32,12 @@ import java.util.Map.Entry;
 import java.util.Properties;
 import java.util.Set;
 
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.client.Connector;
+import org.apache.accumulo.core.client.Instance;
+import org.apache.accumulo.core.client.ZooKeeperInstance;
+import org.apache.accumulo.core.client.security.tokens.PasswordToken;
 import org.apache.accumulo.core.util.Pair;
 import org.apache.accumulo.core.util.UtilWaitThread;
 import org.apache.accumulo.server.master.Master;
@@ -258,7 +264,7 @@ public class MiniAccumuloCluster {
 
     // sleep a little bit to let zookeeper come up before calling init, seems to work better
     UtilWaitThread.sleep(250);
-
+    
     Process initProcess = exec(Initialize.class, "--instance-name", config.getInstanceName(),
"--password", config.getRootPassword(), "--username", "root");
     int ret = initProcess.waitFor();
     if (ret != 0) {
@@ -328,4 +334,9 @@ public class MiniAccumuloCluster {
   public MiniAccumuloConfig getConfig() {
     return config;
   }
+
+  public Connector getConnector(String user, String passwd) throws AccumuloException, AccumuloSecurityException
{
+    Instance instance = new ZooKeeperInstance(this.getInstanceName(), this.getZooKeepers());
+    return instance.getConnector(user, new PasswordToken(passwd));
+  }
 }

Modified: accumulo/trunk/server/src/main/java/org/apache/accumulo/server/ServerConstants.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/server/src/main/java/org/apache/accumulo/server/ServerConstants.java?rev=1495020&r1=1495019&r2=1495020&view=diff
==============================================================================
--- accumulo/trunk/server/src/main/java/org/apache/accumulo/server/ServerConstants.java (original)
+++ accumulo/trunk/server/src/main/java/org/apache/accumulo/server/ServerConstants.java Thu
Jun 20 14:31:09 2013
@@ -50,6 +50,8 @@ public class ServerConstants {
   }
   
   public static String[] prefix(String bases[], String suffix) {
+    if (suffix.startsWith("/"))
+      suffix = suffix.substring(1);
     String result[] = new String[bases.length];
     for (int i = 0; i < bases.length; i++) {
       result[i] = bases[i] + "/" + suffix;
@@ -74,11 +76,11 @@ public class ServerConstants {
   }
   
   public static Path getInstanceIdLocation() {
-    return new Path(getBaseDirs()[0] + "/instance_id");
+    return new Path(getBaseDirs()[0], "instance_id");
   }
   
   public static Path getDataVersionLocation() {
-    return new Path(getBaseDirs()[0] + "/version");
+    return new Path(getBaseDirs()[0], "version");
   }
   
   public static String[] getMetadataTableDirs() {

Added: accumulo/trunk/test/src/main/java/org/apache/accumulo/test/VolumeTest.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/test/src/main/java/org/apache/accumulo/test/VolumeTest.java?rev=1495020&view=auto
==============================================================================
--- accumulo/trunk/test/src/main/java/org/apache/accumulo/test/VolumeTest.java (added)
+++ accumulo/trunk/test/src/main/java/org/apache/accumulo/test/VolumeTest.java Thu Jun 20
14:31:09 2013
@@ -0,0 +1,102 @@
+package org.apache.accumulo.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import org.apache.accumulo.core.client.BatchWriter;
+import org.apache.accumulo.core.client.BatchWriterConfig;
+import org.apache.accumulo.core.client.Connector;
+import org.apache.accumulo.core.client.Scanner;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Mutation;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.security.Authorizations;
+import org.apache.accumulo.core.util.MetadataTable;
+import org.apache.accumulo.minicluster.MiniAccumuloCluster;
+import org.apache.accumulo.minicluster.MiniAccumuloConfig;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.io.Text;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+public class VolumeTest {
+  
+  private static final Text EMPTY = new Text();
+  private static final Value EMPTY_VALUE = new Value(new byte[]{});
+  private static String secret = "superSecret";
+  public static TemporaryFolder folder = new TemporaryFolder();
+  public static MiniAccumuloCluster cluster;
+  public static Path v1;
+  public static Path v2;
+  
+  @BeforeClass
+  public static void setUpBeforeClass() throws Exception {
+    folder.create();
+    // Run MAC on two locations in the local file system
+    MiniAccumuloConfig cfg = new MiniAccumuloConfig(folder.newFolder("miniAccumulo"), secret);
+    Map<String,String> siteConfig = cfg.getSiteConfig();
+    v1 = new Path("file://" + folder.newFolder("v1").getAbsolutePath().toString());
+    v2 = new Path("file://" + folder.newFolder("v2").getAbsolutePath().toString());
+    siteConfig.put(Property.INSTANCE_VOLUMES.getKey(), v1.toString() + "," + v2.toString());
+    cfg.setSiteConfig(siteConfig);
+    cluster = new MiniAccumuloCluster(cfg);
+    cluster.start();
+  }
+  
+  @AfterClass
+  public static void tearDownAfterClass() throws Exception {
+    cluster.stop();
+    folder.delete();
+  }
+  
+  @Test
+  public void test() throws Exception {
+    // create a table
+    Connector connector = cluster.getConnector("root", secret);
+    String tableName = "test";
+    connector.tableOperations().create(tableName);
+    SortedSet<Text> partitions = new TreeSet<Text>();
+    // with some splits
+    for (String s : "d,m,t".split(","))
+      partitions.add(new Text(s));
+    connector.tableOperations().addSplits(tableName, partitions);
+    // scribble over the splits
+    BatchWriter bw = connector.createBatchWriter(tableName, new BatchWriterConfig());
+    String[] rows = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z".split(",");
+    for (String s : rows) {
+      Mutation m = new Mutation(new Text(s));
+      m.put(EMPTY, EMPTY, EMPTY_VALUE);
+      bw.addMutation(m);
+    }
+    bw.close();
+    // write the data to disk, read it back
+    connector.tableOperations().flush(tableName, null, null, true);
+    Scanner scanner = connector.createScanner(tableName, Authorizations.EMPTY);
+    int i = 0;
+    for (Entry<Key,Value> entry : scanner) {
+      assertEquals(rows[i++], entry.getKey().getRow().toString());
+    }
+    // verify the new files are written to the different volumes
+    scanner = connector.createScanner("!METADATA", Authorizations.EMPTY);
+    scanner.setRange(new Range("1", "1<"));
+    scanner.fetchColumnFamily(MetadataTable.DATAFILE_COLUMN_FAMILY);
+    int fileCount = 0;
+    for (Entry<Key,Value> entry : scanner) {
+      boolean inV1 = entry.getKey().getColumnQualifier().toString().contains(v1.toString());
+      boolean inV2 = entry.getKey().getColumnQualifier().toString().contains(v2.toString());

+      assertTrue(inV1 || inV2);
+      fileCount++;
+    }
+    assertEquals(4, fileCount);
+  }
+  
+}

Propchange: accumulo/trunk/test/src/main/java/org/apache/accumulo/test/VolumeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message