This is an automated email from the ASF dual-hosted git repository.

dlmarion pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/accumulo-access.git


The following commit(s) were added to refs/heads/main by this push:
     new 4c79bae  Add Accumulo 3.0 ColViz & VisibilityEvaluator to benchmark 
(#69)
4c79bae is described below

commit 4c79bae6f5084d46e25f26b17925d09254fc11c0
Author: Dave Marion <[email protected]>
AuthorDate: Mon Jul 8 08:10:39 2024 -0400

    Add Accumulo 3.0 ColViz & VisibilityEvaluator to benchmark (#69)
---
 pom.xml                                            |  6 ++
 .../accumulo/access/AccessExpressionBenchmark.java | 75 +++++++++++++++++++++-
 2 files changed, 80 insertions(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 0e23f48..a7ca5b9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -122,6 +122,12 @@
       <version>${version.gson}</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.apache.accumulo</groupId>
+      <artifactId>accumulo-core</artifactId>
+      <version>3.0.0</version>
+      <scope>test</scope>
+    </dependency>
     <dependency>
       <groupId>org.junit.jupiter</groupId>
       <artifactId>junit-jupiter-api</artifactId>
diff --git 
a/src/test/java/org/apache/accumulo/access/AccessExpressionBenchmark.java 
b/src/test/java/org/apache/accumulo/access/AccessExpressionBenchmark.java
index 1c3f4a4..5940b5d 100644
--- a/src/test/java/org/apache/accumulo/access/AccessExpressionBenchmark.java
+++ b/src/test/java/org/apache/accumulo/access/AccessExpressionBenchmark.java
@@ -28,6 +28,9 @@ import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
+import org.apache.accumulo.core.security.ColumnVisibility;
+import org.apache.accumulo.core.security.VisibilityEvaluator;
+import org.apache.accumulo.core.security.VisibilityParseException;
 import org.openjdk.jmh.annotations.Benchmark;
 import org.openjdk.jmh.annotations.Mode;
 import org.openjdk.jmh.annotations.Scope;
@@ -57,6 +60,12 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
  */
 public class AccessExpressionBenchmark {
 
+  public static class VisibilityEvaluatorTests {
+    List<VisibilityEvaluator> evaluator;
+    List<byte[]> expressions;
+    List<ColumnVisibility> columnVisibilities;
+  }
+
   public static class EvaluatorTests {
     AccessEvaluator evaluator;
 
@@ -72,6 +81,8 @@ public class AccessExpressionBenchmark {
 
     private ArrayList<EvaluatorTests> evaluatorTests;
 
+    private ArrayList<VisibilityEvaluatorTests> visibilityEvaluatorTests;
+
     @SuppressFBWarnings(value = {"UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD"},
         justification = "Field is written by Gson")
     @Setup
@@ -80,8 +91,28 @@ public class AccessExpressionBenchmark {
       allTestExpressions = new ArrayList<>();
       allTestExpressionsStr = new ArrayList<>();
       evaluatorTests = new ArrayList<>();
+      visibilityEvaluatorTests = new ArrayList<>();
 
       for (var testDataSet : testData) {
+
+        // Create old
+        VisibilityEvaluatorTests vet = new VisibilityEvaluatorTests();
+        vet.expressions = new ArrayList<>();
+        vet.columnVisibilities = new ArrayList<>();
+
+        if (testDataSet.auths.length == 1) {
+          vet.evaluator = List.of(new VisibilityEvaluator(
+              new 
org.apache.accumulo.core.security.Authorizations(testDataSet.auths[0])));
+        } else {
+          List<VisibilityEvaluator> veList = new ArrayList<>();
+          for (String[] auths : testDataSet.auths) {
+            veList.add(new VisibilityEvaluator(
+                new org.apache.accumulo.core.security.Authorizations(auths)));
+          }
+          vet.evaluator = veList;
+        }
+
+        // Create new
         EvaluatorTests et = new EvaluatorTests();
         et.expressions = new ArrayList<>();
 
@@ -100,11 +131,14 @@ public class AccessExpressionBenchmark {
               byte[] byteExp = exp.getBytes(UTF_8);
               allTestExpressions.add(byteExp);
               et.expressions.add(byteExp);
+              vet.expressions.add(byteExp);
+              vet.columnVisibilities.add(new ColumnVisibility(byteExp));
             }
           }
         }
 
         evaluatorTests.add(et);
+        visibilityEvaluatorTests.add(vet);
       }
     }
 
@@ -120,6 +154,10 @@ public class AccessExpressionBenchmark {
       return evaluatorTests;
     }
 
+    List<VisibilityEvaluatorTests> getVisibilityEvaluatorTests() {
+      return visibilityEvaluatorTests;
+    }
+
   }
 
   /**
@@ -147,7 +185,7 @@ public class AccessExpressionBenchmark {
    * tree an operate on it.
    */
   @Benchmark
-  public void measureEvaluation(BenchmarkState state, Blackhole blackhole) {
+  public void measureParseAndEvaluation(BenchmarkState state, Blackhole 
blackhole) {
     for (EvaluatorTests evaluatorTests : state.getEvaluatorTests()) {
       for (byte[] expression : evaluatorTests.expressions) {
         blackhole.consume(evaluatorTests.evaluator.canAccess(expression));
@@ -155,6 +193,41 @@ public class AccessExpressionBenchmark {
     }
   }
 
+  /**
+   * Measures the time it takes to evaluate a legacy expression.
+   *
+   * @throws VisibilityParseException error parsing expression with legacy code
+   */
+  @Benchmark
+  public void measureLegacyEvaluationOnly(BenchmarkState state, Blackhole 
blackhole)
+      throws VisibilityParseException {
+    for (VisibilityEvaluatorTests evaluatorTests : 
state.getVisibilityEvaluatorTests()) {
+      for (ColumnVisibility expression : evaluatorTests.columnVisibilities) {
+        for (VisibilityEvaluator ve : evaluatorTests.evaluator) {
+          blackhole.consume(ve.evaluate(expression));
+        }
+      }
+    }
+  }
+
+  /**
+   * Measures the time it takes to parse and evaluate a legacy expression. 
This has to create the
+   * parse tree an operate on it.
+   *
+   * @throws VisibilityParseException error parsing expression with legacy code
+   */
+  @Benchmark
+  public void measureLegacyParseAndEvaluation(BenchmarkState state, Blackhole 
blackhole)
+      throws VisibilityParseException {
+    for (VisibilityEvaluatorTests evaluatorTests : 
state.getVisibilityEvaluatorTests()) {
+      for (byte[] expression : evaluatorTests.expressions) {
+        for (VisibilityEvaluator ve : evaluatorTests.evaluator) {
+          blackhole.consume(ve.evaluate(new ColumnVisibility(expression)));
+        }
+      }
+    }
+  }
+
   public static void main(String[] args) throws RunnerException, IOException {
 
     var state = new BenchmarkState();

Reply via email to