Skip to content
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

Convert DummyDataAccess to use a TrieMap internally. #76

Merged
merged 1 commit into from
Jul 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/test/scala/cromwell/engine/WorkflowManagerActorSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ package cromwell.engine
import java.util.{Calendar, UUID}

import akka.testkit.TestActorRef
import cromwell.binding.FullyQualifiedName
import cromwell.binding.types.WdlStringType
import cromwell.binding.values.WdlString
import cromwell.engine.ExecutionStatus.{Done, NotStarted, Running}
import cromwell.engine.ExecutionStatus.{NotStarted, Running}
import cromwell.engine.db.DataAccess.WorkflowInfo
import cromwell.engine.db.{CallStatus, QueryWorkflowExecutionResult, DummyDataAccess}
import cromwell.engine.db.{DummyDataAccess, QueryWorkflowExecutionResult}
import cromwell.engine.workflow.WorkflowManagerActor
import cromwell.engine.workflow.WorkflowManagerActor.{SubmitWorkflow, WorkflowOutputs, WorkflowStatus}
import cromwell.util.SampleWdl
import cromwell.util.SampleWdl.HelloWorld
import cromwell.{engine, CromwellTestkitSpec, binding}
import cromwell.{CromwellTestkitSpec, binding}

import scala.collection.concurrent.TrieMap
import scala.concurrent.Future


Expand Down Expand Up @@ -56,8 +56,12 @@ class WorkflowManagerActorSpec extends CromwellTestkitSpec("WorkflowManagerActor
val dataAccess = new DummyDataAccess() {
workflows foreach { workflow =>
val id = workflow.workflowId
executionStatuses += (id -> Map("hello.hello" -> (if (id == submitted.workflowId) NotStarted else Running)))
symbolStore += (workflow.workflowId -> symbols)
val status = if (id == submitted.workflowId) NotStarted else Running
executionStatuses(id) = TrieMap("hello.hello" -> status)
symbolStore(id) = TrieMap.empty
symbols foreach { case(symbolStoreKey, symbolStoreEntry) =>
symbolStore(id)(symbolStoreKey) = symbolStoreEntry
}
}

override def getWorkflowsByState(states: Traversable[WorkflowState]): Future[Traversable[WorkflowInfo]] = {
Expand Down
36 changes: 19 additions & 17 deletions src/test/scala/cromwell/engine/db/DummyDataAccess.scala
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package cromwell.engine.db

import cromwell.binding.values.WdlValue
import cromwell.binding.{Call, FullyQualifiedName, WdlNamespace}
import cromwell.binding.{Call, FullyQualifiedName}
import cromwell.engine.ExecutionStatus.ExecutionStatus
import cromwell.engine._
import cromwell.engine.backend.Backend
import cromwell.engine.db.DataAccess.WorkflowInfo

import scala.collection.concurrent.TrieMap
import scala.concurrent.Future

case class DummyDataAccess() extends DataAccess {

private var workflowStates: Map[WorkflowId, WorkflowState] = Map.empty
private val workflowStates: TrieMap[WorkflowId, WorkflowState] = TrieMap.empty

var executionStatuses: Map[WorkflowId, Map[String, ExecutionStatus]] = Map.empty
val executionStatuses: TrieMap[WorkflowId, TrieMap[String, ExecutionStatus]] = TrieMap.empty

var symbolStore: Map[WorkflowId, Map[SymbolStoreKey, SymbolStoreEntry]] = Map.empty
val symbolStore: TrieMap[WorkflowId, TrieMap[SymbolStoreKey, SymbolStoreEntry]] = TrieMap.empty

/**
* Creates a row in each of the backend-info specific tables for each call in `calls` corresponding to the backend
Expand All @@ -25,12 +26,13 @@ case class DummyDataAccess() extends DataAccess {
override def createWorkflow(workflowInfo: WorkflowInfo, symbols: Traversable[SymbolStoreEntry],
calls: Traversable[Call], backend: Backend): Future[Unit] = {
Future.successful {
executionStatuses += (workflowInfo.workflowId -> Map.empty)
setStatus(workflowInfo.workflowId, calls map { _.fullyQualifiedName }, ExecutionStatus.NotStarted)
val newEntries = symbols map { symbol =>
symbol.key -> symbol
val id = workflowInfo.workflowId
executionStatuses += (id -> TrieMap.empty)
symbolStore += (id -> TrieMap.empty)
setStatus(id, calls map { _.fullyQualifiedName }, ExecutionStatus.NotStarted)
symbols foreach { symbol =>
symbolStore(id)(symbol.key) = symbol
}
symbolStore += (workflowInfo.workflowId -> newEntries.toMap)
}
}

Expand All @@ -41,7 +43,9 @@ case class DummyDataAccess() extends DataAccess {

override def setStatus(workflowId: WorkflowId, callFqns: Traversable[FullyQualifiedName], callStatus: CallStatus): Future[Unit] = {
Future.successful {
executionStatuses += (workflowId -> (executionStatuses(workflowId) ++ callFqns.map { _ -> callStatus}.toMap))
callFqns foreach { callFqn =>
executionStatuses(workflowId)(callFqn) = callStatus
}
}
}

Expand Down Expand Up @@ -69,17 +73,15 @@ case class DummyDataAccess() extends DataAccess {
/** The keys in the Map are locally qualified names. */
override def setOutputs(workflowId: WorkflowId, call: Call, callOutputs: Map[String, WdlValue]): Future[Unit] = {
Future.successful {
val newOutputs = for {
callOutput <- callOutputs
entry = SymbolStoreEntry(call.fullyQualifiedName + "." + callOutput._1, callOutput._2, input = false)
} yield entry.key -> entry

symbolStore += (workflowId -> (symbolStore(workflowId) ++ newOutputs))
callOutputs foreach { case (name, wdlValue) =>
val entry = SymbolStoreEntry(call.fullyQualifiedName + "." + name, wdlValue, input = false)
symbolStore(workflowId)(entry.key) = entry
}
}
}

override def getExecutionStatuses(workflowId: WorkflowId): Future[Map[FullyQualifiedName, CallStatus]] = {
Future.successful(executionStatuses(workflowId))
Future.successful(executionStatuses(workflowId).toMap)
}

override def getExecutionBackendInfo(workflowId: WorkflowId, call: Call): Future[CallBackendInfo] = ???
Expand Down