我收到一个错误,说我的文件太长了.
[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.
我正在尝试围绕无符号整数和有符号整数设计编号系统.这两种类型都有一个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) 这是我从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) 我目前正在测试一个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) 我有这些案例类:
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
我的Policy
case类中的字段从外键值映射到case类的实际实例的最佳方法是什么PolicyHolder
.
我正在尝试修改我用于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表的主键.以下是我的表的定义方式:
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) 我试图找到一种方法来获得异步before
和after
语句,其中下一个测试用例在测试用例内部的操作完成之前不会运行.就我而言,它是在数据库中创建和删除表
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) 我试图从我的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) 我正在尝试使用 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
?