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/10/17 22:11:23 UTC

git commit: ACCUMULO-1451 add functional test of the configurability of the compaction strategy

Updated Branches:
  refs/heads/master 656a3614e -> 9f9917ca4


ACCUMULO-1451 add functional test of the configurability of the compaction strategy


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/9f9917ca
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/9f9917ca
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/9f9917ca

Branch: refs/heads/master
Commit: 9f9917ca4b8f6d1bcce96d586c38c74d37c4dfd2
Parents: 656a361
Author: Eric Newton <er...@gmail.com>
Authored: Thu Oct 17 16:11:43 2013 -0400
Committer: Eric Newton <er...@gmail.com>
Committed: Thu Oct 17 16:11:43 2013 -0400

----------------------------------------------------------------------
 .../test/TestConfigurableMajorCompactionIT.java | 123 +++++++++++++++++++
 1 file changed, 123 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/9f9917ca/test/src/test/java/org/apache/accumulo/test/TestConfigurableMajorCompactionIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/TestConfigurableMajorCompactionIT.java b/test/src/test/java/org/apache/accumulo/test/TestConfigurableMajorCompactionIT.java
new file mode 100644
index 0000000..1d33666
--- /dev/null
+++ b/test/src/test/java/org/apache/accumulo/test/TestConfigurableMajorCompactionIT.java
@@ -0,0 +1,123 @@
+/*
+ * 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.test;
+
+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 java.util.Map.Entry;
+
+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.Value;
+import org.apache.accumulo.core.metadata.MetadataTable;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema;
+import org.apache.accumulo.core.security.Authorizations;
+import org.apache.accumulo.fate.util.UtilWaitThread;
+import org.apache.accumulo.minicluster.MiniAccumuloConfig;
+import org.apache.accumulo.server.tabletserver.compaction.CompactionPass;
+import org.apache.accumulo.server.tabletserver.compaction.CompactionPlan;
+import org.apache.accumulo.server.tabletserver.compaction.CompactionStrategy;
+import org.apache.accumulo.server.tabletserver.compaction.DefaultWriter;
+import org.apache.accumulo.server.tabletserver.compaction.MajorCompactionRequest;
+import org.apache.accumulo.test.functional.ConfigurableMacIT;
+import org.junit.Test;
+
+public class TestConfigurableMajorCompactionIT extends ConfigurableMacIT {
+  
+  @Override
+  public void configure(MiniAccumuloConfig cfg) {
+    Map<String,String> siteConfig = new HashMap<String, String>();
+    siteConfig.put(Property.TSERV_MAJC_DELAY.getKey(), "1s");
+    cfg.setSiteConfig(siteConfig);
+  }
+
+  public static class TestCompactionStrategy implements CompactionStrategy {
+    @Override
+    public void gatherInformation(MajorCompactionRequest request) throws IOException {
+    }
+
+    @Override
+    public CompactionPlan getCompactionPlan(MajorCompactionRequest request) throws IOException {
+      CompactionPlan plan = new CompactionPlan();
+      if (request.getFiles().size() == 5) {
+        CompactionPass pass = new CompactionPass();
+        pass.inputFiles.addAll(request.getFiles().keySet());
+        plan.passes.add(pass);
+      }
+      return plan;
+    }
+
+    @Override
+    public Writer getCompactionWriter() {
+      return new DefaultWriter();
+    }
+  }
+  
+  
+  
+  @Test(timeout = 20 * 1000)
+  public void test() throws Exception {
+    Connector conn = getConnector();
+    String tableName = "test";
+    conn.tableOperations().create(tableName);
+    conn.tableOperations().setProperty(tableName, Property.TABLE_COMPACTION_STRATEGY.getKey(), TestCompactionStrategy.class.getName());
+    writeFile(conn, tableName);
+    writeFile(conn, tableName);
+    writeFile(conn, tableName);
+    writeFile(conn, tableName);
+    UtilWaitThread.sleep(2*1000);
+    assertEquals(4, countFiles(conn));
+    writeFile(conn, tableName);
+    int count = countFiles(conn);
+    assertTrue(count == 1 || count == 5);
+    while (count != 1) {
+      UtilWaitThread.sleep(250);
+      count = countFiles(conn);
+    }
+  }
+
+  private int countFiles(Connector conn) throws Exception {
+    Scanner s = conn.createScanner(MetadataTable.NAME, Authorizations.EMPTY);
+    s.setRange(MetadataSchema.TabletsSection.getRange());
+    s.fetchColumnFamily(MetadataSchema.TabletsSection.DataFileColumnFamily.NAME);
+    int count = 0;
+    for (@SuppressWarnings("unused") Entry<Key,Value> entry : s)
+      count++;
+    return count;
+  }
+
+
+
+  private void writeFile(Connector conn, String tableName) throws Exception {
+    BatchWriter bw = conn.createBatchWriter(tableName, new BatchWriterConfig());
+    Mutation m = new Mutation("row");
+    m.put("cf", "cq", "value");
+    bw.addMutation(m);
+    bw.close();
+    conn.tableOperations().flush(tableName, null, null, true);
+  }
+  
+}