Repository: incubator-atlas
Updated Branches:
  refs/heads/master cfc3436be -> b557b98c0


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

Signed-off-by: Sarath Subramanian <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/b557b98c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/b557b98c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/b557b98c

Branch: refs/heads/master
Commit: b557b98c0110f2042571b72d41676229766719c5
Parents: cfc3436
Author: apoorvnaik <[email protected]>
Authored: Thu May 25 15:16:55 2017 -0700
Committer: Sarath Subramanian <[email protected]>
Committed: Thu May 25 15:16:55 2017 -0700

----------------------------------------------------------------------
 .../apache/atlas/graph/GraphSandboxUtil.java    | 23 ++++++++++++++------
 .../test/java/org/apache/atlas/DBSandboxer.java | 20 ++++++++++++++++-
 2 files changed, 35 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/b557b98c/graphdb/common/src/test/java/org/apache/atlas/graph/GraphSandboxUtil.java
----------------------------------------------------------------------
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.Logger;
 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());
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/b557b98c/repository/src/test/java/org/apache/atlas/DBSandboxer.java
----------------------------------------------------------------------
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 @@ package org.apache.atlas;
 
 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

Reply via email to