diff --git a/nebula-exchange/src/main/scala/com/vesoft/nebula/exchange/config/Configs.scala b/nebula-exchange/src/main/scala/com/vesoft/nebula/exchange/config/Configs.scala index 1710f3ab..27efc56e 100644 --- a/nebula-exchange/src/main/scala/com/vesoft/nebula/exchange/config/Configs.scala +++ b/nebula-exchange/src/main/scala/com/vesoft/nebula/exchange/config/Configs.scala @@ -36,9 +36,20 @@ object Type extends Enumeration { case class DataBaseConfigEntry(graphAddress: List[String], space: String, metaAddresses: List[String]) { - require(graphAddress.nonEmpty) - require(metaAddresses.nonEmpty) - require(space.trim.nonEmpty) + require(graphAddress.nonEmpty, "nebula.address.graph cannot be empty") + require(metaAddresses.nonEmpty, "nebula.address.meta cannot be empty") + require(space.trim.nonEmpty, "nebula.space cannot be empty") + + for (address <- graphAddress) { + require( + !address.contains(",") && !address.contains(","), + "nebula.address.graph has wrong format, please make sure the format is [\"ip1:port1\",\"ip2:port2\"]") + } + for (address <- metaAddresses) { + require( + !address.contains(",") && !address.contains(","), + "nebula.address.meta has wrong format,,please make sure the format is [\"ip1:port1\",\"ip2:port2\"]") + } override def toString: String = super.toString diff --git a/nebula-exchange/src/test/scala/com/vesoft/nebula/exchange/config/ConfigsSuite.scala b/nebula-exchange/src/test/scala/com/vesoft/nebula/exchange/config/ConfigsSuite.scala index 7a2dc9aa..8f86cdf8 100644 --- a/nebula-exchange/src/test/scala/com/vesoft/nebula/exchange/config/ConfigsSuite.scala +++ b/nebula-exchange/src/test/scala/com/vesoft/nebula/exchange/config/ConfigsSuite.scala @@ -10,6 +10,7 @@ import java.io.File import com.vesoft.nebula.exchange.config.{ Configs, + DataBaseConfigEntry, FileBaseSourceConfigEntry, FileDataSourceConfigEntry, HBaseSourceConfigEntry, @@ -20,9 +21,13 @@ import com.vesoft.nebula.exchange.config.{ SourceCategory } import com.vesoft.nebula.exchange.{Argument, KeyPolicy} +import org.apache.log4j.Logger import org.junit.Test +import org.scalatest.Assertions.assertThrows class ConfigsSuite { + private[this] val LOG = Logger.getLogger(this.getClass) + @Test def configsSuite(): Unit = { val args = List("-c", "src/test/resources/application.conf", "-h", "-d") @@ -237,4 +242,54 @@ class ConfigsSuite { } } } + + /** + * correct config + */ + @Test + def dataBaseConfigSuite(): Unit = { + val graphAddress = List("127.0.0.1:9669", "127.0.0.1:9670") + val metaAddress = List("127.0.0.1:9559", "127.0.0.1:9560") + val space = "test" + DataBaseConfigEntry(graphAddress, space, metaAddress) + } + + /** + * empty space + */ + @Test + def dataBaseConfigEmptySpaceSuite: Unit = { + val graphAddress = List("127.0.0.1:9669", "127.0.0.1:9670") + val metaAddress = List("127.0.0.1:9559", "127.0.0.1:9560") + assertThrows[IllegalArgumentException] { + DataBaseConfigEntry(graphAddress, "", metaAddress) + } + } + + /** + * wrong graph address + */ + @Test + def dataBaseConfigWrongGraphSuite: Unit = { + val wrongGraphAddress = List("127.0.0.1:9669,127.0.0.1:9670") + val space = "test" + val metaAddress = List("127.0.0.1:9559", "127.0.0.1:9560") + + assertThrows[IllegalArgumentException] { + DataBaseConfigEntry(wrongGraphAddress, space, metaAddress) + } + } + + /** + * wrong meta Address + */ + @Test + def dataBaseConfigWrongMetaSuite: Unit = { + val graphAddress = List("127.0.0.1:9669", "127.0.0.1:9670") + val space = "test" + val wrongMetaAddress = List("127.0.0.1:9559,127.0.0.1:9560") + assertThrows[IllegalArgumentException] { + DataBaseConfigEntry(graphAddress, space, wrongMetaAddress) + } + } }