Test cases for ResultSetFuture to Future[ResultSet]

336 views
Skip to first unread message

Arun Sethia

unread,
Jun 14, 2017, 11:00:56 AM6/14/17
to DataStax Java Driver for Apache Cassandra User Mailing List
Hi,

As described here https://stackoverflow.com/questions/18026601/listenablefuture-to-scala-future , I am able to convert my ResultSetFuture to Future[ResultSet], I would like to write test cases (using stubs) for the same using scalamock, my code looks like this, but program hangs it is not giving resultSet back.

val dbConn = stub[DataBaseConnection]
val dbSession = stub[Session]
(dbConn.getSession: () => Session).when().returns(dbSession)
val selectResult: ResultSet = stub[ResultSet]
val rows = new util.ArrayList[Row]();
val row = stub[Row]
val query="SELECT name FROM table"
val resultSetFuture: ResultSetFuture = stub[ResultSetFuture]
(dbSession.executeAsync(_: String)).when(query).returns(resultSetFuture)


where execute async is defined as following

val resultSetFuture: Future[ResultSet] = session.executeAsync(builtStatement).asScala
resultSetFuture.map(result => {
  result.isExhausted match {
    case true => Some(List())
    case false => Some(result.all().asScala.map(row => transformer.buildResult(row)).toList)
  }
})


Thanks 
Arun

Flavian Alexandru

unread,
Jun 16, 2017, 9:53:34 AM6/16/17
to java-dri...@lists.datastax.com
Hi,

You can just use phantom which will give you a full Scala flavour API for what you need, with support for Scala futures, Twitter Futures, reactive streams, iteratees integration and much more. I know this is a sledgehammer to crack open a small nut, but if you are using Scala as a primary language, the Java driver is not your best choice, it's far faster and easier to work with native Scala DSLs.

https://github.com/outworkers/phantom

Also have a look at the tests in phantom, to get a glimpse on how to test Cassandra queries using phantom. There's a tutorial here.

Regards,


--
You received this message because you are subscribed to the Google Groups "DataStax Java Driver for Apache Cassandra User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-user+unsubscribe@lists.datastax.com.



--
Regards,
Flavian
Reply all
Reply to author
Forward
0 new messages