Skip to content

Commit

Permalink
Trigger service style touch ups (digital-asset#6246)
Browse files Browse the repository at this point in the history
* Touch up logTriggerStatus

* Touch up removeRunningTrigger

* Touch up addRunningTrigger

* Remove IntelliJ (scalastyle I think) warnings about public members without type annotations

CHANGELOG_BEGIN
CHANGELOG_END

* Redundant brackets
  • Loading branch information
rohanjr authored Jun 5, 2020
1 parent 5e9490f commit de2b5d1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ class Server(dar: Option[Dar[(PackageId, Package)]], triggerDao: Option[TriggerD
private def addRunningTrigger(t: RunningTrigger): Either[String, Unit] = {
triggerDao match {
case None =>
triggers = triggers + (t.triggerInstance -> t)
triggersByToken = triggersByToken + (t.jwt -> (triggersByToken.getOrElse(t.jwt, Set()) + t.triggerInstance))
triggers += t.triggerInstance -> t
triggersByToken += t.jwt -> (triggersByToken.getOrElse(t.jwt, Set()) + t.triggerInstance)
Right(())
case Some(dao) =>
val insert = dao.transact(TriggerDao.addRunningTrigger(t))
Expand All @@ -116,8 +116,8 @@ class Server(dar: Option[Dar[(PackageId, Package)]], triggerDao: Option[TriggerD
}

private def removeRunningTrigger(t: RunningTrigger): Unit = {
triggers = triggers - t.triggerInstance
triggersByToken = triggersByToken + (t.jwt -> (triggersByToken(t.jwt) - t.triggerInstance))
triggers -= t.triggerInstance
triggersByToken += t.jwt -> (triggersByToken(t.jwt) - t.triggerInstance)
}

private def listRunningTriggers(jwt: Jwt): Either[String, Vector[UUID]] = {
Expand All @@ -138,11 +138,8 @@ class Server(dar: Option[Dar[(PackageId, Package)]], triggerDao: Option[TriggerD

private def logTriggerStatus(t: RunningTrigger, msg: String): Unit = {
val id = t.triggerInstance
val entry = ((LocalDateTime.now), msg)
triggerLog += triggerLog
.get(id)
.map(logs => id -> (logs :+ entry))
.getOrElse(id -> Vector(entry))
val entry = (LocalDateTime.now, msg)
triggerLog += id -> (getTriggerStatus(id) :+ entry)
}

private def getTriggerStatus(uuid: UUID): Vector[(LocalDateTime, String)] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ class ServiceTest extends AsyncFlatSpec with Eventually with Matchers with Postg
override implicit def patienceConfig: PatienceConfig =
PatienceConfig(timeout = scaled(Span(15, Seconds)), interval = scaled(Span(1, Seconds)))

val darPath = requiredResource("triggers/service/test-model.dar")
val encodedDar =
private val darPath = requiredResource("triggers/service/test-model.dar")
private val encodedDar =
DarReader().readArchiveFromFile(darPath).get
val dar = encodedDar.map {
private val dar = encodedDar.map {
case (pkgId, pkgArchive) => Decode.readArchivePayload(pkgId, pkgArchive)
}
val testPkgId = dar.main._1
private val testPkgId = dar.main._1

// Lazy because the postgresDatabase is only available once the tests start
private lazy val jdbcConfig = JdbcConfig(postgresDatabase.url, "operator", "password")

def submitCmd(client: LedgerClient, party: String, cmd: Command) = {
private def submitCmd(client: LedgerClient, party: String, cmd: Command) = {
val req = SubmitAndWaitRequest(
Some(
Commands(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ object TriggerServiceFixture {
private def findFreePort(): Port = {
val socket = new ServerSocket(Port(0).value)
try {
Port(socket.getLocalPort())
Port(socket.getLocalPort)
} finally {
socket.close()
}
Expand All @@ -66,7 +66,7 @@ object TriggerServiceFixture {
ec: ExecutionContext): Future[A] = {
// Launch a toxiproxy instance. Wait on it to be ready to accept
// connections.
val host = InetAddress.getLoopbackAddress()
val host = InetAddress.getLoopbackAddress
val toxiProxyExe = BazelRunfiles.rlocation(System.getProperty("com.daml.toxiproxy"))
val toxiProxyPort = findFreePort()
val toxiProxyProc = Process(Seq(toxiProxyExe, "--port", toxiProxyPort.value.toString)).run()
Expand All @@ -75,7 +75,7 @@ object TriggerServiceFixture {
channel <- Future(new Socket(host, toxiProxyPort.value))
} yield (channel.close())
}
val toxiProxyClient = new ToxiproxyClient(host.getHostName(), toxiProxyPort.value);
val toxiProxyClient = new ToxiproxyClient(host.getHostName, toxiProxyPort.value);

val ledgerId = LedgerId(testName)
val applicationId = ApplicationId(testName)
Expand All @@ -86,16 +86,16 @@ object TriggerServiceFixture {
ledgerProxyPort = findFreePort()
ledgerProxy = toxiProxyClient.createProxy(
"sandbox",
s"${host.getHostName()}:${ledgerProxyPort}",
s"${host.getHostName()}:${ledgerPort}")
s"${host.getHostName}:$ledgerProxyPort",
s"${host.getHostName}:$ledgerPort")
} yield (ledger, ledgerPort, ledgerProxyPort, ledgerProxy)
// 'ledgerProxyPort' is managed by the toxiproxy instance and
// forwards to the real sandbox port.

// Configure this client with the ledger's *actual* port.
val clientF: Future[LedgerClient] = for {
(_, ledgerPort, _, _) <- ledgerF
client <- LedgerClient.singleHost(host.getHostName(), ledgerPort, clientConfig(applicationId))
client <- LedgerClient.singleHost(host.getHostName, ledgerPort, clientConfig(applicationId))
} yield client

val triggerDao: Option[TriggerDao] =
Expand All @@ -111,7 +111,7 @@ object TriggerServiceFixture {
val serviceF: Future[(ServerBinding, TypedActorSystem[Server.Message])] = for {
(_, _, ledgerProxyPort, _) <- ledgerF
ledgerConfig = LedgerConfig(
host.getHostName(),
host.getHostName,
ledgerProxyPort.value,
TimeProviderType.Static,
Duration.ofSeconds(30))
Expand Down

0 comments on commit de2b5d1

Please sign in to comment.