Skip to content

Commit

Permalink
Fail unit tests if zookeeper server is not running
Browse files Browse the repository at this point in the history
  • Loading branch information
John Corwin committed Jul 29, 2010
1 parent 36a91ea commit 39049da
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/test/scala/com/twitter/zookeeper/ZooKeeperClientSpec.scala
@@ -1,6 +1,6 @@
package com.twitter.zookeeper

import java.net.{Socket, SocketException}
import java.net.{Socket, ConnectException}
import org.scala_tools.javautils.Imports._
import org.apache.zookeeper.{CreateMode, Watcher, WatchedEvent, ZooKeeper}
import org.apache.zookeeper.CreateMode._
Expand All @@ -11,17 +11,25 @@ import net.lag.configgy.Configgy
import scala.collection.mutable

class ZookeeperClientSpec extends Specification {
"ZookeeperClient" should {
Configgy.configure("src/main/resources/config.conf")
Configgy.configure("src/main/resources/config.conf")

val configMap = Configgy.config
val hostlist = configMap.getString("zookeeper-client.hostlist", "localhost:2181")

val configMap = Configgy.config
val zkClient = new ZooKeeperClient(configMap, Some((zk : ZooKeeper) => {}))
doBeforeSpec {
// we need to be sure that a ZooKeeper server is running in order to test
println("Testing connection to ZooKeeper server at %s...".format(hostlist))
val socketPort = hostlist.split(":")
new Socket(socketPort(0), socketPort(1).toInt) mustNot throwA[ConnectException]
}

"ZookeeperClient" should {
shareVariables()
var zkClient : ZooKeeperClient = null

doBefore {
// we need to be sure that a ZooKeeper server is running in order to test
val hostlist = configMap.getString("zookeeper-client.hostlist", "localhost:2181")
val socketPort = hostlist.split(":")
new Socket(socketPort(0), socketPort(1).toInt) must throwA[SocketException]
doFirst {
println("Attempting to connect to ZooKeeper server %s...".format(hostlist))
zkClient = new ZooKeeperClient(configMap, None)
}

doLast {
Expand Down

0 comments on commit 39049da

Please sign in to comment.