本文整理汇总了Scala中org.apache.curator.test.TestingServer类的典型用法代码示例。如果您正苦于以下问题:Scala TestingServer类的具体用法?Scala TestingServer怎么用?Scala TestingServer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TestingServer类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: MockZookeeperServer
//设置package包名称以及导入依赖的类
package com.box.castle.core.mock
import org.apache.curator.test.TestingServer
object MockZookeeperServer {
private lazy val testServer = {
val server = new TestingServer()
server.start()
server
}
private val lock = new Object()
private var counter = 1
def getNamespace: String = {
lock.synchronized {
counter += 1
return "mockCurator-" + counter.toString
}
}
def getConnectString: String = testServer.getConnectString
}
示例2: before
//设置package包名称以及导入依赖的类
package com.softbrew.specs2kafka
import java.net.ServerSocket
import java.nio.file.Files
import java.util.Properties
import _root_.kafka.server.KafkaConfig
import _root_.kafka.server.KafkaServerStartable
import org.apache.curator.test.TestingServer
import org.specs2.mutable.BeforeAfter
import org.specs2.specification.Scope
trait SimpleKafkaScope extends Scope with BeforeAfter{
val zkServer = new TestingServer()
val socket = new ServerSocket(0)
val port = socket.getLocalPort.toString
println(s"'port' looks like: $port")
socket.close()
val tmpDir = Files.createTempDirectory("kafka-test-logs")
val serverProps = new Properties()
serverProps.put("broker.id", port)
serverProps.put("log.dirs", tmpDir.toAbsolutePath.toString)
serverProps.put("host.name", "localhost")
serverProps.put("zookeeper.connect", zkServer.getConnectString)
serverProps.put("port", port)
val config = new KafkaConfig(serverProps)
val kafkaServer = new KafkaServerStartable(config)
override def before: Unit = {
kafkaServer.startup()
}
override def after: Unit = {
kafkaServer.shutdown()
zkServer.close()
zkServer.stop()
}
println("zkServer: " + zkServer.getConnectString)
println("Kafka broker port: " + port)
}
示例3: TestingKafkaCluster
//设置package包名称以及导入依赖的类
package com.saikocat.test
import java.io.IOException
import java.util.Properties
import kafka.server.KafkaConfig
import kafka.server.KafkaServerStartable
import kafka.utils.TestUtils
import org.apache.curator.test.TestingServer
class TestingKafkaCluster(val kafkaServer: KafkaServerStartable,
val zkServer: TestingServer) {
def start(): Unit = {
kafkaServer.startup()
}
def kafkaConfig(): KafkaConfig = {
kafkaServer.serverConfig
}
def kafkaBrokerString(): String = {
s"localhost:${kafkaServer.serverConfig.port}"
}
def zkConnectString(): String = {
return zkServer.getConnectString()
}
def kafkaPort(): Int = {
return kafkaServer.serverConfig.port
}
@throws(classOf[IOException])
def stop(): Unit = {
kafkaServer.shutdown()
zkServer.stop()
}
}
object TestingKafkaCluster {
@throws(classOf[Exception])
def apply(): TestingKafkaCluster = {
val zkServer = new TestingServer()
val config: KafkaConfig = getKafkaConfig(zkServer.getConnectString())
val kafkaServer = new KafkaServerStartable(config)
new TestingKafkaCluster(kafkaServer, zkServer)
}
def getKafkaConfig(zkConnectString: String): KafkaConfig = {
val propsI: scala.collection.Iterator[Properties] =
TestUtils.createBrokerConfigs(1).iterator
assert(propsI.hasNext)
val props: Properties = propsI.next()
assert(props.containsKey("zookeeper.connect"))
props.put("zookeeper.connect", zkConnectString)
props.put("host.name", "localhost")
new KafkaConfig(props)
}
}
示例4: ZookeeperServerStartup
//设置package包名称以及导入依赖的类
import java.util
import java.util.concurrent.TimeUnit
import org.apache.curator.framework.{CuratorFramework, CuratorFrameworkFactory}
import org.apache.curator.retry.ExponentialBackoffRetry
import org.apache.curator.test.TestingServer
import org.apache.zookeeper.CreateMode
import org.apache.zookeeper.ZooDefs.Ids
import org.apache.zookeeper.data.ACL
object ZookeeperServerStartup {
val port = 2181
val endpoints = s"127.0.0.1:$port"
def main(args: Array[String]): Unit = {
val zkServer = new TestingServer(port, true)
createNodes()
addShutdownHook(zkServer)
}
private def createNodes() = {
val zkClient: CuratorFramework = {
val connection = CuratorFrameworkFactory.builder()
.connectString(endpoints)
.sessionTimeoutMs(2000)
.connectionTimeoutMs(5000)
.retryPolicy(new ExponentialBackoffRetry(1000, 3))
.build()
connection.start()
connection.blockUntilConnected(5000, TimeUnit.MILLISECONDS)
connection
}
zkClient.create()
.creatingParentsIfNeeded()
.withMode(CreateMode.PERSISTENT)
.withACL(new util.ArrayList[ACL](Ids.OPEN_ACL_UNSAFE))
.forPath(BookieServerStartup.zkLedgersRootPath)
zkClient.create()
.withMode(CreateMode.PERSISTENT)
.withACL(new util.ArrayList[ACL](Ids.OPEN_ACL_UNSAFE))
.forPath(BookieServerStartup.zkBookiesAvailablePath)
zkClient.close()
}
private def addShutdownHook(zkServer: TestingServer) = {
Runtime.getRuntime.addShutdownHook(new Thread() {
override def run(): Unit = {
zkServer.close()
}
})
}
}
示例5: CuratorTests
//设置package包名称以及导入依赖的类
package com.bwsw.imp.curator
import org.apache.curator.framework.{CuratorFramework, CuratorFrameworkFactory}
import org.apache.curator.retry.ExponentialBackoffRetry
import org.apache.curator.test.TestingServer
import org.scalatest.{BeforeAndAfterAll, FlatSpec, Matchers}
class CuratorTests extends FlatSpec with Matchers with BeforeAndAfterAll {
val ZOOKEEPER_PORT = 21810
var testingServer = new TestingServer(ZOOKEEPER_PORT)
implicit var curator: CuratorFramework = _
override def beforeAll() = {
testingServer.start()
curator = CuratorFrameworkFactory.builder()
.retryPolicy(new ExponentialBackoffRetry(1000, 3))
.namespace("tests")
.connectString(s"127.0.0.1:$ZOOKEEPER_PORT").build()
curator.start()
}
it must "do nothing" in {}
override def afterAll() = {
curator.close()
testingServer.stop()
}
}
示例6: ZkSeverAndTransactionServer
//设置package包名称以及导入依赖的类
package util
import com.bwsw.tstreamstransactionserver.netty.server.Server
import org.apache.curator.test.TestingServer
final class ZkSeverAndTransactionServer(val zkServer: TestingServer,
val transactionServer: Server
)
{
def close(): Unit = {
transactionServer.shutdown()
zkServer.close()
}
}
object ZkSeverAndTransactionServer{
def apply(zkServer: TestingServer, transactionServer: Server): ZkSeverAndTransactionServer =
new ZkSeverAndTransactionServer(zkServer, transactionServer)
}
示例7: ZkSeverTxnServerTxnClient
//设置package包名称以及导入依赖的类
package util
import com.bwsw.tstreamstransactionserver.netty.client.Client
import com.bwsw.tstreamstransactionserver.netty.server.Server
import org.apache.curator.test.TestingServer
class ZkSeverTxnServerTxnClient(val zkServer: TestingServer,
val transactionServer: Server,
val client: Client
)
{
def close(): Unit = {
transactionServer.shutdown()
zkServer.close()
client.shutdown()
}
}
object ZkSeverTxnServerTxnClient {
def apply(zkServer: TestingServer,
transactionServer: Server,
client: Client): ZkSeverTxnServerTxnClient =
new ZkSeverTxnServerTxnClient(
zkServer,
transactionServer,
client
)
}
示例8: TestBase
//设置package包名称以及导入依赖的类
package uk.co.appministry.akka.zk
import akka.actor.ActorSystem
import akka.testkit.{ImplicitSender, TestKit}
import com.typesafe.config.ConfigFactory
import org.apache.curator.test.TestingServer
import org.scalatest.concurrent.Eventually
import org.scalatest.time.{Millis, Seconds, Span}
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}
import uk.co.appministry.akka.zk.utils.FreePort
import scala.concurrent.duration._
class TestBase extends TestKit(ActorSystem("testing")) with ImplicitSender
with WordSpecLike
with BeforeAndAfterAll
with Matchers
with Eventually {
override implicit val patienceConfig = PatienceConfig(timeout = scaled(Span(20, Seconds)), interval = scaled(Span(100, Millis)))
var zookeeper: TestingServer = _
val defaultConnectedMsgWait = 10 seconds
override def beforeAll {
super.beforeAll()
ConfigFactory.load().resolve()
zookeeper = new TestingServer(FreePort.getFreePort)
zookeeper.start()
}
override def afterAll {
super.afterAll()
zookeeper.stop()
}
}
示例9: zkConnectString
//设置package包名称以及导入依赖的类
package tanukkii.reactivezk
import java.io.{IOException, File}
import com.google.common.io.Closeables
import org.apache.curator.test.TestingServer
import org.scalatest.{BeforeAndAfterAll, Suite}
trait ZooKeeperTest extends Suite with BeforeAndAfterAll {
var testingServer: TestingServer = _
val dataDir: String
def zkConnectString: String = testingServer.getConnectString
def zkPort: Int = testingServer.getPort
override protected def beforeAll(): Unit = {
testingServer = new TestingServer(-1, new File(dataDir))
testingServer.start()
super.beforeAll()
}
override protected def afterAll(): Unit = {
try {
Closeables.close(testingServer, true)
} catch {
case e: IOException =>
}
super.afterAll()
}
}