Repository: accumulo Updated Branches: refs/heads/1.6 98c524e34 -> 0532b627b refs/heads/master 67a426277 -> 9a9b2de83
ACCUMULO-3401 Clean up old AbstractMacIT classes Remove usage of deprecated SimpleMacIT and consolidate AbstractMacIT with ConfigurableMacIT. Update javadocs to clarify usage. Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/0532b627 Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/0532b627 Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/0532b627 Branch: refs/heads/1.6 Commit: 0532b627b5e86c3e56a0a1009676db7392f81a3a Parents: 98c524e Author: Christopher Tubbs <ctubb...@apache.org> Authored: Wed Dec 10 18:28:13 2014 -0500 Committer: Christopher Tubbs <ctubb...@apache.org> Committed: Wed Dec 10 18:28:13 2014 -0500 ---------------------------------------------------------------------- .../accumulo/harness/AccumuloClusterIT.java | 2 +- .../accumulo/harness/SharedMiniClusterIT.java | 4 +- .../apache/accumulo/test/ImportExportIT.java | 5 +- .../accumulo/test/functional/AbstractMacIT.java | 89 ------------- .../test/functional/ConfigurableMacIT.java | 76 ++++++++--- .../test/functional/HalfDeadTServerIT.java | 3 +- .../accumulo/test/functional/SimpleMacIT.java | 125 +------------------ 7 files changed, 71 insertions(+), 233 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/accumulo/blob/0532b627/test/src/test/java/org/apache/accumulo/harness/AccumuloClusterIT.java ---------------------------------------------------------------------- diff --git a/test/src/test/java/org/apache/accumulo/harness/AccumuloClusterIT.java b/test/src/test/java/org/apache/accumulo/harness/AccumuloClusterIT.java index d9d52d6..8f7e1b7 100644 --- a/test/src/test/java/org/apache/accumulo/harness/AccumuloClusterIT.java +++ b/test/src/test/java/org/apache/accumulo/harness/AccumuloClusterIT.java @@ -44,7 +44,7 @@ import org.slf4j.LoggerFactory; import com.google.common.base.Preconditions; /** - * General Integration-Test base class that provides an Accumulo instance + * General Integration-Test base class that provides access to an Accumulo instance for testing. This instance could be MAC or a standalone instance. */ public abstract class AccumuloClusterIT extends AccumuloIT implements MiniClusterConfigurationCallback { private static final Logger log = LoggerFactory.getLogger(AccumuloClusterIT.class); http://git-wip-us.apache.org/repos/asf/accumulo/blob/0532b627/test/src/test/java/org/apache/accumulo/harness/SharedMiniClusterIT.java ---------------------------------------------------------------------- diff --git a/test/src/test/java/org/apache/accumulo/harness/SharedMiniClusterIT.java b/test/src/test/java/org/apache/accumulo/harness/SharedMiniClusterIT.java index 3f7a8cc..2380f66 100644 --- a/test/src/test/java/org/apache/accumulo/harness/SharedMiniClusterIT.java +++ b/test/src/test/java/org/apache/accumulo/harness/SharedMiniClusterIT.java @@ -29,8 +29,8 @@ import org.junit.BeforeClass; /** * Convenience class which starts a single MAC instance for a test to leverage. * - * There isn't a good way to build this off of the AccumuloClusterIT (as would be the logical place) because we need to start the MiniAccumuloCluster in a - * static BeforeClass-annotated method. Because it is static and invoked before any other BeforeClass methods in the implementation, the actual test classes + * There isn't a good way to build this off of the {@link AccumuloClusterIT} (as would be the logical place) because we need to start the MiniAccumuloCluster in + * a static BeforeClass-annotated method. Because it is static and invoked before any other BeforeClass methods in the implementation, the actual test classes * can't expose any information to tell the base class that it is to perform the one-MAC-per-class semantics. */ public abstract class SharedMiniClusterIT extends AccumuloIT { http://git-wip-us.apache.org/repos/asf/accumulo/blob/0532b627/test/src/test/java/org/apache/accumulo/test/ImportExportIT.java ---------------------------------------------------------------------- diff --git a/test/src/test/java/org/apache/accumulo/test/ImportExportIT.java b/test/src/test/java/org/apache/accumulo/test/ImportExportIT.java index 43606b4..26a1c46 100644 --- a/test/src/test/java/org/apache/accumulo/test/ImportExportIT.java +++ b/test/src/test/java/org/apache/accumulo/test/ImportExportIT.java @@ -35,7 +35,7 @@ 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.test.functional.SimpleMacIT; +import org.apache.accumulo.harness.SharedMiniClusterIT; import org.apache.commons.io.FileUtils; import org.junit.Assert; import org.junit.Test; @@ -53,8 +53,7 @@ import com.google.common.io.Files; * */ // TODO Can switch to AccumuloClusterIT when FileSystem access from the Cluster is implemented. -@SuppressWarnings("deprecation") -public class ImportExportIT extends SimpleMacIT { +public class ImportExportIT extends SharedMiniClusterIT { private static final Logger log = LoggerFactory.getLogger(ImportExportIT.class); http://git-wip-us.apache.org/repos/asf/accumulo/blob/0532b627/test/src/test/java/org/apache/accumulo/test/functional/AbstractMacIT.java ---------------------------------------------------------------------- diff --git a/test/src/test/java/org/apache/accumulo/test/functional/AbstractMacIT.java b/test/src/test/java/org/apache/accumulo/test/functional/AbstractMacIT.java deleted file mode 100644 index 3833e3c..0000000 --- a/test/src/test/java/org/apache/accumulo/test/functional/AbstractMacIT.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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.functional; - -import java.io.File; -import java.util.Map; - -import org.apache.accumulo.core.cli.BatchWriterOpts; -import org.apache.accumulo.core.cli.ScannerOpts; -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.conf.Property; -import org.apache.accumulo.harness.AccumuloIT; -import org.apache.accumulo.minicluster.impl.MiniAccumuloClusterImpl; -import org.apache.accumulo.minicluster.impl.MiniAccumuloConfigImpl; -import org.apache.accumulo.test.util.CertUtils; -import org.apache.log4j.Logger; - -public abstract class AbstractMacIT extends AccumuloIT { - public static final Logger log = Logger.getLogger(AbstractMacIT.class); - - public static final String ROOT_PASSWORD = "testRootPassword1"; - public static final ScannerOpts SOPTS = new ScannerOpts(); - public static final BatchWriterOpts BWOPTS = new BatchWriterOpts(); - - protected static void cleanUp(MiniAccumuloClusterImpl cluster) { - if (cluster != null) - try { - cluster.stop(); - } catch (Exception e) {} - } - - protected static void configureForEnvironment(MiniAccumuloConfigImpl cfg, Class<?> testClass, File folder) { - if ("true".equals(System.getProperty("org.apache.accumulo.test.functional.useSslForIT"))) { - configureForSsl(cfg, folder); - } - if ("true".equals(System.getProperty("org.apache.accumulo.test.functional.useCredProviderForIT"))) { - cfg.setUseCredentialProvider(true); - } - } - - protected static void configureForSsl(MiniAccumuloConfigImpl cfg, File folder) { - Map<String,String> siteConfig = cfg.getSiteConfig(); - if ("true".equals(siteConfig.get(Property.INSTANCE_RPC_SSL_ENABLED.getKey()))) { - // already enabled; don't mess with it - return; - } - - File sslDir = new File(folder, "ssl"); - sslDir.mkdirs(); - File rootKeystoreFile = new File(sslDir, "root-" + cfg.getInstanceName() + ".jks"); - File localKeystoreFile = new File(sslDir, "local-" + cfg.getInstanceName() + ".jks"); - File publicTruststoreFile = new File(sslDir, "public-" + cfg.getInstanceName() + ".jks"); - final String rootKeystorePassword = "root_keystore_password", truststorePassword = "truststore_password"; - try { - new CertUtils(Property.RPC_SSL_KEYSTORE_TYPE.getDefaultValue(), "o=Apache Accumulo,cn=MiniAccumuloCluster", "RSA", 2048, "sha1WithRSAEncryption") - .createAll(rootKeystoreFile, localKeystoreFile, publicTruststoreFile, cfg.getInstanceName(), rootKeystorePassword, cfg.getRootPassword(), - truststorePassword); - } catch (Exception e) { - throw new RuntimeException("error creating MAC keystore", e); - } - - siteConfig.put(Property.INSTANCE_RPC_SSL_ENABLED.getKey(), "true"); - siteConfig.put(Property.RPC_SSL_KEYSTORE_PATH.getKey(), localKeystoreFile.getAbsolutePath()); - siteConfig.put(Property.RPC_SSL_KEYSTORE_PASSWORD.getKey(), cfg.getRootPassword()); - siteConfig.put(Property.RPC_SSL_TRUSTSTORE_PATH.getKey(), publicTruststoreFile.getAbsolutePath()); - siteConfig.put(Property.RPC_SSL_TRUSTSTORE_PASSWORD.getKey(), truststorePassword); - cfg.setSiteConfig(siteConfig); - } - - public abstract Connector getConnector() throws AccumuloException, AccumuloSecurityException; - - public abstract String rootPath(); -} http://git-wip-us.apache.org/repos/asf/accumulo/blob/0532b627/test/src/test/java/org/apache/accumulo/test/functional/ConfigurableMacIT.java ---------------------------------------------------------------------- diff --git a/test/src/test/java/org/apache/accumulo/test/functional/ConfigurableMacIT.java b/test/src/test/java/org/apache/accumulo/test/functional/ConfigurableMacIT.java index f51f297..1c8b1f0 100644 --- a/test/src/test/java/org/apache/accumulo/test/functional/ConfigurableMacIT.java +++ b/test/src/test/java/org/apache/accumulo/test/functional/ConfigurableMacIT.java @@ -21,6 +21,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.util.Map; import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; @@ -30,23 +31,71 @@ import org.apache.accumulo.core.client.ZooKeeperInstance; import org.apache.accumulo.core.client.security.tokens.PasswordToken; import org.apache.accumulo.core.conf.Property; import org.apache.accumulo.core.util.MonitorUtil; +import org.apache.accumulo.harness.AccumuloClusterIT; +import org.apache.accumulo.harness.AccumuloIT; +import org.apache.accumulo.minicluster.MiniAccumuloCluster; import org.apache.accumulo.minicluster.impl.MiniAccumuloClusterImpl; import org.apache.accumulo.minicluster.impl.MiniAccumuloConfigImpl; import org.apache.accumulo.minicluster.impl.ZooKeeperBindException; +import org.apache.accumulo.test.util.CertUtils; import org.apache.hadoop.conf.Configuration; import org.apache.log4j.Logger; import org.apache.zookeeper.KeeperException; import org.junit.After; import org.junit.Before; -public class ConfigurableMacIT extends AbstractMacIT { +/** + * General Integration-Test base class that provides access to a {@link MiniAccumuloCluster} for testing. Tests using these typically do very disruptive things + * to the instance, and require specific configuration. Most tests don't need this level of control and should extend {@link AccumuloClusterIT} instead. + */ +public class ConfigurableMacIT extends AccumuloIT { public static final Logger log = Logger.getLogger(ConfigurableMacIT.class); - public MiniAccumuloClusterImpl cluster; + protected MiniAccumuloClusterImpl cluster; + + protected void configure(MiniAccumuloConfigImpl cfg, Configuration hadoopCoreSite) {} + + protected void beforeClusterStart(MiniAccumuloConfigImpl cfg) throws Exception {} + + protected static final String ROOT_PASSWORD = "testRootPassword1"; - public void configure(MiniAccumuloConfigImpl cfg, Configuration hadoopCoreSite) {} + private static void configureForEnvironment(MiniAccumuloConfigImpl cfg, Class<?> testClass, File folder) { + if ("true".equals(System.getProperty("org.apache.accumulo.test.functional.useSslForIT"))) { + configureForSsl(cfg, folder); + } + if ("true".equals(System.getProperty("org.apache.accumulo.test.functional.useCredProviderForIT"))) { + cfg.setUseCredentialProvider(true); + } + } - public void beforeClusterStart(MiniAccumuloConfigImpl cfg) throws Exception {} + protected static void configureForSsl(MiniAccumuloConfigImpl cfg, File folder) { + Map<String,String> siteConfig = cfg.getSiteConfig(); + if ("true".equals(siteConfig.get(Property.INSTANCE_RPC_SSL_ENABLED.getKey()))) { + // already enabled; don't mess with it + return; + } + + File sslDir = new File(folder, "ssl"); + sslDir.mkdirs(); + File rootKeystoreFile = new File(sslDir, "root-" + cfg.getInstanceName() + ".jks"); + File localKeystoreFile = new File(sslDir, "local-" + cfg.getInstanceName() + ".jks"); + File publicTruststoreFile = new File(sslDir, "public-" + cfg.getInstanceName() + ".jks"); + final String rootKeystorePassword = "root_keystore_password", truststorePassword = "truststore_password"; + try { + new CertUtils(Property.RPC_SSL_KEYSTORE_TYPE.getDefaultValue(), "o=Apache Accumulo,cn=MiniAccumuloCluster", "RSA", 2048, "sha1WithRSAEncryption") + .createAll(rootKeystoreFile, localKeystoreFile, publicTruststoreFile, cfg.getInstanceName(), rootKeystorePassword, cfg.getRootPassword(), + truststorePassword); + } catch (Exception e) { + throw new RuntimeException("error creating MAC keystore", e); + } + + siteConfig.put(Property.INSTANCE_RPC_SSL_ENABLED.getKey(), "true"); + siteConfig.put(Property.RPC_SSL_KEYSTORE_PATH.getKey(), localKeystoreFile.getAbsolutePath()); + siteConfig.put(Property.RPC_SSL_KEYSTORE_PASSWORD.getKey(), cfg.getRootPassword()); + siteConfig.put(Property.RPC_SSL_TRUSTSTORE_PATH.getKey(), publicTruststoreFile.getAbsolutePath()); + siteConfig.put(Property.RPC_SSL_TRUSTSTORE_PASSWORD.getKey(), truststorePassword); + cfg.setSiteConfig(siteConfig); + } @Before public void setUp() throws Exception { @@ -90,28 +139,25 @@ public class ConfigurableMacIT extends AbstractMacIT { @After public void tearDown() throws Exception { - cleanUp(cluster); + if (cluster != null) + try { + cluster.stop(); + } catch (Exception e) {} } - public MiniAccumuloClusterImpl getCluster() { + protected MiniAccumuloClusterImpl getCluster() { return cluster; } - @Override - public Connector getConnector() throws AccumuloException, AccumuloSecurityException { + protected Connector getConnector() throws AccumuloException, AccumuloSecurityException { return getCluster().getConnector("root", new PasswordToken(ROOT_PASSWORD)); } - public Process exec(Class<?> clazz, String... args) throws IOException { + protected Process exec(Class<?> clazz, String... args) throws IOException { return getCluster().exec(clazz, args); } - @Override - public String rootPath() { - return getCluster().getConfig().getDir().getAbsolutePath(); - } - - public String getMonitor() throws KeeperException, InterruptedException { + protected String getMonitor() throws KeeperException, InterruptedException { Instance instance = new ZooKeeperInstance(getCluster().getClientConfig()); return MonitorUtil.getLocation(instance); } http://git-wip-us.apache.org/repos/asf/accumulo/blob/0532b627/test/src/test/java/org/apache/accumulo/test/functional/HalfDeadTServerIT.java ---------------------------------------------------------------------- diff --git a/test/src/test/java/org/apache/accumulo/test/functional/HalfDeadTServerIT.java b/test/src/test/java/org/apache/accumulo/test/functional/HalfDeadTServerIT.java index d48e0f3..0315891 100644 --- a/test/src/test/java/org/apache/accumulo/test/functional/HalfDeadTServerIT.java +++ b/test/src/test/java/org/apache/accumulo/test/functional/HalfDeadTServerIT.java @@ -30,6 +30,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import org.apache.accumulo.core.cli.ScannerOpts; import org.apache.accumulo.core.client.Connector; import org.apache.accumulo.core.conf.Property; import org.apache.accumulo.core.util.Daemon; @@ -165,7 +166,7 @@ public class HalfDeadTServerIT extends ConfigurableMacIT { assertEquals(0, ingest.waitFor()); VerifyIngest.Opts vopts = new VerifyIngest.Opts(); vopts.rows = rows; - VerifyIngest.verifyIngest(c, vopts, SOPTS); + VerifyIngest.verifyIngest(c, vopts, new ScannerOpts()); } else { UtilWaitThread.sleep(5 * 1000); tserver.waitFor(); http://git-wip-us.apache.org/repos/asf/accumulo/blob/0532b627/test/src/test/java/org/apache/accumulo/test/functional/SimpleMacIT.java ---------------------------------------------------------------------- diff --git a/test/src/test/java/org/apache/accumulo/test/functional/SimpleMacIT.java b/test/src/test/java/org/apache/accumulo/test/functional/SimpleMacIT.java index b2667e8..88f24b1 100644 --- a/test/src/test/java/org/apache/accumulo/test/functional/SimpleMacIT.java +++ b/test/src/test/java/org/apache/accumulo/test/functional/SimpleMacIT.java @@ -16,129 +16,10 @@ */ package org.apache.accumulo.test.functional; -import java.io.File; - -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.security.tokens.PasswordToken; -import org.apache.accumulo.core.conf.Property; -import org.apache.accumulo.harness.AccumuloClusterIT; -import org.apache.accumulo.harness.AccumuloIT; -import org.apache.accumulo.harness.MiniClusterHarness; -import org.apache.accumulo.minicluster.MiniAccumuloCluster; -import org.apache.accumulo.minicluster.MiniAccumuloInstance; -import org.apache.accumulo.minicluster.impl.MiniAccumuloClusterImpl; -import org.apache.accumulo.minicluster.impl.MiniAccumuloConfigImpl; -import org.apache.accumulo.minicluster.impl.ZooKeeperBindException; -import org.apache.log4j.Logger; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; +import org.apache.accumulo.harness.SharedMiniClusterIT; /** - * An implementation of {@link AbstractMacIT} for test cases that do not need to know any special details of {@link MiniAccumuloCluster}. Tests which extend - * this class should be runnable on any instance of Accumulo, given a root connector. - * - * New tests should be written using {@link AccumuloClusterIT}. To obtain the same semantics (shared instance across methods in a class), extend - * {@link AccumuloIT} and use {@link MiniClusterHarness} to create a MiniAccumuloCluster properly configured for the environment. + * @deprecated since 1.6.2; use {@link SharedMiniClusterIT} instead */ @Deprecated -public class SimpleMacIT extends AbstractMacIT { - public static final Logger log = Logger.getLogger(SimpleMacIT.class); - - private static File folder; - private static MiniAccumuloClusterImpl cluster = null; - - /** - * Try to get a common instance to run against. Fall back on creating a MiniAccumuloCluster. Subclasses should not care what kind of instance they get, as - * they should only use the API, given a root connector. - */ - @BeforeClass - public static synchronized void setUp() throws Exception { - if (getInstanceOneConnector() == null && cluster == null) { - log.info("No shared instance available, falling back to creating MAC"); - createMiniAccumulo(); - Exception lastException = null; - for (int i = 0; i < 3; i++) { - try { - cluster.start(); - - Runtime.getRuntime().addShutdownHook(new Thread() { - @Override - public void run() { - cleanUp(cluster); - } - }); - - return; - } catch (ZooKeeperBindException e) { - lastException = e; - log.warn("Failed to start MiniAccumuloCluster, assumably due to ZooKeeper issues", lastException); - Thread.sleep(3000); - createMiniAccumulo(); - } - } - - throw new RuntimeException("Failed to start MiniAccumuloCluster after three attempts", lastException); - } - } - - private static void createMiniAccumulo() throws Exception { - folder = createSharedTestDir(SimpleMacIT.class.getName()); - MiniAccumuloConfigImpl cfg = new MiniAccumuloConfigImpl(folder, ROOT_PASSWORD); - cfg.setNativeLibPaths(NativeMapIT.nativeMapLocation().getAbsolutePath()); - cfg.setProperty(Property.TSERV_NATIVEMAP_ENABLED, Boolean.TRUE.toString()); - cfg.setProperty(Property.GC_FILE_ARCHIVE, Boolean.TRUE.toString()); - configureForEnvironment(cfg, SimpleMacIT.class, createSharedTestDir(SimpleMacIT.class.getName() + "-ssl")); - cluster = new MiniAccumuloClusterImpl(cfg); - } - - @Before - public void logTestInfo() { - if (cluster != null) - log.debug("Running " + this.getClass().getSimpleName() + "." + testName.getMethodName() + "() in " + getFolder().getAbsolutePath()); - } - - @Override - public Connector getConnector() throws AccumuloException, AccumuloSecurityException { - Connector conn = getInstanceOneConnector(); - return conn == null ? cluster.getConnector("root", ROOT_PASSWORD) : conn; - } - - @Override - public String rootPath() { - return (getInstanceOneConnector() == null ? cluster.getConfig().getDir() : getInstanceOnePath()).getAbsolutePath(); - } - - public static MiniAccumuloClusterImpl getStaticCluster() { - return cluster; - } - - public static File getFolder() { - return folder; - } - - @After - public void cleanUp() throws Exception {} - - @AfterClass - public static void tearDown() throws Exception {} - - /** - * Try to get a common instance to connect to. (For example, one started in the pre-integration-test phase.) This may not be a MiniAccumuloCluster instance. - */ - private static Connector getInstanceOneConnector() { - try { - return new MiniAccumuloInstance("instance1", getInstanceOnePath()).getConnector("root", new PasswordToken(ROOT_PASSWORD)); - } catch (Exception e) { - return null; - } - } - - private static File getInstanceOnePath() { - return new File(System.getProperty("user.dir") + "/accumulo-maven-plugin/instance1"); - } - -} +public class SimpleMacIT extends SharedMiniClusterIT {}