-
Notifications
You must be signed in to change notification settings - Fork 2
Setup testing #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setup testing #13
Conversation
96d4cd0 to
1ecfcad
Compare
|
|
||
| def fetchMaterial(id: Int): SqlQuery[Option[Material]] = { | ||
| SqlQuery { implicit connection => | ||
| SQL"SELECT * FROM materials where id = {id}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$id
| } yield (professor, material) | ||
| val resF = runner(query) | ||
| val result = Await.result(resF, 1.minute) | ||
| result aka "professor and material" mustEqual None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
beNone
| val result = Await.result(resF, 1.minute) | ||
| result aka "professor and material" mustEqual Tuple2( | ||
| Professor(1, "John Doe", 35, 1), | ||
| Material(1, "Computer Science", 20, "Beginner")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.await
build.sbt
Outdated
| name := "query-core", | ||
| libraryDependencies ++= Seq( | ||
| Dependencies.cats | ||
| Dependencies.acolyte, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
% Test
| type QueryO[Resource, A] = QueryT[Option, Resource, A] | ||
|
|
||
| type QueryE[Resource, A, Err] = | ||
| object QueryO { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplication par rapport à généricité sur QueryT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Je trouve un peu frustrant d'avoir un type dans l'api (pour améliorer la lisibilité) et de devoir faire appel au companion du type générique pour construire son instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Une proposition alternative que je pourrai faire c'est d'extraire les fonctions de QueryT et de les mettre dans un trait partagé par les companions objects QueryT, QueryO et QueryE. @cchantep qu'en penses-tu ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pour moi ces objects ne sont que des convenient instances de QueryT, dupliquer toute la logique apply, pure, ask, liftF, fromQuery ne me semble pas approprié.
|
|
||
| type SqlQueryO[A] = QueryO[Connection, A] | ||
|
|
||
| object SqlQueryO { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplication
| SqlConnectionFactory.withSqlConnection(AcolyteQueryResult.Nil) | ||
| val runner = SqlQueryRunner(withSqlConnection) | ||
| val query = SqlQuery.pure(1) | ||
| val resF = runner(query) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
runner(query) must beTypedEqualTo(1).await
| _ <- SqlQuery.ask | ||
| professor <- Professor.fetchProfessor(2) | ||
| } yield professor | ||
| val resF = runner(query) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
runner(query) must beNone.await
|
|
||
| // execute composed queries into a single transaction | ||
| "retrieve professor with id 1 and his material" in { | ||
| val handler = AcolyteDSL.handleStatement |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a query only handler, AcolyteDSL.handleQuery { .. }
|
|
||
| def fetchProfessor(id: Int): SqlQuery[Option[Professor]] = { | ||
| SqlQuery { implicit connection => | ||
| SQL"SELECT * FROM professors where id = {id}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$id
| implicit ec: ExecutionContext | ||
| ) extends QueryRunner[Resource] { | ||
|
|
||
| def apply[M[_], T](query: QueryT[M, Resource, T]): Future[M[T]] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!!! Si M = Future
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Effectivement. Mais je trouve ça commode de pouvoir run directement un QueryT sans avoir à repasser à une Query. Je pourrai essayer de restreindre en demandant une evidence en implicit mais j'ai plutôt envie de dire que c'est à l'utilisateur de gérer ça.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sauf que le loan pattern ne gèrera pas correctement (ça échouera) la ressource si le traitement Query se base sur M=Future
84912d9 to
fee481c
Compare
fee481c to
e02d1f2
Compare
eaad42d to
b956e67
Compare
b956e67 to
c350426
Compare
| type Outer = Future[F[A]] | ||
|
|
||
| def apply[In](resource: In, f: In => F[A])(onComplete: In => Unit)(implicit ec: ExecutionContext): Outer = { | ||
| Try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/* ? */ Future(f(resource)).andThen { case _ => onComplete(resource) }| SqlConnectionFactory.withSqlConnection(AcolyteQueryResult.Nil) | ||
| val runner = SqlQueryRunner(withSqlConnection) | ||
| val query = SqlQuery.pure(1) | ||
| runner(query) aka "material" must beTypedEqualTo(1).await |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
J'aèrerais avec une ligne d'espace entre le bloc de déclaration/val et l'expectation
| SqlQueryT{implicit c => | ||
| Future { | ||
| Thread.sleep(2000) // Simumlates a a very slow query | ||
| val r = SQL"select sqrt($num) as result".as(SqlParser.double("result").single) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
val r = ...; r => ... ?
|
@stankoua Sur les tests, tu as un soucis de cohérence du formattage : https://travis-ci.org/zengularity/query-monad/builds/354037179#L504 |
| /** | ||
| * Heavily inspired from work done by @cchantep in Acolyte (see acolyte.reactivemongo.ComposeWithCompletion) | ||
| */ | ||
| * Heavily inspired from work done by @cchantep in Acolyte (see acolyte.reactivemongo.ComposeWithCompletion) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indent issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I have an issue with scalafmt which doesn't format properly scaladoc. I'm working on an PR to update scalafmt settings.
No description provided.