Cassandra Unit with scala. Not session -
i'm trying test cassandra cassandraunit. pasted test github , translate scala doesn't work.
import org.junit.rule import org.scalatest.funsuite import com.datastax.driver.core.resultset import org.cassandraunit.cassandracqlunit import org.cassandraunit.dataset.cql.classpathcqldataset class cassandratest extends funsuite{ @rule val cassandracqlunit = new cassandracqlunit(new classpathcqldataset("statementswithblankendings.cql", "mykeyspace")) test("really simple transformation") { val session = cassandracqlunit.session val resultset = session.execute("select * testcqltable id='1690e8da-5bf8-49e8-9583-4dff8a570737'") println(resultset.iterator().next().getstring("value")) } } java.lang.nullpointerexception thrown. java.lang.nullpointerexception @ cassandratest$$anonfun$1.apply$mcv$sp(cassandratest.scala:21) @ cassandratest$$anonfun$1.apply(cassandratest.scala:18) @ cassandratest$$anonfun$1.apply(cassandratest.scala:18) @ org.scalatest.outcomeof$class.outcomeof(outcomeof.scala:85) @ org.scalatest.outcomeof$.outcomeof(outcomeof.scala:104) @ org.scalatest.transformer.apply(transformer.scala:22) @ org.scalatest.transformer.apply(transformer.scala:20) @ org.scalatest.funsuitelike$$anon$1.apply(funsuitelike.scala:186) @ org.scalatest.testsuite$class.withfixture(testsuite.scala:196) @ org.scalatest.funsuite.withfixture(funsuite.scala:1560) @ org.scalatest.funsuitelike$class.invokewithfixture$1(funsuitelike.scala:183) @ org.scalatest.funsuitelike$$anonfun$runtest$1.apply(funsuitelike.scala:196) @ org.scalatest.funsuitelike$$anonfun$runtest$1.apply(funsuitelike.scala:196) @ org.scalatest.superengine.runtestimpl(engine.scala:289) @ org.scalatest.funsuitelike$class.runtest(funsuitelike.scala:196) @ org.scalatest.funsuite.runtest(funsuite.scala:1560) @ org.scalatest.funsuitelike$$anonfun$runtests$1.apply(funsuitelike.scala:229) @ org.scalatest.funsuitelike$$anonfun$runtests$1.apply(funsuitelike.scala:229) @ org.scalatest.superengine$$anonfun$traversesubnodes$1$1.apply(engine.scala:396) @ org.scalatest.superengine$$anonfun$traversesubnodes$1$1.apply(engine.scala:384) @ scala.collection.immutable.list.foreach(list.scala:381) @ org.scalatest.superengine.traversesubnodes$1(engine.scala:384) @ org.scalatest.superengine.org$scalatest$superengine$$runtestsinbranch(engine.scala:379) @ org.scalatest.superengine.runtestsimpl(engine.scala:461) @ org.scalatest.funsuitelike$class.runtests(funsuitelike.scala:229) @ org.scalatest.funsuite.runtests(funsuite.scala:1560) @ org.scalatest.suite$class.run(suite.scala:1147) @ org.scalatest.funsuite.org$scalatest$funsuitelike$$super$run(funsuite.scala:1560) @ org.scalatest.funsuitelike$$anonfun$run$1.apply(funsuitelike.scala:233) @ org.scalatest.funsuitelike$$anonfun$run$1.apply(funsuitelike.scala:233) @ org.scalatest.superengine.runimpl(engine.scala:521) @ org.scalatest.funsuitelike$class.run(funsuitelike.scala:233) @ org.scalatest.funsuite.run(funsuite.scala:1560) @ org.scalatest.tools.suiterunner.run(suiterunner.scala:45) @ org.scalatest.tools.runner$$anonfun$dorunrunrundadorunrun$1.apply(runner.scala:1340) @ org.scalatest.tools.runner$$anonfun$dorunrunrundadorunrun$1.apply(runner.scala:1334) @ scala.collection.immutable.list.foreach(list.scala:381) @ org.scalatest.tools.runner$.dorunrunrundadorunrun(runner.scala:1334) @ org.scalatest.tools.runner$$anonfun$runoptionallywithpassfailreporter$2.apply(runner.scala:1011) @ org.scalatest.tools.runner$$anonfun$runoptionallywithpassfailreporter$2.apply(runner.scala:1010) @ org.scalatest.tools.runner$.withclassloaderanddispatchreporter(runner.scala:1500) @ org.scalatest.tools.runner$.runoptionallywithpassfailreporter(runner.scala:1010) @ org.scalatest.tools.runner$.run(runner.scala:850) @ org.scalatest.tools.runner.run(runner.scala) @ org.jetbrains.plugins.scala.testingsupport.scalatest.scalatestrunner.runscalatest2(scalatestrunner.java:138) @ org.jetbrains.plugins.scala.testingsupport.scalatest.scalatestrunner.main(scalatestrunner.java:28)
session variable null don't know why. understand cassandracqlunit has cassandra server in same vm. necessary else?
you need startup server , connect. can load data in:
import com.datastax.driver.core.{cluster, session} import org.cassandraunit.cqldataloader import org.cassandraunit.dataset.cql.classpathcqldataset import org.cassandraunit.utils.embeddedcassandraserverhelper import org.scalatest.{beforeandafterall, funsuite} class cassandratest extends funsuite beforeandafterall { var cluster : cluster = _ var session : session = _ override def beforeall(): unit = { embeddedcassandraserverhelper.startembeddedcassandra(embeddedcassandraserverhelper.cassandra_rndport_yml_file) cluster = embeddedcassandraserverhelper.getcluster() session = cluster.connect() val dataloader = new cqldataloader(session) dataloader.load(new classpathcqldataset("statementswithblankendings.cql","mykeyspace")) } test("really simple transformation") { val resultset = session.execute("select * mykeyspace.testcqltable id='1690e8da-5bf8-49e8-9583-4dff8a570737'") println(resultset.iterator().next().getstring("value")) } }
Comments
Post a Comment