ACCUMULO-3167 Lift some repeated stuff into AccumuloClusterIT. Pass down env information from property file to cluster
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/0105730b Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/0105730b Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/0105730b Branch: refs/heads/metrics2 Commit: 0105730b9fdec3603236e632afd0ba9376e8df4b Parents: 3342e32 Author: Josh Elser <[email protected]> Authored: Mon Nov 24 00:07:26 2014 -0500 Committer: Josh Elser <[email protected]> Committed: Mon Nov 24 18:08:52 2014 -0500 ---------------------------------------------------------------------- .../accumulo/harness/AccumuloClusterIT.java | 38 ++++++- .../AccumuloClusterPropertyConfiguration.java | 2 +- .../AccumuloStandaloneClusterConfiguration.java | 99 ---------------- .../StandaloneAccumuloClusterConfiguration.java | 114 +++++++++++++++++++ .../accumulo/test/functional/BulkFileIT.java | 12 +- 5 files changed, 151 insertions(+), 114 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/accumulo/blob/0105730b/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 08c8275..621fb13 100644 --- a/test/src/test/java/org/apache/accumulo/harness/AccumuloClusterIT.java +++ b/test/src/test/java/org/apache/accumulo/harness/AccumuloClusterIT.java @@ -18,6 +18,9 @@ package org.apache.accumulo.harness; import static org.junit.Assert.fail; +import java.io.File; +import java.io.IOException; + import org.apache.accumulo.cluster.AccumuloCluster; import org.apache.accumulo.cluster.standalone.StandaloneAccumuloCluster; import org.apache.accumulo.core.client.Connector; @@ -25,9 +28,10 @@ import org.apache.accumulo.core.client.admin.SecurityOperations; import org.apache.accumulo.core.client.admin.TableOperations; import org.apache.accumulo.core.client.security.tokens.AuthenticationToken; import org.apache.accumulo.harness.conf.AccumuloClusterPropertyConfiguration; -import org.apache.accumulo.harness.conf.AccumuloStandaloneClusterConfiguration; +import org.apache.accumulo.harness.conf.StandaloneAccumuloClusterConfiguration; import org.apache.accumulo.minicluster.impl.MiniAccumuloConfigImpl; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.Path; import org.junit.After; import org.junit.Assume; import org.junit.Before; @@ -77,8 +81,14 @@ public abstract class AccumuloClusterIT extends AccumuloIT implements MiniCluste cluster = miniClusterHarness.create(this, getToken()); break; case STANDALONE: - AccumuloStandaloneClusterConfiguration conf = (AccumuloStandaloneClusterConfiguration) clusterConf; - cluster = new StandaloneAccumuloCluster(conf.getInstance()); + StandaloneAccumuloClusterConfiguration conf = (StandaloneAccumuloClusterConfiguration) clusterConf; + StandaloneAccumuloCluster standaloneCluster = new StandaloneAccumuloCluster(conf.getInstance()); + // If these are provided in the configuration, pass them into the cluster + standaloneCluster.setAccumuloHome(conf.getAccumuloHome()); + standaloneCluster.setAccumuloConfDir(conf.getAccumuloConfDir()); + standaloneCluster.setHadoopConfDir(conf.getHadoopConfDir()); + // Set the implementation + cluster = standaloneCluster; break; default: throw new RuntimeException("Unhandled type"); @@ -173,4 +183,26 @@ public abstract class AccumuloClusterIT extends AccumuloIT implements MiniCluste public boolean canRunTest(ClusterType type) { return true; } + + /** + * Tries to give a reasonable directory which can be used to create temporary files for the test. Makes a basic attempt to create the directory if it does not + * already exist. + * + * @return A directory which can be expected to exist on the Cluster's FileSystem + * @throws IOException + * @throws IllegalArgumentException + */ + public String getUsableDir() throws IllegalArgumentException, IOException { + if (ClusterType.MINI == getClusterType()) { + File f = new File(System.getProperty("user.dir"), "target"); + f.mkdirs(); + return f.getAbsolutePath(); + } else if (ClusterType.STANDALONE == getClusterType()) { + String path = "/tmp"; + cluster.getFileSystem().mkdirs(new Path(path)); + return path; + } + + throw new IllegalArgumentException("Cannot determine a usable directory for cluster: " + getClusterType()); + } } http://git-wip-us.apache.org/repos/asf/accumulo/blob/0105730b/test/src/test/java/org/apache/accumulo/harness/conf/AccumuloClusterPropertyConfiguration.java ---------------------------------------------------------------------- diff --git a/test/src/test/java/org/apache/accumulo/harness/conf/AccumuloClusterPropertyConfiguration.java b/test/src/test/java/org/apache/accumulo/harness/conf/AccumuloClusterPropertyConfiguration.java index 3bcee98..75c0e70 100644 --- a/test/src/test/java/org/apache/accumulo/harness/conf/AccumuloClusterPropertyConfiguration.java +++ b/test/src/test/java/org/apache/accumulo/harness/conf/AccumuloClusterPropertyConfiguration.java @@ -103,7 +103,7 @@ public abstract class AccumuloClusterPropertyConfiguration implements AccumuloCl case MINI: return new AccumuloMiniClusterConfiguration(); case STANDALONE: - return new AccumuloStandaloneClusterConfiguration(); + return new StandaloneAccumuloClusterConfiguration(); default: throw new RuntimeException("Clusters other than MiniAccumuloCluster are not yet implemented"); } http://git-wip-us.apache.org/repos/asf/accumulo/blob/0105730b/test/src/test/java/org/apache/accumulo/harness/conf/AccumuloStandaloneClusterConfiguration.java ---------------------------------------------------------------------- diff --git a/test/src/test/java/org/apache/accumulo/harness/conf/AccumuloStandaloneClusterConfiguration.java b/test/src/test/java/org/apache/accumulo/harness/conf/AccumuloStandaloneClusterConfiguration.java deleted file mode 100644 index d5dcff8..0000000 --- a/test/src/test/java/org/apache/accumulo/harness/conf/AccumuloStandaloneClusterConfiguration.java +++ /dev/null @@ -1,99 +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.harness.conf; - -import java.util.Map; - -import org.apache.accumulo.core.client.Instance; -import org.apache.accumulo.core.client.ZooKeeperInstance; -import org.apache.accumulo.core.client.security.tokens.AuthenticationToken; -import org.apache.accumulo.core.client.security.tokens.PasswordToken; -import org.apache.accumulo.harness.AccumuloClusterIT.ClusterType; - -/** - * Extract connection information to a standalone Accumulo instance from Java properties - */ -public class AccumuloStandaloneClusterConfiguration extends AccumuloClusterPropertyConfiguration { - - public static final String ACCUMULO_STANDALONE_PRINCIPAL_KEY = ACCUMULO_STANDALONE_PREFIX + "principal"; - public static final String ACCUMULO_STANDALONE_PRINCIPAL_DEFAULT = "root"; - public static final String ACCUMULO_STANDALONE_PASSWORD_KEY = ACCUMULO_STANDALONE_PREFIX + "password"; - public static final String ACCUMULO_STANDALONE_PASSWORD_DEFAULT = "rootPassword1"; - public static final String ACCUMULO_STANDALONE_ZOOKEEPERS_KEY = ACCUMULO_STANDALONE_PREFIX + "zookeepers"; - public static final String ACCUMULO_STANDALONE_ZOOKEEPERS_DEFAULT = "localhost"; - public static final String ACCUMULO_STANDALONE_INSTANCE_NAME_KEY = ACCUMULO_STANDALONE_PREFIX + "instance.name"; - public static final String ACCUMULO_STANDALONE_INSTANCE_NAME_DEFAULT = "accumulo"; - - private Map<String,String> conf; - - public AccumuloStandaloneClusterConfiguration() { - ClusterType type = getClusterType(); - if (ClusterType.STANDALONE != type) { - throw new IllegalStateException("Expected only to see standalone cluster state"); - } - - this.conf = getConfiguration(type); - } - - @Override - public String getPrincipal() { - String principal = conf.get(ACCUMULO_STANDALONE_PRINCIPAL_KEY); - if (null == principal) { - principal = ACCUMULO_STANDALONE_PRINCIPAL_DEFAULT; - } - return principal; - } - - public String getPassword() { - String password = conf.get(ACCUMULO_STANDALONE_PASSWORD_KEY); - if (null == password) { - password = ACCUMULO_STANDALONE_PASSWORD_DEFAULT; - } - return password; - } - - @Override - public AuthenticationToken getToken() { - return new PasswordToken(getPassword()); - } - - public String getZooKeepers() { - String zookeepers = conf.get(ACCUMULO_STANDALONE_ZOOKEEPERS_KEY); - if (null == zookeepers) { - zookeepers = ACCUMULO_STANDALONE_ZOOKEEPERS_DEFAULT; - } - return zookeepers; - } - - public String getInstanceName() { - String instanceName = conf.get(ACCUMULO_STANDALONE_INSTANCE_NAME_KEY); - if (null == instanceName) { - instanceName = ACCUMULO_STANDALONE_INSTANCE_NAME_DEFAULT; - } - return instanceName; - } - - public Instance getInstance() { - return new ZooKeeperInstance(getInstanceName(), getZooKeepers()); - } - - @Override - public ClusterType getClusterType() { - return ClusterType.STANDALONE; - } - -} http://git-wip-us.apache.org/repos/asf/accumulo/blob/0105730b/test/src/test/java/org/apache/accumulo/harness/conf/StandaloneAccumuloClusterConfiguration.java ---------------------------------------------------------------------- diff --git a/test/src/test/java/org/apache/accumulo/harness/conf/StandaloneAccumuloClusterConfiguration.java b/test/src/test/java/org/apache/accumulo/harness/conf/StandaloneAccumuloClusterConfiguration.java new file mode 100644 index 0000000..5fb7203 --- /dev/null +++ b/test/src/test/java/org/apache/accumulo/harness/conf/StandaloneAccumuloClusterConfiguration.java @@ -0,0 +1,114 @@ +/* + * 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.harness.conf; + +import java.util.Map; + +import org.apache.accumulo.core.client.Instance; +import org.apache.accumulo.core.client.ZooKeeperInstance; +import org.apache.accumulo.core.client.security.tokens.AuthenticationToken; +import org.apache.accumulo.core.client.security.tokens.PasswordToken; +import org.apache.accumulo.harness.AccumuloClusterIT.ClusterType; + +/** + * Extract connection information to a standalone Accumulo instance from Java properties + */ +public class StandaloneAccumuloClusterConfiguration extends AccumuloClusterPropertyConfiguration { + + public static final String ACCUMULO_STANDALONE_PRINCIPAL_KEY = ACCUMULO_STANDALONE_PREFIX + "principal"; + public static final String ACCUMULO_STANDALONE_PRINCIPAL_DEFAULT = "root"; + public static final String ACCUMULO_STANDALONE_PASSWORD_KEY = ACCUMULO_STANDALONE_PREFIX + "password"; + public static final String ACCUMULO_STANDALONE_PASSWORD_DEFAULT = "rootPassword1"; + public static final String ACCUMULO_STANDALONE_ZOOKEEPERS_KEY = ACCUMULO_STANDALONE_PREFIX + "zookeepers"; + public static final String ACCUMULO_STANDALONE_ZOOKEEPERS_DEFAULT = "localhost"; + public static final String ACCUMULO_STANDALONE_INSTANCE_NAME_KEY = ACCUMULO_STANDALONE_PREFIX + "instance.name"; + public static final String ACCUMULO_STANDALONE_INSTANCE_NAME_DEFAULT = "accumulo"; + + public static final String ACCUMULO_STANDALONE_HOME = ACCUMULO_STANDALONE_PREFIX + "home"; + public static final String ACCUMULO_STANDALONE_CONF = ACCUMULO_STANDALONE_PREFIX + "conf"; + public static final String ACCUMULO_STANDALONE_HADOOP_CONF = ACCUMULO_STANDALONE_PREFIX + "hadoop.conf"; + + private Map<String,String> conf; + + public StandaloneAccumuloClusterConfiguration() { + ClusterType type = getClusterType(); + if (ClusterType.STANDALONE != type) { + throw new IllegalStateException("Expected only to see standalone cluster state"); + } + + this.conf = getConfiguration(type); + } + + @Override + public String getPrincipal() { + String principal = conf.get(ACCUMULO_STANDALONE_PRINCIPAL_KEY); + if (null == principal) { + principal = ACCUMULO_STANDALONE_PRINCIPAL_DEFAULT; + } + return principal; + } + + public String getPassword() { + String password = conf.get(ACCUMULO_STANDALONE_PASSWORD_KEY); + if (null == password) { + password = ACCUMULO_STANDALONE_PASSWORD_DEFAULT; + } + return password; + } + + @Override + public AuthenticationToken getToken() { + return new PasswordToken(getPassword()); + } + + public String getZooKeepers() { + String zookeepers = conf.get(ACCUMULO_STANDALONE_ZOOKEEPERS_KEY); + if (null == zookeepers) { + zookeepers = ACCUMULO_STANDALONE_ZOOKEEPERS_DEFAULT; + } + return zookeepers; + } + + public String getInstanceName() { + String instanceName = conf.get(ACCUMULO_STANDALONE_INSTANCE_NAME_KEY); + if (null == instanceName) { + instanceName = ACCUMULO_STANDALONE_INSTANCE_NAME_DEFAULT; + } + return instanceName; + } + + public Instance getInstance() { + return new ZooKeeperInstance(getInstanceName(), getZooKeepers()); + } + + @Override + public ClusterType getClusterType() { + return ClusterType.STANDALONE; + } + + public String getHadoopConfDir() { + return conf.get(ACCUMULO_STANDALONE_HADOOP_CONF); + } + + public String getAccumuloHome() { + return conf.get(ACCUMULO_STANDALONE_HOME); + } + + public String getAccumuloConfDir() { + return conf.get(ACCUMULO_STANDALONE_CONF); + } +} http://git-wip-us.apache.org/repos/asf/accumulo/blob/0105730b/test/src/test/java/org/apache/accumulo/test/functional/BulkFileIT.java ---------------------------------------------------------------------- diff --git a/test/src/test/java/org/apache/accumulo/test/functional/BulkFileIT.java b/test/src/test/java/org/apache/accumulo/test/functional/BulkFileIT.java index 3772937..67de2e6 100644 --- a/test/src/test/java/org/apache/accumulo/test/functional/BulkFileIT.java +++ b/test/src/test/java/org/apache/accumulo/test/functional/BulkFileIT.java @@ -18,7 +18,6 @@ package org.apache.accumulo.test.functional; import static com.google.common.base.Charsets.UTF_8; -import java.io.File; import java.util.Iterator; import java.util.Map.Entry; import java.util.SortedSet; @@ -42,7 +41,6 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.Text; -import org.junit.Assert; import org.junit.Test; public class BulkFileIT extends AccumuloClusterIT { @@ -70,15 +68,7 @@ public class BulkFileIT extends AccumuloClusterIT { AccumuloConfiguration aconf = ServerConfiguration.getDefaultConfiguration(); FileSystem fs = getCluster().getFileSystem(); - String rootPath; - if (ClusterType.MINI == getClusterType()) { - rootPath = new File(System.getProperty("user.dir"), "target").getCanonicalPath(); - } else if (ClusterType.STANDALONE == getClusterType()) { - rootPath = "/tmp"; - } else { - Assert.fail("Cannot compute root path for test"); - return; - } + String rootPath = getUsableDir(); String dir = rootPath + "/bulk_test_diff_files_89723987592_" + getUniqueNames(1)[0];
