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

Scala SECONDS类代码示例

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

本文整理汇总了Scala中scala.concurrent.duration.SECONDS的典型用法代码示例。如果您正苦于以下问题:Scala SECONDS类的具体用法?Scala SECONDS怎么用?Scala SECONDS使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了SECONDS类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: IBQuoteProviderSpec

//设置package包名称以及导入依赖的类
package com.larroy.openquant.quoteprovider.ib

import java.time.ZonedDateTime

import com.larroy.quant.common.CurrencyContract
import com.typesafe.config.ConfigFactory
import org.slf4j.{Logger, LoggerFactory}
import org.specs2.mutable._

import scala.concurrent.duration.{Duration, SECONDS}
import scala.concurrent.{ExecutionContext, Await}
import scala.util.{Success, Failure}
import net.ceedubs.ficus.Ficus._


class IBQuoteProviderSpec extends Specification {
  private val log: Logger = LoggerFactory.getLogger(this.getClass)
  val cfg = ConfigFactory.load().getConfig("ibquoteprovider.test")
  val timeoutDuration = Duration(cfg.getInt("tws.timeout_s"), SECONDS)
  "IBQuoteProvider" should {
    "get quotes" in { implicit ec: ExecutionContext =>
      val ibQuoteProvider = Await.result(IBQuoteProvider(cfg.as[String]("tws.host"), cfg.as[Int]("tws.port"), cfg.as[Int]("tws.clientId")), timeoutDuration)
      val futureQuotes = ibQuoteProvider.quotes(CurrencyContract("EUR.USD"), ZonedDateTime.now.minusDays(4), ZonedDateTime.now)
      val success = Await.ready(futureQuotes, timeoutDuration).value match {
        // completed with error
        case Some(x @Failure(e)) ? log.error(e.toString)
          false
        // completed with failure
        case Some(Success(bars)) ? log.info(bars.toString)
          true
        // not completed
        case None ? false
      }
      success must beTrue
    }
  }
} 
开发者ID:openquant,项目名称:ibquoteprovider,代码行数:38,代码来源:IBQuoteProviderSpec.scala


示例2: CrudServiceSpec

//设置package包名称以及导入依赖的类
package io.shedin.crud.lib

import org.mockito.Mockito.{verify, when}
import org.scalatest.FlatSpec
import org.scalatest.mockito.MockitoSugar

import scala.concurrent.Await.result
import scala.concurrent.Future
import scala.concurrent.Future.successful
import scala.concurrent.duration.{Duration, SECONDS}

class CrudServiceSpec extends FlatSpec with MockitoSugar {

  class CrudServiceTestImpl(crudRepository: CrudRepository[Int]) extends CrudService[Int](crudRepository)

  private val crudRepository = mock[CrudRepository[Int]]
  private val crudService = new CrudServiceTestImpl(crudRepository)
  private val resource = 123
  private val resourceId = "resourceId"

  private implicit val timeout = Duration(2, SECONDS)

  def await[T](future: Future[T])(implicit timeout: Duration) = result(future, timeout)

  "Crud service" should "delegate creation to a repository" in {
    when(crudRepository.create(resource)).thenReturn(successful(resource))
    await(crudService.create(resource))
    verify(crudRepository).create(resource)
  }

  it should "delegate reading to a repository" in {
    when(crudRepository.read(resourceId)).thenReturn(successful(None))
    await(crudService.read(resourceId))
    verify(crudRepository).read(resourceId)
  }

  it should "delegate whole updates to a repository" in {
    when(crudRepository.update(resourceId, resource)).thenReturn(successful(None))
    await(crudService.update(resourceId, resource))
    verify(crudRepository).update(resourceId, resource)
  }

  it should "delegate partial updates to a repository" in {
    when(crudRepository.update(resourceId, "partial payload")).thenReturn(successful(None))
    await(crudService.update(resourceId, "partial payload"))
    verify(crudRepository).update(resourceId, "partial payload")
  }

  it should "delegate deletion to a repository" in {
    when(crudRepository.delete(resourceId)).thenReturn(successful(true))
    await(crudService.delete(resourceId))
    verify(crudRepository).delete(resourceId)
  }

} 
开发者ID:edinhodzic,项目名称:shedin-crud-lib,代码行数:56,代码来源:CrudServiceSpec.scala


示例3: HttpTest

//设置package包名称以及导入依赖的类
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import com.github.nscala_time.time.Imports._
import play.api.libs.ws._
import play.api.libs.ws.ahc.AhcWSClient
//import scala.concurrent.ExecutionContext.Implicits.global

import scala.concurrent.Await
import scala.concurrent.duration.{Duration, SECONDS}

object HttpTest extends App{

  val url = "http://pit-devvm-opswisemaster2.snc1/opswise/resources/task/ops-task-launch"
  val userName = "ramsubramani"
  val password = "Savitha1$"

  implicit val actor = ActorSystem()
  implicit val materializer = ActorMaterializer()
  val ws = AhcWSClient()
  val request = ws.url(url)
                  .withAuth(userName, password, WSAuthScheme.BASIC)
                  .withHeaders( "Content-Type" -> "application/xml")


  val startDate = DateTime.parse("2017-01-01")
  val endDate = DateTime.parse("2017-01-10")
  val jobName = "Ramesh_test"

  for ( date: DateTime <- startDate to endDate by 1.day){

    val dt = date.toString("yyyy-MM-dd")
    val dtKey = dt.replace("-","")
    val dt1 = date + 1.day toString("yyyy-MM-dd")

    val variableName = "context"
    val variableValue = s"""--context=start_date_key:${dtKey},end_date_key:${dtKey},wf_key:${dtKey},start_date:${dt},end_date:${dt},load_date:${dt},load_start_date:${dt1}"""

    val data =
      <task-launch>
        <name>{jobName}</name>
        <variables>
          <variable>
            <name>{variableName}</name>
            <value>{variableValue}</value>
          </variable>
        </variables>
      </task-launch>

    println(data)
    val resp = request.post(data)
    val result = Await.result(resp, Duration( 5, SECONDS))
    println( result.body)
  }

  ws.close()
  actor.terminate()

} 
开发者ID:ramesavi,项目名称:play-http-example,代码行数:59,代码来源:HttpPostTest.scala


示例4: FileDestination

//设置package包名称以及导入依赖的类
import java.io.{BufferedWriter, FileOutputStream, OutputStreamWriter}
import scala.concurrent.duration.{FiniteDuration, SECONDS}
import com.github.nscala_time.time.Imports._
import org.joda.time.format._
import akka.util.Timeout

package hyperion {

  class FileDestination(id: String, fileName: String, template: String) extends Pipe with Tickable {
    def selfId = id

    val writer = new BufferedWriter(new OutputStreamWriter(
      new FileOutputStream(fileName), "utf-8"))
    var lastMessage = DateTime.now
    implicit val timeout = Timeout(FiniteDuration(1, SECONDS))
    val msgTemplate = if (template == "") new MessageTemplate("<$PRIO> $DATE $HOST $PROGRAM $PID : $MESSAGE \n") else new MessageTemplate(template)
    var processed = 0

    override def preStart() = {
      super.preStart()
      startTicking(FiniteDuration(0, SECONDS), FiniteDuration(1, SECONDS))

    }

    override def postStop() = {
      stopTicking()
      writer.close()
      super.postStop()
    }

    def process = {
      case msg: Message => {
        writer.write(msgTemplate.format(msg))
        processed += 1
        lastMessage = DateTime.now
      }

      case Tick => {

        if (DateTime.now.minus(lastMessage.getMillis).getMillis > 1000L) {
          writer.flush()
        }

      }

      case StatsRequest => {
        sender ! StatsResponse(Map[String, Int]( "processed" -> processed))
      }
    }
  }

} 
开发者ID:talien,项目名称:hyperion,代码行数:53,代码来源:filedestination.scala


示例5: Bootstrap

//设置package包名称以及导入依赖的类
import akka.actor.{ActorRef, ActorSystem}
import akka.stream.ActorMaterializer
import authentication.Authenticator
import authentication.fsm.AuthenticationFSM
import commands.executor.CommandExecutor
import commands.parser.CommandParser
import commands.runner.ClientCommandsLoop
import rest.client.HttpRestClient
import utils.Configuration

import scala.concurrent.duration.{Duration, SECONDS}
import scala.concurrent.{Await, ExecutionContext}

class Bootstrap() {

  def startup(): Unit = {

    implicit val actorSystem: ActorSystem        = ActorSystem("fun-chat-client")
    implicit val materializer: ActorMaterializer = ActorMaterializer()
    implicit val ec: ExecutionContext            = actorSystem.dispatcher

    val config = new Configuration()

    val restClient                  = new HttpRestClient(config)
    val authenticator: ActorRef     = actorSystem.actorOf(Authenticator.props(restClient), "authenticator")
    val authenticationFSM: ActorRef = actorSystem.actorOf(AuthenticationFSM.props(authenticator), "authenticationFSM")

    val commandParser = new CommandParser()
    val messenger: ActorRef = null
    val clientCommandsExecutor: ActorRef =
      actorSystem.actorOf(CommandExecutor.props(commandParser, authenticationFSM, restClient, messenger),
                          "command-executor")

    val exitCallback = (exitCode: Int) => {
      val whenTerminated = actorSystem.terminate()
      Await.result(whenTerminated, Duration(30, SECONDS))
      System.exit(exitCode)
    }

    val clientCommandsLoop = new ClientCommandsLoop(clientCommandsExecutor, exitCallback)
    clientCommandsLoop.start()
  }
} 
开发者ID:lymr,项目名称:fun-chat,代码行数:44,代码来源:Bootstrap.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Scala IndexType类代码示例发布时间:2022-05-23
下一篇:
Scala AsyncWordSpec类代码示例发布时间: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