From 0d5162d9d3df384237aed1dea8febaf74cdac603 Mon Sep 17 00:00:00 2001 From: Nicole00 <16240361+Nicole00@users.noreply.github.com> Date: Fri, 16 Jul 2021 15:00:30 +0800 Subject: [PATCH 1/2] add more check for config file --- .../nebula/exchange/config/Configs.scala | 17 +++++- .../nebula/exchange/config/ConfigsSuite.scala | 57 +++++++++++++++++++ 2 files changed, 71 insertions(+), 3 deletions(-) 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..9c00e52f 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,12 @@ import com.vesoft.nebula.exchange.config.{ SourceCategory } import com.vesoft.nebula.exchange.{Argument, KeyPolicy} +import org.apache.log4j.Logger import org.junit.Test 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 +241,57 @@ class ConfigsSuite { } } } + + @Test + def DataBaseConfigsSuite(): Unit = { + // correct config + 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 + try { + DataBaseConfigEntry(graphAddress, "", metaAddress) + } catch { + case e: IllegalArgumentException => { + LOG.error("we expect here, ", e) + assert(true) + } + case e: Throwable => { + LOG.error("DataBaseConfigSuite failed, ", e) + assert(false) + } + } + + // wrong graph address + val wrongGraphAddress = List("127.0.0.1:9669,127.0.0.1:9670") + try { + DataBaseConfigEntry(wrongGraphAddress, space, metaAddress) + } catch { + case e: IllegalArgumentException => { + LOG.error("we expect here, ", e) + assert(true) + } + case e: Throwable => { + LOG.error("DataBaseConfigSuite failed, ", e) + assert(false) + } + } + + // wrong meta Address + val wrongMetaAddress = List("127.0.0.1:9559,127.0.0.1:9560") + try { + DataBaseConfigEntry(graphAddress, space, wrongMetaAddress) + } catch { + case e: IllegalArgumentException => { + LOG.error("we expect here, ", e) + assert(true) + } + case e: Throwable => { + LOG.error("DataBaseConfigSuite failed, ", e) + assert(false) + } + } + } } From 173400997555315a3b45d16b1e1f5faed0275390 Mon Sep 17 00:00:00 2001 From: Nicole00 <16240361+Nicole00@users.noreply.github.com> Date: Wed, 21 Jul 2021 10:06:33 +0800 Subject: [PATCH 2/2] split multi test --- .../nebula/exchange/config/ConfigsSuite.scala | 68 +++++++++---------- 1 file changed, 33 insertions(+), 35 deletions(-) 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 9c00e52f..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 @@ -23,6 +23,7 @@ import com.vesoft.nebula.exchange.config.{ 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) @@ -242,56 +243,53 @@ class ConfigsSuite { } } + /** + * correct config + */ @Test - def DataBaseConfigsSuite(): Unit = { - // correct config + 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 - try { + /** + * 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) - } catch { - case e: IllegalArgumentException => { - LOG.error("we expect here, ", e) - assert(true) - } - case e: Throwable => { - LOG.error("DataBaseConfigSuite failed, ", e) - assert(false) - } } + } - // wrong graph address + /** + * wrong graph address + */ + @Test + def dataBaseConfigWrongGraphSuite: Unit = { val wrongGraphAddress = List("127.0.0.1:9669,127.0.0.1:9670") - try { + val space = "test" + val metaAddress = List("127.0.0.1:9559", "127.0.0.1:9560") + + assertThrows[IllegalArgumentException] { DataBaseConfigEntry(wrongGraphAddress, space, metaAddress) - } catch { - case e: IllegalArgumentException => { - LOG.error("we expect here, ", e) - assert(true) - } - case e: Throwable => { - LOG.error("DataBaseConfigSuite failed, ", e) - assert(false) - } } + } - // wrong meta Address + /** + * 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") - try { + assertThrows[IllegalArgumentException] { DataBaseConfigEntry(graphAddress, space, wrongMetaAddress) - } catch { - case e: IllegalArgumentException => { - LOG.error("we expect here, ", e) - assert(true) - } - case e: Throwable => { - LOG.error("DataBaseConfigSuite failed, ", e) - assert(false) - } } } }