ATLAS-1753: Fix for sandbox graph instance for each test
Signed-off-by: Sarath Subramanian <ssubramanian@hortonworks.com>
diff --git a/graphdb/common/src/test/java/org/apache/atlas/graph/GraphSandboxUtil.java b/graphdb/common/src/test/java/org/apache/atlas/graph/GraphSandboxUtil.java
index 44ad4fc..3cccd84 100644
--- a/graphdb/common/src/test/java/org/apache/atlas/graph/GraphSandboxUtil.java
+++ b/graphdb/common/src/test/java/org/apache/atlas/graph/GraphSandboxUtil.java
@@ -24,29 +24,38 @@
import org.slf4j.LoggerFactory;
import java.io.File;
+import java.util.UUID;
public class GraphSandboxUtil {
private static final Logger LOG = LoggerFactory.getLogger(GraphSandboxUtil.class);
- public static void create() {
+ public static void create(String sandboxName) {
Configuration configuration;
try {
configuration = ApplicationProperties.get();
- // Append a suffix to isolate the database for each instance
- long currentMillisecs = System.currentTimeMillis();
String newStorageDir = System.getProperty("atlas.data") +
- File.pathSeparator + "storage" +
- File.pathSeparator + currentMillisecs;
+ File.separatorChar + "storage" +
+ File.separatorChar + sandboxName;
+
configuration.setProperty("atlas.graph.storage.directory", newStorageDir);
+
String newIndexerDir = System.getProperty("atlas.data") +
- File.pathSeparator + "index" +
- File.pathSeparator + currentMillisecs;
+ File.separatorChar + "index" +
+ File.separatorChar + sandboxName;
+
configuration.setProperty("atlas.graph.index.search.directory", newIndexerDir);
+
LOG.debug("New Storage dir : {}", newStorageDir);
LOG.debug("New Indexer dir : {}", newIndexerDir);
} catch (AtlasException ignored) {}
}
+
+ public static void create() {
+ // Append a suffix to isolate the database for each instance
+ UUID uuid = UUID.randomUUID();
+ create(uuid.toString());
+ }
}
diff --git a/repository/src/test/java/org/apache/atlas/DBSandboxer.java b/repository/src/test/java/org/apache/atlas/DBSandboxer.java
index cc8e0e2..f4f099a 100644
--- a/repository/src/test/java/org/apache/atlas/DBSandboxer.java
+++ b/repository/src/test/java/org/apache/atlas/DBSandboxer.java
@@ -19,13 +19,31 @@
import org.apache.atlas.graph.GraphSandboxUtil;
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.TestListenerAdapter;
+import org.testng.xml.XmlClass;
+
+import java.util.List;
public class DBSandboxer extends TestListenerAdapter {
@Override
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