Commit b557b98c by apoorvnaik Committed by Sarath Subramanian

ATLAS-1753: Fix for sandbox graph instance for each test

parent cfc3436b
...@@ -24,29 +24,38 @@ import org.slf4j.Logger; ...@@ -24,29 +24,38 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.File; import java.io.File;
import java.util.UUID;
public class GraphSandboxUtil { public class GraphSandboxUtil {
private static final Logger LOG = LoggerFactory.getLogger(GraphSandboxUtil.class); private static final Logger LOG = LoggerFactory.getLogger(GraphSandboxUtil.class);
public static void create() { public static void create(String sandboxName) {
Configuration configuration; Configuration configuration;
try { try {
configuration = ApplicationProperties.get(); configuration = ApplicationProperties.get();
// Append a suffix to isolate the database for each instance
long currentMillisecs = System.currentTimeMillis();
String newStorageDir = System.getProperty("atlas.data") + String newStorageDir = System.getProperty("atlas.data") +
File.pathSeparator + "storage" + File.separatorChar + "storage" +
File.pathSeparator + currentMillisecs; File.separatorChar + sandboxName;
configuration.setProperty("atlas.graph.storage.directory", newStorageDir); configuration.setProperty("atlas.graph.storage.directory", newStorageDir);
String newIndexerDir = System.getProperty("atlas.data") + String newIndexerDir = System.getProperty("atlas.data") +
File.pathSeparator + "index" + File.separatorChar + "index" +
File.pathSeparator + currentMillisecs; File.separatorChar + sandboxName;
configuration.setProperty("atlas.graph.index.search.directory", newIndexerDir); configuration.setProperty("atlas.graph.index.search.directory", newIndexerDir);
LOG.debug("New Storage dir : {}", newStorageDir); LOG.debug("New Storage dir : {}", newStorageDir);
LOG.debug("New Indexer dir : {}", newIndexerDir); LOG.debug("New Indexer dir : {}", newIndexerDir);
} catch (AtlasException ignored) {} } catch (AtlasException ignored) {}
} }
public static void create() {
// Append a suffix to isolate the database for each instance
UUID uuid = UUID.randomUUID();
create(uuid.toString());
}
} }
...@@ -19,13 +19,31 @@ package org.apache.atlas; ...@@ -19,13 +19,31 @@ package org.apache.atlas;
import org.apache.atlas.graph.GraphSandboxUtil; import org.apache.atlas.graph.GraphSandboxUtil;
import org.apache.atlas.repository.graph.AtlasGraphProvider; import org.apache.atlas.repository.graph.AtlasGraphProvider;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.testng.ITestContext; import org.testng.ITestContext;
import org.testng.TestListenerAdapter; import org.testng.TestListenerAdapter;
import org.testng.xml.XmlClass;
import java.util.List;
public class DBSandboxer extends TestListenerAdapter { public class DBSandboxer extends TestListenerAdapter {
@Override @Override
public void onStart(ITestContext context) { public void onStart(ITestContext context) {
GraphSandboxUtil.create(); // This will only work if each test is run individually (test suite has only one running test)
// If there are multiple tests the the sandbox folder name is not provided and the GraphSandboxUtil provisions
// a unique name
List<XmlClass> testClassesToRun = context.getCurrentXmlTest().getClasses();
if (CollectionUtils.isNotEmpty(testClassesToRun) && 1 == testClassesToRun.size()) {
XmlClass currentTestClass = testClassesToRun.get(0);
if (null != currentTestClass && StringUtils.isNotEmpty(currentTestClass.getName())) {
GraphSandboxUtil.create(currentTestClass.getName());
} else {
GraphSandboxUtil.create();
}
} else {
GraphSandboxUtil.create();
}
} }
@Override @Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment