1 /*
2  *  Make.org Core API
3  *  Copyright (C) 2018 Make.org
4  *
5  * This program is free software: you can redistribute it and/or modify
6  *  it under the terms of the GNU Affero General Public License as
7  *  published by the Free Software Foundation, either version 3 of the
8  *  License, or (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU Affero General Public License for more details.
14  *
15  *  You should have received a copy of the GNU Affero General Public License
16  *  along with this program.  If not, see <https://www.gnu.org/licenses/>.
17  *
18  */
19 
20 package org.make.api.technical.healthcheck
21 
22 import org.make.api.technical.DatabaseTransactions._
23 import org.make.api.technical.healthcheck.HealthCheck.Status
24 import scalikejdbc._
25 
26 import scala.concurrent.{ExecutionContext, Future}
27 
28 class CockroachHealthCheck(defaultAdminEmail: String) extends HealthCheck {
29 
30   override val techno: String = "cockroach"
31 
32   override def healthCheck()(implicit ctx: ExecutionContext): Future[Status] = {
33     Future(NamedDB("READ").retryableTx { implicit session =>
34       sql"select first_name from make_user where email=$defaultAdminEmail".map(_.toMap()).list()
35     }).map(_.length).map {
36       case 1 => Status.OK
37       case other =>
38         Status.NOK(Some(s"""Unexpected result in cockroach health check: expected "1" result but got "$other""""))
39     }
40   }
41 }
Line Stmt Id Pos Tree Symbol Tests Code
30 43116 1086 - 1097 Literal <nosymbol> org.scalatest.testsuite "cockroach"
35 35532 1184 - 1531 ApplyToImplicitArgs scala.concurrent.Future.map org.scalatest.testsuite scala.concurrent.Future.apply[List[Map[String,Any]]]({ <artifact> val qual$1: org.make.api.technical.DatabaseTransactions.RichDatabase = org.make.api.technical.DatabaseTransactions.RichDatabase({ <artifact> val x$1: String("READ") = "READ"; <artifact> val x$2: scalikejdbc.SettingsProvider = scalikejdbc.NamedDB.apply$default$2; <artifact> val x$3: scalikejdbc.ConnectionPoolContext = scalikejdbc.NamedDB.apply$default$3("READ", x$2); scalikejdbc.NamedDB.apply("READ", x$2)(x$3) }); <artifact> val x$7: scalikejdbc.DBSession => List[Map[String,Any]] @scala.reflect.internal.annotations.uncheckedBounds = ((implicit session: scalikejdbc.DBSession) => { <synthetic> <stable> <artifact> val stabilizer$1: scalikejdbc.SQLToList[Map[String,Any],scalikejdbc.HasExtractor] @scala.reflect.internal.annotations.uncheckedBounds = scalikejdbc.`package`.scalikejdbcSQLInterpolationImplicitDef(scala.StringContext.apply("select first_name from make_user where email=", "")).sql[Nothing](CockroachHealthCheck.this.defaultAdminEmail).map[Map[String,Any]](((x$1: scalikejdbc.WrappedResultSet) => x$1.toMap())).list; { <artifact> val x$4: scalikejdbc.DBSession = session; <artifact> val x$5: scalikejdbc.SQL[Map[String,Any],scalikejdbc.HasExtractor] =:= scalikejdbc.SQL[Map[String,Any],scalikejdbc.HasExtractor] @scala.reflect.internal.annotations.uncheckedBounds = GeneralizedTypeConstraintsForWithExtractor.this.=:=.tpEquals[scalikejdbc.SQL[Map[String,Any],scalikejdbc.HasExtractor]]; <artifact> val x$6: scalikejdbc.ConnectionPoolContext = stabilizer$1.apply$default$2(); stabilizer$1.apply()(x$4, x$6, x$5) } }); <artifact> val x$8: scalikejdbc.TxBoundary[List[Map[String,Any]]] @scala.reflect.internal.annotations.uncheckedBounds = qual$1.retryableTx$default$2[List[Map[String,Any]]](x$7); qual$1.retryableTx[List[Map[String,Any]]](x$7)(x$8) })(ctx).map[Int](((x$2: List[Map[String,Any]]) => x$2.length))(ctx).map[org.make.api.technical.healthcheck.HealthCheck.Status](((x0$1: Int) => x0$1 match { case 1 => org.make.api.technical.healthcheck.HealthCheck.Status.OK case (other @ _) => org.make.api.technical.healthcheck.HealthCheck.Status.NOK.apply(scala.Some.apply[String](("Unexpected result in cockroach health check: expected \"1\" result but got \"".+(other).+("\""): String))) }))(ctx)