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

add more check for config file & add test #108

Merged
merged 2 commits into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

split multi test cases;
add @test(expected = IllegalArgumentException.class)

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could use ExpectedException rule in the test method

}
}

/**
* 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)
}
}
}