You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@s2graph.apache.org by st...@apache.org on 2018/05/14 12:29:46 UTC

[02/25] incubator-s2graph git commit: - remove hard coded paths on FetcherTest, HDFSImporterTest.

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/319ae49c/s2core/src/test/scala/org/apache/s2graph/core/model/FetcherTest.scala
----------------------------------------------------------------------
diff --git a/s2core/src/test/scala/org/apache/s2graph/core/model/FetcherTest.scala b/s2core/src/test/scala/org/apache/s2graph/core/model/FetcherTest.scala
index e89f8de..fb6ff16 100644
--- a/s2core/src/test/scala/org/apache/s2graph/core/model/FetcherTest.scala
+++ b/s2core/src/test/scala/org/apache/s2graph/core/model/FetcherTest.scala
@@ -1,6 +1,9 @@
 package org.apache.s2graph.core.model
 
+import java.io.File
+
 import com.typesafe.config.ConfigFactory
+import org.apache.commons.io.FileUtils
 import org.apache.s2graph.core.Integrate.IntegrateCommon
 import org.apache.s2graph.core.Management.JsonModel.{Index, Prop}
 import org.apache.s2graph.core.schema.Label
@@ -67,12 +70,16 @@ class FetcherTest extends IntegrateCommon{
   test("AnnoyModelFetcher") {
 
     val labelName = "annoy_model_fetcher_test"
-    val hdfsConfDir = "/usr/local/Cellar/hadoop/2.7.3/libexec/etc/hadoop/"
+    val HDFS_CONF_DIR = "./"
+
+    val remoteIndexFilePath = getClass.getResource(s"/test-index.tree").toURI.getPath
+    val remoteDictFilePath = getClass.getResource(s"/test-index.dict").toURI.getPath
 
-    val REMOTE_INDEX_FILE = "/Users/shon/Downloads/test-index.tree"
-    val LOCAL_INDEX_FILE = "./test-index.tree"
-    val REMOTE_DICT_FILE = "/Users/shon/Downloads/test-index.dict"
-    val LOCAL_DICT_FILE = "./test-index.dict"
+    val localIndexFilePath = ".test-index.tree"
+    val localDictFilePath = ".test-index.dict"
+
+    FileUtils.deleteQuietly(new File(localIndexFilePath))
+    FileUtils.deleteQuietly(new File(localDictFilePath))
 
     val service = management.createService("s2graph", "localhost", "s2graph_htable", -1, None).get
     val serviceColumn =
@@ -81,19 +88,19 @@ class FetcherTest extends IntegrateCommon{
     val options = s"""{
                      | "importer": {
                      |   "${ModelManager.ImporterClassNameKey}": "org.apache.s2graph.core.model.HDFSImporter",
-                     |   "${HDFSImporter.HDFSConfDirKey}": "$hdfsConfDir",
+                     |   "${HDFSImporter.HDFSConfDirKey}": "$HDFS_CONF_DIR",
                      |   "${HDFSImporter.PathsKey}": [{
-                     |      "src": "${REMOTE_INDEX_FILE}",
-                     |      "tgt": "${LOCAL_INDEX_FILE}"
+                     |      "src": "${remoteDictFilePath}",
+                     |      "tgt": "${localDictFilePath}"
                      |   }, {
-                     |      "src": "${REMOTE_DICT_FILE}",
-                     |      "tgt": "${LOCAL_DICT_FILE}"
+                     |      "src": "${remoteIndexFilePath}",
+                     |      "tgt": "${localIndexFilePath}"
                      |   }]
                      | },
                      | "fetcher": {
                      |   "${ModelManager.FetcherClassNameKey}": "org.apache.s2graph.core.model.AnnoyModelFetcher",
-                     |   "${AnnoyModelFetcher.IndexFilePathKey}": "${LOCAL_INDEX_FILE}",
-                     |   "${AnnoyModelFetcher.DictFilePathKey}": "${LOCAL_DICT_FILE}",
+                     |   "${AnnoyModelFetcher.IndexFilePathKey}": "${localIndexFilePath}",
+                     |   "${AnnoyModelFetcher.DictFilePathKey}": "${localDictFilePath}",
                      |   "${AnnoyModelFetcher.DimensionKey}": 10
                      | }
                      |}""".stripMargin
@@ -130,5 +137,8 @@ class FetcherTest extends IntegrateCommon{
     stepResult.edgeWithScores.foreach { es =>
       println(es.edge)
     }
+
+    FileUtils.deleteQuietly(new File(localIndexFilePath))
+    FileUtils.deleteQuietly(new File(localDictFilePath))
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/319ae49c/s2core/src/test/scala/org/apache/s2graph/core/model/HDFSImporterTest.scala
----------------------------------------------------------------------
diff --git a/s2core/src/test/scala/org/apache/s2graph/core/model/HDFSImporterTest.scala b/s2core/src/test/scala/org/apache/s2graph/core/model/HDFSImporterTest.scala
index 385c9a7..3b274ab 100644
--- a/s2core/src/test/scala/org/apache/s2graph/core/model/HDFSImporterTest.scala
+++ b/s2core/src/test/scala/org/apache/s2graph/core/model/HDFSImporterTest.scala
@@ -1,6 +1,9 @@
 package org.apache.s2graph.core.model
 
+import java.io.File
+
 import com.typesafe.config.ConfigFactory
+import org.apache.commons.io.FileUtils
 import org.apache.s2graph.core.Integrate.IntegrateCommon
 import org.apache.s2graph.core.Management.JsonModel.{Index, Prop}
 import org.apache.s2graph.core.{Query, QueryParam}
@@ -15,12 +18,16 @@ class HDFSImporterTest extends IntegrateCommon {
   test("hdfs test.") {
 
     val labelName = "hdfs_importer_test"
-    val hdfsConfDir = "/usr/local/Cellar/hadoop/2.7.3/libexec/etc/hadoop/"
+    val HDFS_CONF_DIR = "./"
+
+    val remoteIndexFilePath = getClass.getResource(s"/test-index.tree").toURI.getPath
+    val remoteDictFilePath = getClass.getResource(s"/test-index.dict").toURI.getPath
 
-    val REMOTE_INDEX_FILE = "/Users/shon/Downloads/test-index.tree"
-    val LOCAL_INDEX_FILE = "./test-index.tree"
-    val REMOTE_DICT_FILE = "/Users/shon/Downloads/test-index.dict"
-    val LOCAL_DICT_FILE = "./test-index.dict"
+    val localIndexFilePath = ".test-index.tree"
+    val localDictFilePath = ".test-index.dict"
+
+    FileUtils.deleteQuietly(new File(localIndexFilePath))
+    FileUtils.deleteQuietly(new File(localDictFilePath))
 
     val service = management.createService("s2graph", "localhost", "s2graph_htable", -1, None).get
     val serviceColumn =
@@ -29,13 +36,13 @@ class HDFSImporterTest extends IntegrateCommon {
     val options = s"""{
                      | "importer": {
                      |   "${ModelManager.ImporterClassNameKey}": "org.apache.s2graph.core.model.HDFSImporter",
-                     |   "${HDFSImporter.HDFSConfDirKey}": "$hdfsConfDir",
+                     |   "${HDFSImporter.HDFSConfDirKey}": "$HDFS_CONF_DIR",
                      |   "${HDFSImporter.PathsKey}": [{
-                     |       "src":  "${REMOTE_INDEX_FILE}",
-                     |       "tgt": "${LOCAL_INDEX_FILE}"
+                     |       "src":  "${remoteIndexFilePath}",
+                     |       "tgt": "${localIndexFilePath}"
                      |     }, {
-                     |       "src": "${REMOTE_DICT_FILE}",
-                     |       "tgt": "${LOCAL_DICT_FILE}"
+                     |       "src": "${remoteDictFilePath}",
+                     |       "tgt": "${localDictFilePath}"
                      |     }
                      |   ]
                      | },
@@ -76,5 +83,8 @@ class HDFSImporterTest extends IntegrateCommon {
     stepResult.edgeWithScores.foreach { es =>
       println(es.edge)
     }
+
+    FileUtils.deleteQuietly(new File(localIndexFilePath))
+    FileUtils.deleteQuietly(new File(localDictFilePath))
   }
 }