Skip to content

Commit

Permalink
Merge pull request #395 from ksilin/stringListsinClusterBuilder
Browse files Browse the repository at this point in the history
added handling for string lists in ClusterBuilder
  • Loading branch information
fwbrasil authored Jun 11, 2016
2 parents c89e700 + 19c1215 commit 9445a75
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.typesafe.config.Config
import com.typesafe.config.ConfigValueType
import java.lang.reflect.Method
import scala.collection.JavaConversions._
import scala.collection.JavaConverters._
import com.datastax.driver.core.Cluster

object ClusterBuilder {
Expand Down Expand Up @@ -58,10 +59,14 @@ object ClusterBuilder {
instance
}

val stringArrayClass = java.lang.reflect.Array.newInstance(classOf[String], 0).getClass()

private def param(key: String, tpe: Class[_], cfg: Config) =
Try {
if (tpe == classOf[String])
cfg.getString(key)
else if (tpe == stringArrayClass)
cfg.getStringList(key).asScala.toArray
else if (tpe == classOf[Int] || tpe == classOf[Integer])
cfg.getInt(key)
else if (tpe.isEnum)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.getquill.sources.cassandra.cluster

import java.net.InetSocketAddress

import com.datastax.driver.core.Cluster.Builder
import com.typesafe.config.ConfigFactory
import io.getquill.Spec

class ClusterBuilderSpec extends Spec {

val hosts = List("127.0.0.1", "127.0.0.2", "127.0.0.3")
val contactPoints = hosts.map(new InetSocketAddress(_, 9042))

"creates Builder" - {

"with a single host" in {
val cfgString = s"contactPoint = ${hosts.head}"
val clusterBuilder: Builder = ClusterBuilder(ConfigFactory.parseString(cfgString))
clusterBuilder.getContactPoints must contain theSameElementsAs (contactPoints.take(1))
}

"with a single host in an array" in {
val cfgString = s"contactPoints = [${hosts.head}]"
val clusterBuilder: Builder = ClusterBuilder(ConfigFactory.parseString(cfgString))
clusterBuilder.getContactPoints must contain theSameElementsAs (contactPoints.take(1))
}

"with multiple hosts" in {
val cfgString = s"""contactPoints = [${hosts.mkString(",")}] """
val clusterBuilder: Builder = ClusterBuilder(ConfigFactory.parseString(cfgString))
clusterBuilder.getContactPoints must contain theSameElementsAs (contactPoints)
}
}
}

0 comments on commit 9445a75

Please sign in to comment.