You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by ct...@apache.org on 2013/07/18 21:03:53 UTC

git commit: ACCUMULO-1579 Fix classpath issues and add plugin test with iterator

Updated Branches:
  refs/heads/master f8b9145d4 -> 3d7a6e71a


ACCUMULO-1579 Fix classpath issues and add plugin test with iterator


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

Branch: refs/heads/master
Commit: 3d7a6e71abea53485ef37b9e6e27134a722c6088
Parents: f8b9145
Author: Christopher Tubbs <ct...@apache.org>
Authored: Thu Jul 18 15:01:49 2013 -0400
Committer: Christopher Tubbs <ct...@apache.org>
Committed: Thu Jul 18 15:01:49 2013 -0400

----------------------------------------------------------------------
 maven-plugin/pom.xml                            |  4 ++
 .../src/it/plugin-test/postbuild.groovy         |  3 ++
 .../apache/accumulo/plugin/CustomFilter.java    | 33 +++++++++++++++
 .../org/apache/accumulo/plugin/PluginIT.java    | 44 ++++++++++++++++++--
 .../maven/plugin/AbstractAccumuloMojo.java      | 31 +++++++-------
 .../apache/accumulo/maven/plugin/StartMojo.java |  2 +
 .../apache/accumulo/maven/plugin/StopMojo.java  |  2 +
 pom.xml                                         |  7 +++-
 8 files changed, 108 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/3d7a6e71/maven-plugin/pom.xml
----------------------------------------------------------------------
diff --git a/maven-plugin/pom.xml b/maven-plugin/pom.xml
index 9060498..9a073c6 100644
--- a/maven-plugin/pom.xml
+++ b/maven-plugin/pom.xml
@@ -72,6 +72,10 @@
     </dependency>
     <dependency>
       <groupId>org.apache.maven</groupId>
+      <artifactId>maven-core</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
       <artifactId>maven-plugin-api</artifactId>
     </dependency>
     <dependency>

http://git-wip-us.apache.org/repos/asf/accumulo/blob/3d7a6e71/maven-plugin/src/it/plugin-test/postbuild.groovy
----------------------------------------------------------------------
diff --git a/maven-plugin/src/it/plugin-test/postbuild.groovy b/maven-plugin/src/it/plugin-test/postbuild.groovy
index 404961a..3fbfcab 100644
--- a/maven-plugin/src/it/plugin-test/postbuild.groovy
+++ b/maven-plugin/src/it/plugin-test/postbuild.groovy
@@ -22,3 +22,6 @@ assert testCreateTable.isFile()
 
 File testWriteToTable = new File(basedir, "target/accumulo-maven-plugin/plugin-it-instance/testWriteToTablePassed");
 assert testWriteToTable.isFile()
+
+File testCheckIterator = new File(basedir, "target/accumulo-maven-plugin/plugin-it-instance/testCheckIteratorPassed");
+assert testCheckIterator.isFile()

http://git-wip-us.apache.org/repos/asf/accumulo/blob/3d7a6e71/maven-plugin/src/it/plugin-test/src/main/java/org/apache/accumulo/plugin/CustomFilter.java
----------------------------------------------------------------------
diff --git a/maven-plugin/src/it/plugin-test/src/main/java/org/apache/accumulo/plugin/CustomFilter.java b/maven-plugin/src/it/plugin-test/src/main/java/org/apache/accumulo/plugin/CustomFilter.java
new file mode 100644
index 0000000..9a0497a
--- /dev/null
+++ b/maven-plugin/src/it/plugin-test/src/main/java/org/apache/accumulo/plugin/CustomFilter.java
@@ -0,0 +1,33 @@
+/*
+ * 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.plugin;
+
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.iterators.Filter;
+
+/**
+ * 
+ */
+public class CustomFilter extends Filter {
+  
+  @Override
+  public boolean accept(Key k, Value v) {
+    return k.getColumnFamily().toString().equals("allowed");
+  }
+  
+}

http://git-wip-us.apache.org/repos/asf/accumulo/blob/3d7a6e71/maven-plugin/src/it/plugin-test/src/test/java/org/apache/accumulo/plugin/PluginIT.java
----------------------------------------------------------------------
diff --git a/maven-plugin/src/it/plugin-test/src/test/java/org/apache/accumulo/plugin/PluginIT.java b/maven-plugin/src/it/plugin-test/src/test/java/org/apache/accumulo/plugin/PluginIT.java
index e4dee28..1e3fe37 100644
--- a/maven-plugin/src/it/plugin-test/src/test/java/org/apache/accumulo/plugin/PluginIT.java
+++ b/maven-plugin/src/it/plugin-test/src/test/java/org/apache/accumulo/plugin/PluginIT.java
@@ -29,6 +29,7 @@ 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.Instance;
+import org.apache.accumulo.core.client.IteratorSetting;
 import org.apache.accumulo.core.client.Scanner;
 import org.apache.accumulo.core.client.TableExistsException;
 import org.apache.accumulo.core.client.TableNotFoundException;
@@ -38,7 +39,6 @@ import org.apache.accumulo.core.data.Mutation;
 import org.apache.accumulo.core.data.Value;
 import org.apache.accumulo.core.security.Authorizations;
 import org.apache.accumulo.minicluster.MiniAccumuloInstance;
-import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
@@ -92,7 +92,45 @@ public class PluginIT {
     assertTrue(new File("target/accumulo-maven-plugin/" + instance.getInstanceName() + "/testWriteToTablePassed").createNewFile());
   }
   
-  @AfterClass
-  public static void tearDown() throws Exception {}
+  @Test
+  public void checkIterator() throws IOException, AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException {
+    String tableName = "checkIterator";
+    connector.tableOperations().create(tableName);
+    BatchWriter bw = connector.createBatchWriter(tableName, new BatchWriterConfig());
+    Mutation m = new Mutation("ROW1");
+    m.put("allowed", "CQ1", "V1");
+    m.put("denied", "CQ2", "V2");
+    m.put("allowed", "CQ3", "V3");
+    bw.addMutation(m);
+    m = new Mutation("ROW2");
+    m.put("allowed", "CQ1", "V1");
+    m.put("denied", "CQ2", "V2");
+    m.put("allowed", "CQ3", "V3");
+    bw.addMutation(m);
+    bw.close();
+    
+    // check filter
+    Scanner scanner = connector.createScanner(tableName, Authorizations.EMPTY);
+    IteratorSetting is = new IteratorSetting(5, CustomFilter.class);
+    scanner.addScanIterator(is);
+    int count = 0;
+    for (Entry<Key,Value> entry : scanner) {
+      count++;
+      assertEquals("allowed", entry.getKey().getColumnFamily().toString());
+    }
+    assertEquals(4, count);
+    
+    // check filter negated
+    scanner.clearScanIterators();
+    CustomFilter.setNegate(is, true);
+    scanner.addScanIterator(is);
+    count = 0;
+    for (Entry<Key,Value> entry : scanner) {
+      count++;
+      assertEquals("denied", entry.getKey().getColumnFamily().toString());
+    }
+    assertEquals(2, count);
+    assertTrue(new File("target/accumulo-maven-plugin/" + instance.getInstanceName() + "/testCheckIteratorPassed").createNewFile());
+  }
   
 }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/3d7a6e71/maven-plugin/src/main/java/org/apache/accumulo/maven/plugin/AbstractAccumuloMojo.java
----------------------------------------------------------------------
diff --git a/maven-plugin/src/main/java/org/apache/accumulo/maven/plugin/AbstractAccumuloMojo.java b/maven-plugin/src/main/java/org/apache/accumulo/maven/plugin/AbstractAccumuloMojo.java
index 7eb4acb..65174ed 100644
--- a/maven-plugin/src/main/java/org/apache/accumulo/maven/plugin/AbstractAccumuloMojo.java
+++ b/maven-plugin/src/main/java/org/apache/accumulo/maven/plugin/AbstractAccumuloMojo.java
@@ -18,32 +18,35 @@ package org.apache.accumulo.maven.plugin;
 
 import java.io.File;
 import java.net.MalformedURLException;
-import java.util.List;
 
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.plugin.AbstractMojo;
-import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.plugins.annotations.Component;
+import org.apache.maven.project.MavenProject;
 
 public abstract class AbstractAccumuloMojo extends AbstractMojo {
   
-  @Parameter(defaultValue = "${plugin.artifacts}", readonly = true, required = true)
-  private List<Artifact> pluginArtifacts;
+  @Component
+  private MavenProject project;
   
-  void configureMiniClasspath(String miniClasspath) {
+  void configureMiniClasspath(String miniClasspath) throws MalformedURLException {
     String classpath = "";
-    if (miniClasspath == null && pluginArtifacts != null) {
-      String sep = "";
-      for (Artifact artifact : pluginArtifacts) {
-        try {
-          classpath += sep + artifact.getFile().toURI().toURL();
-          sep = File.pathSeparator;
-        } catch (MalformedURLException e) {
-          e.printStackTrace();
-        }
+    StringBuilder sb = new StringBuilder();
+    if (miniClasspath == null && project != null) {
+      sb.append(project.getBuild().getOutputDirectory());
+      String sep = File.pathSeparator;
+      sb.append(sep).append(project.getBuild().getTestOutputDirectory());
+      for (Artifact artifact : project.getArtifacts()) {
+        addArtifact(sb, sep, artifact);
       }
+      classpath = sb.toString();
     } else if (miniClasspath != null && !miniClasspath.isEmpty()) {
       classpath = miniClasspath;
     }
     System.setProperty("java.class.path", System.getProperty("java.class.path", "") + File.pathSeparator + classpath);
   }
+  
+  private void addArtifact(StringBuilder classpath, String separator, Artifact artifact) throws MalformedURLException {
+    classpath.append(separator).append(artifact.getFile().toURI().toURL());
+  }
 }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/3d7a6e71/maven-plugin/src/main/java/org/apache/accumulo/maven/plugin/StartMojo.java
----------------------------------------------------------------------
diff --git a/maven-plugin/src/main/java/org/apache/accumulo/maven/plugin/StartMojo.java b/maven-plugin/src/main/java/org/apache/accumulo/maven/plugin/StartMojo.java
index b3efd81..9579952 100644
--- a/maven-plugin/src/main/java/org/apache/accumulo/maven/plugin/StartMojo.java
+++ b/maven-plugin/src/main/java/org/apache/accumulo/maven/plugin/StartMojo.java
@@ -23,6 +23,7 @@ import java.util.Set;
 
 import org.apache.accumulo.minicluster.MiniAccumuloCluster;
 import org.apache.accumulo.minicluster.MiniAccumuloConfig;
+import org.apache.http.annotation.ThreadSafe;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugins.annotations.LifecyclePhase;
 import org.apache.maven.plugins.annotations.Mojo;
@@ -33,6 +34,7 @@ import org.codehaus.plexus.util.FileUtils;
 /**
  * Goal which starts an instance of {@link MiniAccumuloCluster}.
  */
+@ThreadSafe
 @Mojo(name = "start", defaultPhase = LifecyclePhase.PRE_INTEGRATION_TEST, requiresDependencyResolution = ResolutionScope.TEST)
 public class StartMojo extends AbstractAccumuloMojo {
   

http://git-wip-us.apache.org/repos/asf/accumulo/blob/3d7a6e71/maven-plugin/src/main/java/org/apache/accumulo/maven/plugin/StopMojo.java
----------------------------------------------------------------------
diff --git a/maven-plugin/src/main/java/org/apache/accumulo/maven/plugin/StopMojo.java b/maven-plugin/src/main/java/org/apache/accumulo/maven/plugin/StopMojo.java
index ae1b7c0..70150ea 100644
--- a/maven-plugin/src/main/java/org/apache/accumulo/maven/plugin/StopMojo.java
+++ b/maven-plugin/src/main/java/org/apache/accumulo/maven/plugin/StopMojo.java
@@ -18,6 +18,7 @@ package org.apache.accumulo.maven.plugin;
 
 import org.apache.accumulo.minicluster.MiniAccumuloCluster;
 import org.apache.accumulo.minicluster.MiniAccumuloCluster.LogWriter;
+import org.apache.http.annotation.ThreadSafe;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugins.annotations.LifecyclePhase;
 import org.apache.maven.plugins.annotations.Mojo;
@@ -26,6 +27,7 @@ import org.apache.maven.plugins.annotations.ResolutionScope;
 /**
  * Goal which stops all instances of {@link MiniAccumuloCluster} started with the start mojo.
  */
+@ThreadSafe
 @Mojo(name = "stop", defaultPhase = LifecyclePhase.POST_INTEGRATION_TEST, requiresDependencyResolution = ResolutionScope.TEST)
 public class StopMojo extends AbstractAccumuloMojo {
   

http://git-wip-us.apache.org/repos/asf/accumulo/blob/3d7a6e71/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index edcaa16..6454ff3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -305,6 +305,11 @@
       </dependency>
       <dependency>
         <groupId>org.apache.maven</groupId>
+        <artifactId>maven-core</artifactId>
+        <version>${maven.min-version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.maven</groupId>
         <artifactId>maven-plugin-api</artifactId>
         <version>${maven.min-version}</version>
       </dependency>
@@ -670,7 +675,7 @@
             <configuration>
               <!--parallel>classes</parallel-->
               <perCoreThreadCount>false</perCoreThreadCount>
-              <threadCount>${accumulo.it.threads}</threadCount> 
+              <threadCount>${accumulo.it.threads}</threadCount>
               <redirectTestOutputToFile>true</redirectTestOutputToFile>
             </configuration>
           </execution>