小编Chr*_*art的帖子

文件名太长sbt

我收到一个错误,说我的文件太长了.

 [info] Compiling 29 Scala sources to /home/chris/dev/suredbits-core/target/scala-2.11/classes...
    [error] File name too long
    [error] one error found
    [error] (compile:compile) Compilation failed
    [error] Total time: 7 s, completed Feb 17, 2015 8:10:25 AM
Run Code Online (Sandbox Code Playgroud)

如何找出哪个文件太长,以便缩短文件名?我添加了编译器标志-Xmax-classfile-name并将其设置为254.

scala sbt

29
推荐指数
3
解决办法
7339
查看次数

使用未签名和签名的整数设计编号系统

我正在尝试围绕无符号整数和有符号整数设计编号系统.这两种类型都有一个underlying值,表示Scala数字系统中的数字.这是我到目前为止的类型层次结构.

sealed trait Number {
  def + (num : Number) : Number = ???
  def - (num : Number) : Number = ???
  def * (num : Number) : Number = ???
}

sealed trait SignedNumber extends Number

sealed trait UnsignedNumber extends Number

sealed trait UInt32 extends UnsignedNumber {
  def underlying : Long
}

sealed trait UInt64 extends UnsignedNumber {
  def underlying : BigInt
}

sealed trait Int32 extends SignedNumber {
  def underlying : Int
}

sealed trait …
Run Code Online (Sandbox Code Playgroud)

scala

10
推荐指数
1
解决办法
410
查看次数

为什么Akka在使用ScalaTest进行测试时失败并出现"IllegalStateException:在终止或终止时无法创建子节点"?

这是我从Akka收到的错误:

[debug] Running TaskDef(com.suredbits.core.util.time.TimeUtilUnitTest, org.scalatest.tools.Framework$$anon$1@7e1522e, false, [SuiteSelector])
[debug] Running TaskDef(com.suredbits.core.address.AddressDAOSystemTest, org.scalatest.tools.Framework$$anon$1@7e1522e, false, [SuiteSelector])
[debug] Running TaskDef(com.suredbits.core.policy.PolicyHolderDAOUnitTest, org.scalatest.tools.Framework$$anon$1@7e1522e, false, [SuiteSelector])
[debug] Running TaskDef(rpc.ModesTest, org.scalatest.tools.Framework$$anon$1@7e1522e, false, [SuiteSelector])
[debug] Running TaskDef(com.suredbits.core.policy.PolicyDAOSystemTest, org.scalatest.tools.Framework$$anon$1@7e1522e, false, [SuiteSelector])
java.lang.IllegalStateException: cannot create children while terminating or terminated
    at akka.actor.dungeon.Children$class.makeChild(Children.scala:199)
    at akka.actor.dungeon.Children$class.attachChild(Children.scala:41)
    at akka.actor.ActorCell.attachChild(ActorCell.scala:369)
    at akka.actor.ActorSystemImpl.systemActorOf(ActorSystem.scala:551)
    at akka.testkit.TestKitBase$class.$init$(TestKit.scala:125)
    at akka.testkit.TestKit.<init>(TestKit.scala:718)
    at com.suredbits.core.policy.PolicyDAOSystemTest.<init>(PolicyDAOSystemTest.scala:34)
    at com.suredbits.core.policy.PolicyDAOSystemTest.<init>(PolicyDAOSystemTest.scala:46)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at java.lang.Class.newInstance(Class.java:379)
    at org.scalatest.tools.Framework$ScalaTestTask.execute(Framework.scala:641)
    at sbt.TestRunner.runTest$1(TestFramework.scala:84)
    at sbt.TestRunner.run(TestFramework.scala:94)
    at sbt.TestFramework$$anon$2$$anonfun$$init$$1$$anonfun$apply$8.apply(TestFramework.scala:219)
    at sbt.TestFramework$$anon$2$$anonfun$$init$$1$$anonfun$apply$8.apply(TestFramework.scala:219)
    at sbt.TestFramework$.sbt$TestFramework$$withContextLoader(TestFramework.scala:207)
    at sbt.TestFramework$$anon$2$$anonfun$$init$$1.apply(TestFramework.scala:219) …
Run Code Online (Sandbox Code Playgroud)

scala akka

8
推荐指数
1
解决办法
4687
查看次数

在1秒的Scala Spray Testing中,请求既未完成也未被拒绝

我目前正在测试一个Web服务,并且我一直在遇到Web服务测试失败的错误,因为它已超时.我试图将超时延长到5秒.我试图模仿一个解决方案,一些人发布在Scala Spray谷歌组论坛上无济于事.这是我试图在我的测试中使用的代码:

import akka.testkit._
import akka.actor.ActorSystem
import com.github.nfldb.config.{NflDbApiActorSystemConfig, NflDbApiDbConfigTest}
import org.scalatest.MustMatchers
import org.specs2.mutable.Specification
import spray.testkit.Specs2RouteTest
import spray.routing.HttpService
import spray.http.StatusCodes._
import spray.json.DefaultJsonProtocol._
import spray.httpx.SprayJsonSupport._
import concurrent.duration._

/**
 * Created by chris on 8/25/15.
 */
class NflPlayerScoringSvcTest extends Specification with Specs2RouteTest  with NflPlayerScoringService
  with NflDbApiDbConfigTest with NflDbApiActorSystemConfig {
  import PlayerScoreProtocol.playerScoreProtocol
  implicit def actorRefFactory = actorSystem
  implicit def default(system: ActorSystem = actorSystem) = RouteTestTimeout(new DurationInt(5).second.dilated)

  "NflPlayerScoringSvc" should {

    "return hello" in {
      Get("/hello") ~> nflPlayerScoringServiceRoutes ~> check {
        responseAs[String] must contain("Say …
Run Code Online (Sandbox Code Playgroud)

scala spray

8
推荐指数
2
解决办法
3978
查看次数

定义投影以映射到嵌套的案例类

我有这些案例类:

case class PolicyHolder(id : String, firstName : String, lastName : String)
case class Policy(address : Future[Address], policyHolder : Future[PolicyHolder], created : RichDateTime, duration : RichDuration )
Run Code Online (Sandbox Code Playgroud)

然后我为Policy定义了一个光滑的模式

class PolicyDAO(tag: Tag) extends Table[Policy](tag, "POLICIES") with DbConfig {
  def address = column[String]("ADDRESS", O.PrimaryKey)
  def policyHolder = foreignKey("POLICY_HOLDER_FK", address, TableQuery[PolicyHolderDAO])(_.id)

  def created = column[RichDateTime]("CREATED")
  def duration = column[String]("DURATION")

  def * = (address, policyHolder, created, duration) <> (Policy.apply, Policy.unapply)
}
Run Code Online (Sandbox Code Playgroud)

对我来说,正确定义此投影以将policyHolder我的Policycase类中的字段从外键值映射到case类的实际实例的最佳方法是什么PolicyHolder.

scala slick-2.0

7
推荐指数
1
解决办法
244
查看次数

Scala Slick Query中表元素的子类型

我正在尝试修改我用于Scala Slick数据库查询的特征.到目前为止,我有两种方法:

protected def findByPrimaryKey(id: PrimaryKeyType): Query[Table[_], T, Seq]

/**
 * return the row that corresponds with this record
 * @param t - the row to find
 * @return query - the sql query to find this record
 */

protected def find(t: T): Query[Table[_], T, Seq]
Run Code Online (Sandbox Code Playgroud)

我想修改这两个方法签名以允许子类型T.一个例子是如果我有一个记录的特征定义,但需要具体实现该特征实际用于光滑.我尝试过这样的事情:

/**
 * return all rows that have a certain primary key
 * @param id
 * @return Query object corresponding to the selected rows
 */
protected def findByPrimaryKey(id: PrimaryKeyType): Query[Table[_], _ <: …
Run Code Online (Sandbox Code Playgroud)

scala slick

7
推荐指数
1
解决办法
239
查看次数

使用Scala Slick创建合成主键

我正在尝试使用两列作为Scala Slick表的主键.以下是我的表的定义方式:

class NbaPlayerBoxScoreTable(tag : Tag) extends Table[NbaPlayerBoxScore](tag, "player_box_scores") {
  import com.suredbits.core.db.ColumnMappers._
  private val gameTable : TableQuery[NbaGameTable] = TableQuery[NbaGameTable]
  private val playerTable  : TableQuery[NbaPlayerTable] = TableQuery[NbaPlayerTable]
  def playerId = column[Long]("player_id", O.PrimaryKey)
  def gameId = column[Long]("game_id", O.PrimaryKey)
  def lastUpdated = column[DateTime]("last_updated")
  def min = column[String]("min")
  def fgm = column[Int]("fgm")
  def fga = column[Int]("fga")
  def tpm = column[Int]("tpm")
  def tpa = column[Int]("tpa")
  def ftm = column[Int]("ftm")
  def fta = column[Int]("fta")
  def plusminus = column[Int]("plusminus")
  def off = column[Int]("off")
  def deff = column[Int]("def") …
Run Code Online (Sandbox Code Playgroud)

scala slick

7
推荐指数
1
解决办法
3541
查看次数

在scalatest中创建和删除scala光滑表之前和之后的异步

我试图找到一种方法来获得异步beforeafter语句,其中下一个测试用例在测试用例内部的操作完成之前不会运行.就我而言,它是在数据库中创建和删除表

  val table = TableQuery[BlockHeaderTable]
  val dbConfig: DatabaseConfig[PostgresDriver] = DatabaseConfig.forConfig("databaseUrl")
  val database: Database = dbConfig.db
  before {
    //Awaits need to be used to make sure this is fully executed before the next test case starts
    //TODO: Figure out a way to make this asynchronous 
    Await.result(database.run(table.schema.create), 10.seconds)
  }

  "BlockHeaderDAO" must "store a blockheader in the database, then read it from the database" in {
    //...
  }

  it must "delete a block header in the database" in { …
Run Code Online (Sandbox Code Playgroud)

scala scalatest slick slick-3.0

7
推荐指数
1
解决办法
541
查看次数

Scala在从application.conf获取数据源时没有启动应用程序

我试图从我的application.conf文件中读取数据源,但每次运行我的服务器,或者尝试运行测试用例时,我都会收到错误消息,说明没有应用程序启动.

这是我想要做的一个例子:

试图从我的房产中读取房产的单元测试 application.conf

class DbConfigWebUnitTest extends PlaySpec with OneAppPerSuite {

  implicit override lazy val app: FakeApplication = FakeApplication(
    additionalConfiguration = Map("db.test.url" -> "jdbc:postgresql://localhost:5432/suredbitswebtest",
      "db.test.user" -> "postgres", "db.test.password" -> "postgres", "db.test.driver" -> "org.postgresql.Driver"))
  val dbManagementWeb = new DbManagementWeb with DbConfigWeb with DbTestQualifier
  "DbConfigWebTest" must {
    "have the same username as what is defined in application.conf" in {
      dbManagementWeb.username must be("postgres")
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

这是我的 DbConfigWeb

import play.api.Play.current    
trait DbConfigWeb extends DbConfig { qualifier: DbQualifier =>

      val url: String = current.configuration.getString(qualifier …
Run Code Online (Sandbox Code Playgroud)

scala playframework playframework-2.0 playframework-2.3

6
推荐指数
1
解决办法
6101
查看次数

0 &lt;= x &lt; 2^64 之间的 Scalacheck 数字生成器

我正在尝试使用 C 语言修复一个很好的数字生成器uint64_t。这是我目前所拥有的。

def uInt64s : Gen[BigInt] = Gen.choose(0,64).map(pow2(_) - 1)
Run Code Online (Sandbox Code Playgroud)

这是一个好的开始,但它只生成数字2^n - 1。有没有更有效的方法来生成随机 BigInts 同时保留数字范围0 <= n < 2^64

scala scalacheck

5
推荐指数
1
解决办法
1416
查看次数