/*
* 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 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.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.log4j.Logger;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
/**
* 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.
*/
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) {
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());
configureForEnvironment(cfg, SimpleMacIT.class, createSharedTestDir(SimpleMacIT.class.getName() + "-ssl"));
cluster = new MiniAccumuloClusterImpl(cfg);
cluster.start();
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
cleanUp(cluster);
}
});
}
}
@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");
}
}