本文整理汇总了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
}
}
}
示例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)
}
}
示例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()
}
示例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))
}
}
}
}
示例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()
}
}