You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by dl...@apache.org on 2022/06/30 10:56:18 UTC

[accumulo] branch main updated: Move MiniAccumuloClusterTest.testPerTableClasspath to new test class (#2794)

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.git


The following commit(s) were added to refs/heads/main by this push:
     new b31f065d23 Move MiniAccumuloClusterTest.testPerTableClasspath to new test class (#2794)
b31f065d23 is described below

commit b31f065d2371f0bbe9dca4fc2f322e7baae9b8ac
Author: Dave Marion <dl...@apache.org>
AuthorDate: Thu Jun 30 06:56:12 2022 -0400

    Move MiniAccumuloClusterTest.testPerTableClasspath to new test class (#2794)
    
    MiniAccumuloClusterTest.testPerTableClasspath is intermittently failing with
    a MutationsRejectedException when the BatchWriter is closed because the TabletServer
    is not seeing property changes made in the test right before the BatchWriter is
    created. This change moves this test method to its own test class so that MAC is
    configured with the classpath context configuration properties from the start.
---
 .../MiniAccumuloClusterClasspathTest.java          | 139 +++++++++++++++++++++
 .../minicluster/MiniAccumuloClusterTest.java       |  62 ---------
 2 files changed, 139 insertions(+), 62 deletions(-)

diff --git a/minicluster/src/test/java/org/apache/accumulo/minicluster/MiniAccumuloClusterClasspathTest.java b/minicluster/src/test/java/org/apache/accumulo/minicluster/MiniAccumuloClusterClasspathTest.java
new file mode 100644
index 0000000000..c3c1af4a91
--- /dev/null
+++ b/minicluster/src/test/java/org/apache/accumulo/minicluster/MiniAccumuloClusterClasspathTest.java
@@ -0,0 +1,139 @@
+/*
+ * 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
+ *
+ *   https://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.minicluster;
+
+import static java.util.Objects.requireNonNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.File;
+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.IteratorSetting;
+import org.apache.accumulo.core.client.Scanner;
+import org.apache.accumulo.core.client.admin.NewTableConfiguration;
+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.security.Authorizations;
+import org.apache.commons.io.FileUtils;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+import org.junit.jupiter.api.io.TempDir;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
+@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "paths not set by user input")
+public class MiniAccumuloClusterClasspathTest extends WithTestNames {
+
+  @SuppressWarnings("removal")
+  private static final Property VFS_CONTEXT_CLASSPATH_PROPERTY =
+      Property.VFS_CONTEXT_CLASSPATH_PROPERTY;
+
+  @TempDir
+  private static File tempDir;
+
+  public static final String ROOT_PASSWORD = "superSecret";
+  public static final String ROOT_USER = "root";
+
+  public static File testDir;
+
+  private static MiniAccumuloCluster accumulo;
+
+  @BeforeAll
+  public static void setupMiniCluster() throws Exception {
+    File baseDir = new File(System.getProperty("user.dir") + "/target/mini-tests");
+    assertTrue(baseDir.mkdirs() || baseDir.isDirectory());
+    testDir = new File(baseDir, MiniAccumuloClusterTest.class.getName());
+    FileUtils.deleteQuietly(testDir);
+    assertTrue(testDir.mkdir());
+
+    File jarFile = new File(tempDir, "iterator.jar");
+    FileUtils.copyURLToFile(
+        requireNonNull(MiniAccumuloClusterClasspathTest.class.getResource("/FooFilter.jar")),
+        jarFile);
+
+    MiniAccumuloConfig config = new MiniAccumuloConfig(testDir, ROOT_PASSWORD).setJDWPEnabled(true);
+    config.setZooKeeperPort(0);
+    HashMap<String,String> site = new HashMap<>();
+    site.put(Property.TSERV_WORKQ_THREADS.getKey(), "2");
+    site.put(VFS_CONTEXT_CLASSPATH_PROPERTY.getKey() + "cx1", jarFile.toURI().toString());
+    config.setSiteConfig(site);
+    accumulo = new MiniAccumuloCluster(config);
+    accumulo.start();
+  }
+
+  @AfterAll
+  public static void tearDownMiniCluster() throws Exception {
+    accumulo.stop();
+  }
+
+  @SuppressWarnings("deprecation")
+  @Test
+  @Timeout(60)
+  public void testPerTableClasspath() throws Exception {
+    org.apache.accumulo.core.client.Connector conn =
+        accumulo.getConnector(ROOT_USER, ROOT_PASSWORD);
+
+    final String tableName = testName();
+
+    var ntc = new NewTableConfiguration();
+    ntc.setProperties(Map.of(Property.TABLE_CLASSLOADER_CONTEXT.getKey(), "cx1"));
+    ntc.attachIterator(new IteratorSetting(100, "foocensor", "org.apache.accumulo.test.FooFilter"));
+
+    conn.tableOperations().create(tableName, ntc);
+
+    try (BatchWriter bw = conn.createBatchWriter(tableName, new BatchWriterConfig())) {
+
+      Mutation m1 = new Mutation("foo");
+      m1.put("cf1", "cq1", "v2");
+      m1.put("cf1", "cq2", "v3");
+
+      bw.addMutation(m1);
+
+      Mutation m2 = new Mutation("bar");
+      m2.put("cf1", "cq1", "v6");
+      m2.put("cf1", "cq2", "v7");
+
+      bw.addMutation(m2);
+
+    }
+
+    int count = 0;
+    try (Scanner scanner = conn.createScanner(tableName, new Authorizations())) {
+      for (Entry<Key,Value> entry : scanner) {
+        assertFalse(entry.getKey().getRowData().toString().toLowerCase().contains("foo"));
+        count++;
+      }
+    }
+
+    assertEquals(2, count);
+
+    conn.tableOperations().delete(tableName);
+  }
+
+}
diff --git a/minicluster/src/test/java/org/apache/accumulo/minicluster/MiniAccumuloClusterTest.java b/minicluster/src/test/java/org/apache/accumulo/minicluster/MiniAccumuloClusterTest.java
index 4f8fab146b..61921fa238 100644
--- a/minicluster/src/test/java/org/apache/accumulo/minicluster/MiniAccumuloClusterTest.java
+++ b/minicluster/src/test/java/org/apache/accumulo/minicluster/MiniAccumuloClusterTest.java
@@ -19,9 +19,7 @@
 package org.apache.accumulo.minicluster;
 
 import static java.nio.charset.StandardCharsets.UTF_8;
-import static java.util.Objects.requireNonNull;
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.junit.jupiter.api.Assertions.fail;
@@ -30,7 +28,6 @@ import java.io.File;
 import java.io.FileReader;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
 import java.util.UUID;
@@ -58,17 +55,12 @@ import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.Timeout;
-import org.junit.jupiter.api.io.TempDir;
 
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 
 @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "paths not set by user input")
 public class MiniAccumuloClusterTest extends WithTestNames {
 
-  @SuppressWarnings("removal")
-  private static final Property VFS_CONTEXT_CLASSPATH_PROPERTY =
-      Property.VFS_CONTEXT_CLASSPATH_PROPERTY;
-
   public static final String ROOT_PASSWORD = "superSecret";
   public static final String ROOT_USER = "root";
 
@@ -186,60 +178,6 @@ public class MiniAccumuloClusterTest extends WithTestNames {
     conn.tableOperations().delete(tableName);
   }
 
-  @TempDir
-  private static File tempDir;
-
-  @SuppressWarnings("deprecation")
-  @Test
-  @Timeout(60)
-  public void testPerTableClasspath() throws Exception {
-    org.apache.accumulo.core.client.Connector conn =
-        accumulo.getConnector(ROOT_USER, ROOT_PASSWORD);
-
-    final String tableName = testName();
-    File jarFile = new File(tempDir, "iterator.jar");
-
-    var ntc = new NewTableConfiguration();
-    ntc.setProperties(Map.of(Property.TABLE_CLASSLOADER_CONTEXT.getKey(), "cx1"));
-    ntc.attachIterator(new IteratorSetting(100, "foocensor", "org.apache.accumulo.test.FooFilter"));
-
-    conn.tableOperations().create(tableName, ntc);
-
-    FileUtils.copyURLToFile(requireNonNull(getClass().getResource("/FooFilter.jar")), jarFile);
-
-    conn.instanceOperations().setProperty(VFS_CONTEXT_CLASSPATH_PROPERTY.getKey() + "cx1",
-        jarFile.toURI().toString());
-
-    try (BatchWriter bw = conn.createBatchWriter(tableName, new BatchWriterConfig())) {
-
-      Mutation m1 = new Mutation("foo");
-      m1.put("cf1", "cq1", "v2");
-      m1.put("cf1", "cq2", "v3");
-
-      bw.addMutation(m1);
-
-      Mutation m2 = new Mutation("bar");
-      m2.put("cf1", "cq1", "v6");
-      m2.put("cf1", "cq2", "v7");
-
-      bw.addMutation(m2);
-
-    }
-
-    int count = 0;
-    try (Scanner scanner = conn.createScanner(tableName, new Authorizations())) {
-      for (Entry<Key,Value> entry : scanner) {
-        assertFalse(entry.getKey().getRowData().toString().toLowerCase().contains("foo"));
-        count++;
-      }
-    }
-
-    assertEquals(2, count);
-
-    conn.instanceOperations().removeProperty(VFS_CONTEXT_CLASSPATH_PROPERTY.getKey() + "cx1");
-    conn.tableOperations().delete(tableName);
-  }
-
   @Test
   @Timeout(10)
   public void testDebugPorts() {