1

Can someone tell me what "Fragment evaluation error" means, or where I might look for solutions? I sometimes (but not always) get lots of these errors (without changing my code):

[error] ! Fragment evaluation error
[error]     ThrowableException: Could not initialize class code.model.Post$  (FutureTask.java:138)
[error] code.model.PostSpec$$anonfun$1$$anonfun$apply$1.apply$mcZ$sp(PostSpec.scala:68)
[error] code.model.PostSpec$$anonfun$1$$anonfun$apply$1.apply(PostSpec.scala:51)
[error] code.model.PostSpec$$anonfun$1$$anonfun$apply$1.apply(PostSpec.scala:51)

Line 68 of PostSpec is the first line in the (specs2) test that references the Post model companion object:

val test4 = Post.fixJValue(toextract4).extract[Selection]

I'm using Scala 2.9.0-1.

Also: I have no idea whether it matters, but Post is a net.liftweb.mongodb.record.MongoRecord class companion object:

object Post extends Post with MongoMetaRecord[Post] { ... }
brandon
  • 675
  • 6
  • 10
  • Here's a convenient link to the [source code of FutureTask.java](http://javasourcecode.org/html/open-source/jdk/jdk-6u23/java/util/concurrent/FutureTask.java.html). Line 138 is a call to sync.innerRun(): `public void run() { sync.innerRun(); }` – brandon Sep 14 '11 at 22:39
  • I have also been having issues with mongo and specs2 – wfbarksdale Aug 28 '12 at 02:01

1 Answers1

2

In a specs2 specification, Fragments are pieces of the specification. A Fragment can be a Text, an Example, a Step.

Some fragments, like Example and Step are meant to be executed and are supposed to catch Exceptions so that they can be marked as failures. But they won't catch Errors (except AssertionErrors). So if an Example throws an OutOfMemoryError, this will be reported as a Fragment evaluation error.

Other fragments, like Text fragments are not supposed to throw exceptions when being evaluated. If they do, you will get the same Fragment evaluation error message.

Without seeing the full specification it's hard for me to say what's happening there but I suspect that you had a non-Exception type thrown in the body of an Example. But I have more questions than answers for now:

  • where is test4 declared? Inside the specification body? Inside a Context case class?
  • since errors happen intermittently, are you sure you always have a proper mongodb context? Maybe your specification examples are being executed concurrently on the same mongo db instance?
Eric
  • 15,494
  • 38
  • 61
  • `test4` is declared inside a specification body. In this case, the method that I'm calling (`Post.fixJValue(JValue):JValue`) is just a convenience method that was (...well...) convenient to place inside the `Post` object -- it actually does no work on mongodb. – brandon Sep 15 '11 at 02:25
  • Maybe you could try to declare the val as a lazy val so that its evaluation really happens during the example execution. – Eric Sep 15 '11 at 04:26
  • Your note about "context" got me thinking and searching in a new direction, however. I'll bet that initialization of the MongoMetaRecord object is causing problems. And, I'll bet that moving this method out of that object will resolve the issue. – brandon Sep 15 '11 at 04:47