Ensuring serialization in unit tests

29 views
Skip to first unread message

Stuart Reynolds

unread,
Apr 24, 2016, 7:24:47 PM4/24/16
to OrientDB
I'm working on some extensions to the soriento scala wrapper for orientdb.
I'm trying to write some unit tests like this:



   
implicit val db: ODatabaseDocumentTx = new ODatabaseDocumentTx("memory:jsondb")
    db
.create()
   
...
    db
.save(myObj)

   
...
    db
.queryBySql[MyObj]("select * from MyObj;")

queryBySql is provided by Soriento.
What I find is that the object saved to the DB has the same identity (according to System.identityHashCode), as the object loaded (i.e. it was never serialized -- the same reference is received from the query, as was saved). Therefore, serialization is not tested.

This makes sense -- presumably the memory database has no need to serialize. However, my unit tests really need to force serialization to happen. I get the same result if creating a plocal.

So, what's the best way to set up and tear down an orientdb DB for unit tests so that serialization happens for saves and loads? (I can't rely on an external DB since other people will need to run the unit test.)


Stuart Reynolds

unread,
Apr 24, 2016, 7:33:41 PM4/24/16
to OrientDB
Update: to be a little more precise.

case class Y
case class MyObj(val a:String: val b:List[Y])

I save a MyObj, its loaded back as a document and the identityHashCode of the b attribute is identical to the saved object's.
Reply all
Reply to author
Forward
0 new messages