本文整理汇总了Scala中scala.compat.Platform类的典型用法代码示例。如果您正苦于以下问题:Scala Platform类的具体用法?Scala Platform怎么用?Scala Platform使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Platform类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: PaymentProtocolSpec
//设置package包名称以及导入依赖的类
package fr.acinq.syscoin
import java.io._
import java.security._
import java.security.cert.{CertificateFactory, X509Certificate}
import java.security.spec.PKCS8EncodedKeySpec
import com.google.protobuf.ByteString
import org.syscoin.protocols.payments.Protos.{Output, PaymentDetails, PaymentRequest}
import org.bouncycastle.util.io.pem.PemReader
import org.junit.runner.RunWith
import org.scalatest.FlatSpec
import org.scalatest.junit.JUnitRunner
import scala.compat.Platform
@RunWith(classOf[JUnitRunner])
class PaymentProtocolSpec extends FlatSpec {
val keystore = KeyStore.getInstance("JKS")
keystore.load(classOf[PaymentProtocolSpec].getResourceAsStream("/cacerts"), null)
val aliases = keystore.aliases()
"Payment protocol" should "verify payment requests" in {
val stream = classOf[PaymentProtocolSpec].getResourceAsStream("/r1411736682.syscoinpaymentrequest")
val request = PaymentRequest.parseFrom(stream)
val (name, publicKey, trustAnchor) = PaymentProtocol.verifySignature(request, keystore)
assert(name === "www.syscoincore.org")
// check that we get an exception if we attempt to modify payment details
val details = PaymentDetails.parseFrom(request.getSerializedPaymentDetails)
val request1 = request.toBuilder.setSerializedPaymentDetails(details.toBuilder.setPaymentUrl("foo").build().toByteString).build()
intercept[RuntimeException] {
PaymentProtocol.verifySignature(request1, keystore)
}
}
it should "sign payment requests" in {
val factory = CertificateFactory.getInstance("X.509")
val cacert = factory.generateCertificate(classOf[PaymentProtocolSpec].getResourceAsStream("/cacert.pem")).asInstanceOf[X509Certificate]
val servercert = factory.generateCertificate(classOf[PaymentProtocolSpec].getResourceAsStream("/servercert.pem")).asInstanceOf[X509Certificate]
//val cert3 = factory.generateCertificate(classOf[PaymentProtocolSpec].getResourceAsStream("/ca-int2.crt")).asInstanceOf[X509Certificate]
val keyPair = new PemReader(new InputStreamReader(classOf[PaymentProtocolSpec].getResourceAsStream("/serverkey.pem"))).readPemObject()
val keyFactory = KeyFactory.getInstance("RSA")
val key = keyFactory.generatePrivate(new PKCS8EncodedKeySpec(keyPair.getContent))
keystore.setCertificateEntry("foo", cacert)
val details = PaymentDetails.newBuilder()
.addOutputs(Output.newBuilder().setAmount(100).setScript(ByteString.EMPTY))
.setMemo("foo")
.setPaymentUrl("")
.setTime(Platform.currentTime)
val request = PaymentRequest.newBuilder()
.setPaymentDetailsVersion(1)
.setSerializedPaymentDetails(details.build().toByteString)
.build
val request1 = PaymentProtocol.sign(request, Seq(servercert), key)
val (name, publicKey, trustAnchor) = PaymentProtocol.verifySignature(request1, keystore)
assert(name === "Foobar")
}
}
开发者ID:sidhujag,项目名称:syscoin-lib,代码行数:61,代码来源:PaymentProtocolSpec.scala
示例2: NormalSpec
//设置package包名称以及导入依赖的类
package com.github.dnvriend.perf
import com.github.dnvriend.IntegrationSpec
import scala.compat.Platform
class NormalSpec extends IntegrationSpec {
it should "perform with type 'String'" in withSingleEntity { pid => entity =>
val numberOfEvents = 10000
val eventsSender = persistEvents(pid, entity, "NormalSpec", numberOfEvents)
val eventsReader = readEvents(pid, numberOfEvents)
val start = Platform.currentTime
eventsSender.futureValue
println(s"Writing events took: ${Platform.currentTime - start} ms")
eventsReader.futureValue.size shouldBe numberOfEvents
println(s"Reading events took: ${Platform.currentTime - start} ms")
}
}
开发者ID:dnvriend,项目名称:akka-persistence-cassandra-test,代码行数:21,代码来源:NormalSpec.scala
示例3: FastSpec
//设置package包名称以及导入依赖的类
package com.github.dnvriend.perf
import com.github.dnvriend.IntegrationSpec
import scala.compat.Platform
class FastSpec extends IntegrationSpec {
def writeEvents(numberOfEvents: Int): Unit = withRoundRobinEntity { pid => entity =>
val eventsSender = persistEvents(pid, entity, "FastSpec", numberOfEvents)
val eventsReader = readEvents(pid, numberOfEvents)
val start = Platform.currentTime
eventsSender.futureValue
println(s"Writing events took: ${Platform.currentTime - start} ms")
eventsReader.futureValue.size shouldBe numberOfEvents
println(s"Reading events took: ${Platform.currentTime - start} ms")
}
it should "perform with type 'String'" in {
(1 to 5).foreach( _ => writeEvents(10000))
}
}
开发者ID:dnvriend,项目名称:akka-persistence-cassandra-test,代码行数:24,代码来源:FastSpec.scala
示例4: MetricHelper
//设置package包名称以及导入依赖的类
package com.evolutiongaming.util
import com.codahale.metrics.{Gauge, Histogram, MetricRegistry, Timer}
import scala.compat.Platform
import scala.concurrent.duration._
import scala.concurrent.{ExecutionContext, Future}
import scala.util.control.NonFatal
object MetricHelper {
object GaugeF {
def apply[T](f: => T): Gauge[T] = new Gauge[T] { def getValue: T = f }
}
implicit class RichTimer(val timer: Timer) extends AnyVal {
def timeExceed[T](limit: FiniteDuration)(f: => T): T = {
val start = Platform.currentTime
try f finally {
val stop = Platform.currentTime
val duration = stop - start
if (duration >= limit.toMillis) timer.update(duration, MILLISECONDS)
}
}
def timeFuture[T](f: => Future[T])(implicit ec: ExecutionContext): Future[T] = {
val time = timer.time()
try f andThen { case _ => time.stop() } catch {
case NonFatal(e) => time.stop(); throw e
}
}
def timeFunc[T](f: => T): T = {
val time = timer.time()
try f finally time.stop()
}
}
implicit class HistogramOps(val histogram: Histogram) extends AnyVal {
def timeFunc[T](f: => T): T = {
val start = Platform.currentTime
try f finally histogram.update(Platform.currentTime - start)
}
def timeFuture[T](f: => Future[T])(implicit ec: ExecutionContext): Future[T] = {
val start = Platform.currentTime
f andThen { case _ => histogram.update(Platform.currentTime - start) }
}
}
implicit class MetricRegistryOps(val self: MetricRegistry) extends AnyVal {
def gauge[T](name: String, f: => T): Gauge[T] = {
self remove name
self.register(name, GaugeF(f))
}
}
}
开发者ID:evolution-gaming,项目名称:metric-tools,代码行数:58,代码来源:MetricHelper.scala
示例5: AnnouncementsSpec
//设置package包名称以及导入依赖的类
package fr.acinq.eclair.router
import fr.acinq.eclair.TestConstants.Alice
import fr.acinq.eclair._
import fr.acinq.eclair.router.Announcements._
import org.junit.runner.RunWith
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner
import scala.compat.Platform
@RunWith(classOf[JUnitRunner])
class AnnouncementsSpec extends FunSuite {
test("create valid signed channel announcement") {
val (node_a, node_b, bitcoin_a, bitcoin_b) = (randomKey, randomKey, randomKey, randomKey)
val (node_a_sig, bitcoin_a_sig) = signChannelAnnouncement(42, node_a, node_b.publicKey, bitcoin_a, bitcoin_b.publicKey, "")
val (node_b_sig, bitcoin_b_sig) = signChannelAnnouncement(42, node_b, node_a.publicKey, bitcoin_b, bitcoin_a.publicKey, "")
val ann = makeChannelAnnouncement(42, node_a.publicKey, node_b.publicKey, bitcoin_a.publicKey, bitcoin_b.publicKey, node_a_sig, node_b_sig, bitcoin_a_sig, bitcoin_b_sig)
assert(checkSigs(ann))
assert(checkSigs(ann.copy(nodeId1 = randomKey.publicKey)) === false)
}
test("create valid signed node announcement") {
val ann = makeNodeAnnouncement(Alice.nodeParams.privateKey, Alice.nodeParams.alias, Alice.nodeParams.color, Alice.nodeParams.address :: Nil, Platform.currentTime / 1000)
assert(checkSig(ann))
assert(checkSig(ann.copy(timestamp = 153)) === false)
}
test("create valid signed channel update announcement") {
val ann = makeChannelUpdate(Alice.nodeParams.privateKey, randomKey.publicKey, 45561, Alice.nodeParams.expiryDeltaBlocks, Alice.nodeParams.htlcMinimumMsat, Alice.nodeParams.feeBaseMsat, Alice.nodeParams.feeProportionalMillionth, Platform.currentTime / 1000)
assert(checkSig(ann, Alice.nodeParams.privateKey.publicKey))
assert(checkSig(ann, randomKey.publicKey) === false)
}
}
开发者ID:viacoin,项目名称:eclair,代码行数:38,代码来源:AnnouncementsSpec.scala
示例6: UpdateProducer
//设置package包名称以及导入依赖的类
package com.github.dnvriend
import java.util.UUID
import akka.Done
import akka.actor.ActorSystem
import akka.kafka.ProducerSettings
import akka.kafka.scaladsl.Producer
import akka.stream.ActorMaterializer
import akka.stream.scaladsl.{ Sink, Source }
import com.sksamuel.avro4s.RecordFormat
import org.apache.avro.generic.GenericRecord
import org.apache.kafka.clients.producer.ProducerRecord
import play.api.libs.json.Json
import scala.compat.Platform
import scala.concurrent.Future
import scala.util.Random
object UpdateProducer extends App {
final case class Update(name: String, count: Int)
object Update {
implicit val recordFormat = RecordFormat[Update]
}
implicit val system = ActorSystem()
implicit val mat = ActorMaterializer()
implicit val ec = system.dispatcher
val producerSettings: ProducerSettings[String, GenericRecord] = ProducerSettings[String, GenericRecord](system, None, None)
.withBootstrapServers("localhost:9092")
def randomId: String = UUID.randomUUID.toString
def genericRecord[A](value: A)(implicit recordFormat: RecordFormat[A]): GenericRecord = recordFormat.to(value)
def record[A: RecordFormat](topic: String, key: String, value: A): ProducerRecord[String, GenericRecord] =
new ProducerRecord(topic, key, genericRecord(value))
val sink: Sink[ProducerRecord[String, GenericRecord], Future[Done]] =
Producer.plainSink(producerSettings)
val done =
Source.repeat(1)
.take(10)
.map(value => record("Updatess", "foo", Update("foo", 1)))
.runWith(sink)
val start = Platform.currentTime
(for {
_ <- done
_ <- system.terminate()
} yield println("took: " + (Platform.currentTime - start) + " millis")).recoverWith {
case t: Throwable =>
t.printStackTrace()
system.terminate()
}
}
开发者ID:dnvriend,项目名称:kafka-streams-test,代码行数:59,代码来源:UpdateProducer.scala
注:本文中的scala.compat.Platform类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论