Skip to content
This repository has been archived by the owner on Oct 18, 2021. It is now read-only.

Commit

Permalink
Merge pull request #108 from Nicole00/add_test
Browse files Browse the repository at this point in the history
add more check for config file & add test
  • Loading branch information
Nicole00 authored Jul 21, 2021
2 parents 3a0efe8 + 1734009 commit c4c70d6
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import java.io.File

import com.vesoft.nebula.exchange.config.{
Configs,
DataBaseConfigEntry,
FileBaseSourceConfigEntry,
FileDataSourceConfigEntry,
HBaseSourceConfigEntry,
Expand All @@ -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")
Expand Down Expand Up @@ -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)
}
}
}

0 comments on commit c4c70d6

Please sign in to comment.