Lagom service test to use real Cassancra - scala

I am creating a service test based on this docs: https://www.lagomframework.com/documentation/1.6.x/scala/TestingServices.html
I don't want to use Lagom's built in Cassandra, so I have this in my sbt file:
ThisBuild / lagomCassandraEnabled := false
ThisBuild / lagomUnmanagedServices := Map("cas_native" -> "tcp://...:9042")
ThisBuild / lagomKafkaEnabled := false
ThisBuild / lagomKafkaAddress := "...:9092"
but it is not taken into consideration probably, because I am getting this error:
com.google.common.util.concurrent.UncheckedExecutionException: com.datastax.driver.core.exceptions.InvalidQueryException: Keyspace 'xyz' does not exist
How can I make the test use the real db? I assume it is still using Lagom's built in Cassandra.

Related

Debug query with offical mongodb golang package (command monitoring)

I'm trying to print mongodb query created with "go.mongodb.org/mongo-driver/mongo" package. Is there any option to take a look at the query produced by this package or dump it in any way? I can go inside mongod instance and modify profiling level and see the queries from mongod, but it's not the right way.
Thanks to user D. SM I've got a code sample to achieve monitoring of all logs.
cmdMonitor := &event.CommandMonitor{
Started: func(_ context.Context, evt *event.CommandStartedEvent) {
log.Print(evt.Command)
},
}
ctx := context.Background()
clientOpts := options.Client().ApplyURI(connectionString).SetMonitor(cmdMonitor)

Table "play_evolutions" not found

I have a basic development database configured like this:
# Default database configuration using H2 database engine in an in-memory mode
db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:play;DB_CLOSE_DELAY=-1;MODE=MYSQL;DATABASE_TO_UPPER=FALSE"
I added a script to create the tables from the database in conf/evolutions/default/1.sql
When starting the application with sbt run and going to any page, Play asks me to apply the script 1.sql. After pressing the button, I get the following error:
JdbcSQLException: Table "play_evolutions" not found; SQL statement: update play_evolutions set last_problem = ? where id = ? [42102-192]`en`
Shouldn't the play framework already create this?
Versions:
//project/plugins.sbt
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.5.10")
//build.sbt
lazy val root =
(project in file("."))
.enablePlugins(PlayScala)
scalaVersion := "2.11.8"
libraryDependencies += jdbc
libraryDependencies += evolutions
I have checked the 1.sql in evolutions.default package, and there might be something that causes the table not found thing.
USE mydb;
With this statement, your "working schema" is now jdbc:h2:mem:play/mydb.
However the play_evolutions table is created just under the root jdbc:h2:mem:play, meaning nothing under jdbc:h2:mem:play/mydb called play_evolutions, which causes the ERROR.
The solution is easy:
remove USE mydb;
Hope it helps.

Play Framework trying to access DB with windows username

I have a db.conf which looks like this in the conf folder:
db.default.driver=org.postgresql.Driver
db.default.url="jdbc:postgresql://62.210.145.112/babybets"
db.default.username=postgres
db.default.password="my_password"
It is included in the application.conf:
include "db.conf"
Infos are definitely correct, as I use this very same jdbc connection string, user/pass to connect the Intellij DB view to the database.
When I try to access any page, I get an error:
play.api.Configuration$$anon$1: Configuration error[Cannot connect to database [default]]
at play.api.Configuration$.play$api$Configuration$$configError(Configuration.scala:94) ~[play_2.10-2.3.8.jar:2.3.8]
at play.api.Configuration.reportError(Configuration.scala:743) ~[play_2.10-2.3.8.jar:2.3.8]
at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:247) ~[play-jdbc_2.10-2.3.2.jar:2.3.2]
at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:238) ~[play-jdbc_2.10-2.3.2.jar:2.3.2]
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244) ~[scala-library-2.10.5.jar:na]
Caused by: org.postgresql.util.PSQLException: FATAL: password authentication failed for user "John"
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:293) ~[postgresql-9.1-901-1.jdbc4.jar:na]
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:108) ~[postgresql-9.1-901-1.jdbc4.jar:na]
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66) ~[postgresql-9.1-901-1.jdbc4.jar:na]
at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:125) ~[postgresql-9.1-901-1.jdbc4.jar:na]
at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30) ~[postgresql-9.1-901-1.jdbc4.jar:na]
In the above you can see it tries to connect to the database using my windows login "John".
I went through the project with agent Ransack and tried the following (case insensitive) regex:
[^\\]john[^\\]
It only matches with the above error log.
Question: Why is play using my windows login to Connect DB? How to prevent that ?
Just for info my build.sbt looks like this:
name := "babyBets2"
version := "1.0"
lazy val `babybets2` = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.10.5"
libraryDependencies ++= Seq( cache , ws )
libraryDependencies ++= Seq("postgresql" % "postgresql" % "9.1-901-1.jdbc4",
"com.typesafe.play" %% "play-slick" % "0.8.0",
"ws.securesocial" %% "securesocial" % "2.1.4" )
unmanagedResourceDirectories in Test <+= baseDirectory ( _ /"target/web/public/test" )
Ok this is crazy, there is a difference between Play versions:
https://www.playframework.com/documentation/2.4.x/ScalaDatabase
https://www.playframework.com/documentation/2.3.x/ScalaDatabase
db.default.username=postgres
vs
db.default.user=postgres
So apparently, if no user is provided, play displays no useful error messages and tries to connect you with windows login!

How to configure HikariCP for Slick 3.0.0 RC1 on Typesafe conf

I have a Play Application based on the play-scala Typesafe template (Play Scala Seed), and tried to add Slick 3.0.0 to the project and connect to a PostgreSQL database.
First I added the dependencies to build.sbt:
libraryDependencies ++= Seq(
"com.typesafe.slick" %% "slick" % "3.0.0-RC1",
"postgresql" % "postgresql" % "9.1-901.jdbc4"
)
Then added the database configuration on application.conf:
brDb = {
dataSourceClass = org.postgresql.ds.PGSimpleDataSource
url = "jdbc:postgresql://localhost:5432/test"
user = "postgres"
password = "postgres"
numThreads = 10
}
Note that I haven't disabled explicitly the pooling, so it is enabled by default, and will try to use HikariCP, because as of Slick 3.0.0 RC1, HikariCP support exists and pooling using it is enabled by default.
And in my DAO object, tried to get the database connection like this:
Database.forConfig("brDb")
When I run the app using activator run, I get this error:
RuntimeException: java.lang.NoClassDefFoundError:
com/zaxxer/hikari/HikariConfig
Then I tried adding HikariCP as a dependency in build.sbt:
libraryDependencies ++= Seq(
// ...
"com.zaxxer" % "HikariCP" % "2.3.3",
// ...
)
Cleaned and recompiled the app using activator clean compile, and runned it again, but I get another error:
RuntimeException: java.lang.UnsupportedClassVersionError: com/zaxxer/hikari/HikariConfig
I think I am missing some configuration, but I am not sure and have not found more info about it. How should I set up the configuration to get the connection pool working?
That error means that the HikariCP package is compiled for a JRE newer than the one you#re running on. And in fact, if you look at the homepage, you'll see that the version you are using is this:
Java 8 maven artifact:
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>2.3.5</version>
<scope>compile</scope>
</dependency>
I suppose you're running on Java 7. For that, add the following to your build.sbt:
libraryDependencies ++= Seq(
"com.zaxxer" % "HikariCP-java6" % "2.3.3",
)
Btw, I have found out that the configuration structure that you specified above does not actually work as of Slick 3.0.0. What worked for me was to specify the database configuration as described in the documentation http://slick.typesafe.com/doc/3.0.0/database.html#using-typesafe-config, otherwise Slick will assume some default values for the configuration. I'm mainly talking about the "properties" field.
So something like this should work:
mydb = {
dataSourceClass = "org.postgresql.ds.PGSimpleDataSource"
properties = {
serverName = "postgresdb"
portNumber = "5432"
databaseName = "mydb"
user = "myuser"
password = "secret"
}
numThreads = 10
}

Play 2.3.5 and ReactiveMongo: MongoError['No primary node is available!']

I recently upgraded Play to version 2.3.5 and try to use it with ReactiveMongo. However everytime I try to read data from mongoDB an exception occurred. This is my build.sbt:
name := """ReactiveMongoRestExample"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.11.1"
libraryDependencies ++= Seq(
jdbc,
anorm,
cache,
ws,
"org.reactivemongo" %% "play2-reactivemongo" % "0.10.5.0.akka23"
)
This is the stacktrace:
play.api.Application$$anon$1: Execution
exception[[PrimaryUnavailableException$: MongoError['No primary node
is available!']]] at
play.api.Application$class.handleError(Application.scala:296)
~[play_2.11-2.3.5.jar:2.3.5] at
play.api.DefaultApplication.handleError(Application.scala:402)
[play_2.11-2.3.5.jar:2.3.5] at
play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$14$$anonfun$apply$1.applyOrElse(PlayDefaultUpstreamHandler.scala:205)
[play_2.11-2.3.5.jar:2.3.5] at
play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$14$$anonfun$apply$1.applyOrElse(PlayDefaultUpstreamHandler.scala:202)
[play_2.11-2.3.5.jar:2.3.5] at
scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:36)
[scala-library-2.11.2.jar:na] Caused by:
reactivemongo.core.actors.Exceptions$PrimaryUnavailableException$:
MongoError['No primary node is available!'] at
reactivemongo.core.actors.Exceptions$PrimaryUnavailableException$.(actors.scala)
~[reactivemongo_2.11-0.10.5.0.akka23.jar:0.10.5.0.akka23] at
reactivemongo.core.actors.MongoDBSystem$$anonfun$pickChannel$4.apply(actors.scala:508)
~[reactivemongo_2.11-0.10.5.0.akka23.jar:0.10.5.0.akka23] at
reactivemongo.core.actors.MongoDBSystem$$anonfun$pickChannel$4.apply(actors.scala:508)
~[reactivemongo_2.11-0.10.5.0.akka23.jar:0.10.5.0.akka23] at
scala.Option.getOrElse(Option.scala:120)
~[scala-library-2.11.2.jar:na] at
reactivemongo.core.actors.MongoDBSystem.pickChannel(actors.scala:508)
~[reactivemongo_2.11-0.10.5.0.akka23.jar:0.10.5.0.akka23]
MongoDB works fine. I'm able to retrieve data with the commandline tool and IntelliJ.
I pushed the code to github
Maybe someone knows the issue and can help me? That would be awesome
Same issue though updated to Play 2.3.8 with same rx mongo plugin. Mongodb backed works fine under mongo shell as does mongo explorer in intellij idea 14.
Using mongodb.uri in application.conf:
mongodb.uri = "mongodb://pxxxxxxxx:pxxxxxxxx#berne:27017/playdb"
Digging deeper on assumption this is a configuration issue.
Henry
It's probably unable to start the Mongo server.
Go to your /bin folder and run mongo.
You might have too little room available on your temporary folder.
try running : mongo --smallfiles
I had this error because I tried to connect to the db with an unknown user. Creating the user resolved the error.