• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala TestingServer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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
} 
开发者ID:Box-Castle,项目名称:core,代码行数:25,代码来源:MockZookeeperServer.scala


示例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)
} 
开发者ID:ciaran-,项目名称:specs2-kafka,代码行数:44,代码来源:SimpleKafkaScope.scala


示例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)
  }
} 
开发者ID:saikocat,项目名称:spark-sql-kafka-avroflumeevent,代码行数:62,代码来源:TestHelper.scala


示例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()
      }
    })
  }
} 
开发者ID:bwsw,项目名称:bookkeeper-tutorial-scala,代码行数:59,代码来源:ZookeeperServerStartup.scala


示例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()
  }

} 
开发者ID:bwsw,项目名称:imp,代码行数:32,代码来源:CuratorTests.scala


示例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)
} 
开发者ID:bwsw,项目名称:tstreams-transaction-server,代码行数:20,代码来源:ZkSeverAndTransactionServer.scala


示例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
    )
} 
开发者ID:bwsw,项目名称:tstreams-transaction-server,代码行数:29,代码来源:ZkSeverTxnServerTxnClient.scala


示例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()
  }

} 
开发者ID:AppMinistry,项目名称:akka-zk,代码行数:39,代码来源:TestBase.scala


示例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()
  }
} 
开发者ID:TanUkkii007,项目名称:reactive-zookeeper,代码行数:33,代码来源:ZooKeeperTest.scala



注:本文中的org.apache.curator.test.TestingServer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala PipelineStage类代码示例发布时间:2022-05-23
下一篇:
Scala ConsoleReporter类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap